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

local_sgd: initial version of fault tolerant LocalSGD #47

Merged
merged 1 commit into from
Dec 18, 2024
Merged

Conversation

d4l3k
Copy link
Member

@d4l3k d4l3k commented Dec 18, 2024

This implements an initial version of LocalSGD. #39

This has some limitations:

  • workers can only join at the start of the sync_every period
  • in async mode, the joining worker will discard the first sync_every steps as it's treated as a single Manager step
  • if any errors/workers fail we will only detect it at the end of sync_every steps
  • This uses a copy of the weights in memory in order to restore the model on commit failure to guarantee we always step exactly sync_every steps on each worker. This copy will be required for DiLoCo to compute the pseudo gradient.
  • We don't do any bucketization for the allreduce operation

Test plan:

pyre
pytest

This will require more testing as I've only tested it with a mocked Manager and no e2e/integration tests

@d4l3k d4l3k requested review from wconstab and H-Huang December 18, 2024 19:38
@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Meta Open Source bot. label Dec 18, 2024

if self._local_step >= self._sync_every:
self._local_step = 0
self._average()
Copy link
Member

Choose a reason for hiding this comment

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

in the function description it is saying we allreduce the weights, but the function implemented below allreduces the grads?

Copy link
Member Author

Choose a reason for hiding this comment

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

allreduce_grads is a bit misnamed, I'll rename it as we're not reducing gradients here

The behavior is just an allreduce though with some rescaling logic on top

Copy link
Member Author

Choose a reason for hiding this comment

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

done


def step(self) -> None:
"""
This should be called after the optimizer step.
Copy link
Member

@H-Huang H-Huang Dec 18, 2024

Choose a reason for hiding this comment

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

hmm, i wonder instead of having the user call step after optimizer step, we modify the init of LocalSGD to pass in the optimizer as well and then add an optimizer hook (https://pytorch.org/docs/stable/generated/torch.optim.Optimizer.register_step_post_hook.html#torch.optim.Optimizer.register_step_post_hook) to automatically call this logic?

Copy link
Member Author

Choose a reason for hiding this comment

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

TIL -- that looks pretty useful

I do think we can potentially move this into the forward wrapper as well but it makes things a bit harder to reason about

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@d4l3k d4l3k force-pushed the d4l3k/local_sgd branch 2 times, most recently from ae46ea7 to 4bd104e Compare December 18, 2024 21:27
Copy link
Member

@H-Huang H-Huang left a comment

Choose a reason for hiding this comment

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

Very cool to add localSGD!

@d4l3k d4l3k merged commit 6d6e9a4 into main Dec 18, 2024
6 checks passed
@d4l3k d4l3k deleted the d4l3k/local_sgd branch December 18, 2024 23:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Meta Open Source bot.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants