-
Notifications
You must be signed in to change notification settings - Fork 176
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
Statistics averaging #229
Statistics averaging #229
Conversation
@@ -46,7 +49,7 @@ def __init__(self, opt: torch.optim.Optimizer, *, average_parameters: bool, aver | |||
def step(self, wait: bool = True, **kwargs): | |||
""" Average optimizer weights and gradients with peers. """ | |||
if not wait: | |||
return run_in_background(self.step, wait=False, **kwargs) | |||
return run_in_background(self.step, wait=True, **kwargs) |
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.
good catch!
grad_avg = 0.5 * (x1.grad + x2.grad) | ||
stats_avg = 0.5 * (opt1.state[x1]["exp_avg_sq"] + opt2.state[x2]["exp_avg_sq"]) | ||
|
||
f1 = averager1.step(wait=False) |
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.
f1 = averager1.step(wait=False) | |
# We set wait=False to test hivemind.utils.run_in_background() usage | |
f1 = averager1.step(wait=False) |
nit: Using wait=False
and then waiting for the result looked surprising to me. I'd suggest clarifying this with the comment.
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.
Actually the main purpose of wait=False
is to prevent deadlock, when averager1 waits for averager2 to join.
Fix: write this explicitly in comment
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.
Oh, sure, missed that! Thanks for the explanation :)
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.
I approve the PR, but ask you to consider the minor change I've suggested :)
This PR extends
TrainingAverager
with optimizer's stats averaging. It should serve as base for subsequent decentralized adaptive optims implementations.