Skip to content
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

[fix] oss dict load fix #383

Merged
merged 2 commits into from
Feb 12, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions fairscale/optim/oss.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,16 +391,16 @@ def load_state_dict(self, state_dict: Dict[str, Any]) -> None:

# NOTE: PyTorch 1.5 does not index linearly but with the id(params) at saving time
# we work around that here by using the fact that the params are ordered as in the param_groups
pytorch15_index_redirect = {k: i for i, k in enumerate(state_dict["state"].keys())}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is useless post pytorch 1.5


for i_param, (key, value) in enumerate(state_dict["state"].items()):
param = self.index_to_param[i_param]
for key, value in state_dict["state"].items():
param = self.index_to_param[pytorch15_index_redirect[key]]

# Populate the sharded optimizer state on the fly
if self.param_to_rank[param] != self.rank:
state_dict["state"][key] = None

if key in self.index_to_param:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test was definitely wrong, I should have seen that..

param = self.index_to_param[i_param]
else:

# Only add this state to the sharded optimizer if it owns this param
for pg in self.optim.param_groups:
Expand Down