Fix incorrect behaviour of loader when load_state_dict is after state…
…_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)
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.
- If you are adding a new node, ensure you read that section in the contribution guide, as it includes requirements for functionality and testing.
Changes
-
Fix incorrect iterator when called state_dict before load_state_dict
Hi @edgarshmavonyan!
Thank you for your pull request and welcome to our community.
Action Required
In 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.
Process
In 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 CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.
If you have received this in error or have any questions, please contact us at [email protected]. Thanks!
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!