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

Hotfix: load_state_from_peers with offload_optimizer #417

Merged
merged 1 commit into from
Dec 2, 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
5 changes: 4 additions & 1 deletion hivemind/optim/experimental/state_averager.py
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,8 @@ def load_state_from_peers(self, **kwargs):
Attempt to download the latest optimizer state from peers and update trainer parameters/statistics.
:returns: whether or the averager succeeded in loading parameters
"""
main_parameters_and_extras = tuple(chain(self.main_parameters, self.extra_tensors))
opt_parameters = tuple(param for param_group in self.optimizer.param_groups for param in param_group["params"])
main_parameters_and_extras = tuple(chain(opt_parameters, self.extra_tensors))
Copy link
Member

Choose a reason for hiding this comment

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

What does it mean? If self.main_parameters are invalid at this stage, shouldn't we replace them?

Copy link
Member Author

Choose a reason for hiding this comment

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

If offload_optimizer == False, opt_parameters ARE main parameters

If offload_optimizer == True, we update main parameters in L665

num_parameters_and_extras = len(main_parameters_and_extras)

loaded_state = super().load_state_from_peers(**kwargs)
Expand Down Expand Up @@ -661,6 +662,8 @@ def load_state_from_peers(self, **kwargs):

if self.offload_optimizer:
self._apply_optimizer_parameters_()
if not self.reuse_tensors:
self._load_local_tensors_into_averager_()

self.local_epoch = metadata["epoch"]
self._update_scheduler()
Expand Down