-
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -181,6 +181,7 @@ def __iter__(self): | |
|
|
||
| class StatefulDistributedSampler(torch.utils.data.distributed.DistributedSampler): | ||
| _YIELDED = "yielded" | ||
| _EPOCH = "epoch" | ||
|
|
||
| def __init__( | ||
| self, | ||
|
|
@@ -196,6 +197,7 @@ def __init__( | |
| self.next_yielded = None | ||
|
|
||
| def __iter__(self): | ||
| print(f"Calling __iter__... {self.yielded=} {self.next_yielded=}") | ||
| self.yielded = 0 | ||
| if self.next_yielded is not None: | ||
| self.yielded = self.next_yielded | ||
|
|
@@ -206,9 +208,12 @@ def __iter__(self): | |
| yield idx | ||
|
|
||
| def state_dict(self) -> Dict[str, Any]: | ||
| return {self._YIELDED: self.yielded} | ||
| return {self._YIELDED: self.yielded, self._EPOCH: self.epoch, "NEXT_YIELDED": self.next_yielded} | ||
|
|
||
| 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]) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the user is trying to |
||
| if self._YIELDED not in state_dict: | ||
| raise ValueError("Invalid state_dict") | ||
| if state_dict[self._YIELDED] < 0: | ||
|
|
||
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