KEMBAR78
Stateful Checkpointing for Distributed [1/N] by LucasLLC · Pull Request #113867 · pytorch/pytorch · GitHub
Skip to content

Conversation

@LucasLLC
Copy link
Contributor

@LucasLLC LucasLLC commented Nov 16, 2023

First pass at adding a save/load API, as well as definition of Stateful objects.

Amongst a couple todo's, we still need to explore adding an all_gather & potentially a barrier while iterating through state keys.

cc @mrshenli @pritamdamania87 @zhaojuanmao @satgera @rohan-varma @gqchen @aazzolini @osalpekar @jiayisuse @H-Huang @kwen2501 @awgu @penguinwu @fegin @XilunWu @wanchaol @fduwjj @wz337 @tianyu-l @wconstab @yf225 @kiukchung @d4l3k @LucasLLC

@LucasLLC LucasLLC self-assigned this Nov 16, 2023
@pytorch-bot
Copy link

pytorch-bot bot commented Nov 16, 2023

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/113867

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit 3c2dcb7 with merge base ec124b9 (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@LucasLLC LucasLLC changed the title Stateful Checkpointing for Distributed Stateful Checkpointing for Distributed [1/N] Nov 27, 2023
Copy link
Contributor

@fegin fegin left a comment

Choose a reason for hiding this comment

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

LGTM, the failing test is real.

Copy link
Contributor

@wz337 wz337 left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks!

@@ -0,0 +1,104 @@
# Owner(s): ["oncall: distributed"]
Copy link
Contributor

Choose a reason for hiding this comment

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

We can later move this to https://github.com/pytorch/examples or update this tutorial in https://github.com/pytorch/tutorials/blob/main/recipes_source/distributed_checkpoint_recipe.rst.

From what I learned, we should not keep the examples PT repo, but we still have a couples for checkpoint and other distributed componenets.

return torch.rand(8, 8, device="cuda")


def _make_stateful(model, optim):
Copy link
Contributor

Choose a reason for hiding this comment

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

what does this do? should users rely on it, or should they write their own state function on their model?

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 question is a bit loaded, I'm still thinking about the best UX around this item in particular. In general, if users are defining objects with custom Stateful behavior, they should define state_dict and load_state_dict on those objects.

For model/optim, which need to call get_state_dict and set_state_dict in state_dict and load_state_dict, the two options so far are:

  1. Create a wrapper:
    class DOptim:
           def __init__(self, model, optim):
               self.model = model
               self.optim = optim
            ...
    

We're still evaluating whether it makes sense to include the wrapper as part of DCP since it can be a little tricky and could lead to a less then ideal UX

  1. The other option, which I don't think is a bad one, is using the _patch methods as above. The patch methods are still in testing but I think it's pretty reasonable

@LucasLLC
Copy link
Contributor Author

LucasLLC commented Dec 1, 2023

@pytorchbot merge

@pytorch-bot pytorch-bot bot added the ciflow/trunk Trigger trunk jobs on your pull request label Dec 1, 2023
@pytorchmergebot
Copy link
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

@albanD albanD added oncall: distributed Add this issue/PR to distributed oncall triage queue and removed module: distributed labels Dec 8, 2023
dmenig pushed a commit to dmenig/pytorch that referenced this pull request Dec 21, 2023
First pass at adding a save/load API, as well as definition of Stateful objects.

Amongst a couple todo's, we still need to explore adding an `all_gather` & potentially a `barrier` while iterating through state keys.

Pull Request resolved: pytorch#113867
Approved by: https://github.com/fegin, https://github.com/wz337
@github-actions github-actions bot deleted the dcp_stateful branch February 19, 2024 02:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/trunk Trigger trunk jobs on your pull request Merged oncall: distributed Add this issue/PR to distributed oncall triage queue release notes: distributed (checkpoint)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants