-
Notifications
You must be signed in to change notification settings - Fork 170
[SDL] StatefulDistributedSampler add epoch to state_dict #1515
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
[SDL] StatefulDistributedSampler add epoch to state_dict #1515
Conversation
|
@aelavender has imported this pull request. If you are a Meta employee, you can view this in D87398440. |
| self.next_yielded = None | ||
|
|
||
| def __iter__(self): | ||
| print(f"Calling __iter__... {self.yielded=} {self.next_yielded=}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can skip the print ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, will remove
| def load_state_dict(self, state_dict: Dict[str, Any]) -> None: | ||
| if self._EPOCH not in state_dict: | ||
| raise ValueError("Invalid state_dict") | ||
| self.set_epoch(state_dict[self._EPOCH]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If users are used to calling set_epoch in a certain in the main loop, then doing self.set_epoch(..) on load_state_dict might interfere with that ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the user is trying to set_epoch to something other than what was previously saved, then they are likely going to get repeated indices in the current epoch, which seems like broken behaviour. Perhaps we should warn in that case.
Partially fixes #1513
StatefulDistributedSamplerhas epoch-dependent behaviour (the sampling order depends on epoch), so we need to save and restore the correct epoch.When used with
StatefulDataLoaderthis is mostly an edge case, as users are expected to explicitly callset_epochbefore each epoch. But the order matters here: if the user forgets to callset_epoch()or calls__iter__()beforeset_epoch(), things will be incorrect. By putting the epoch in state we can avoid these mistakes.See also #1516.