Fix incorrect behaviour of loader when load_state_dict is after state…#1548
Fix incorrect behaviour of loader when load_state_dict is after state…#1548edgarshmavonyan wants to merge 1 commit into
Conversation
…_dict() call
Fixes when load_state_dict and iter are called after state_dict()
Example:
import torchdata.nodes as tn
n = tn.IterableWrapper(range(10))
l = tn.Loader(n)
it = iter(l)
for i in range(5):
assert i == next(it)
sd = l.state_dict()
n = tn.IterableWrapper(range(10))
l = tn.Loader(n)
l.state_dict() # Critical line
l.load_state_dict(sd)
# Now, we should have continued from 5
it = iter(l)
# But it continues from 0, not respecting load_state_dict
for i in range(5):
assert i == next(it) # Should have been i + 5 == next(it)
|
Hi @edgarshmavonyan! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
…_dict() call
Fixes when load_state_dict and iter are called after state_dict()
Example:
I did not open an issue on that, but it's pretty obvious what the problem is.
load_state_dict specifies that this behaviour is incorrect: https://meta-pytorch.org/data/main/torchdata.nodes.html#torchdata.nodes.Loader.load_state_dict
"Loads a state_dict which will be used to initialize the next iter() requested from this loader."
It makes sense to add tests for this behaviour, did not do that yet
Please read through our contribution guide prior to
creating your pull request.
functionality and testing.
Changes