-
Notifications
You must be signed in to change notification settings - Fork 25.6k
E2E test for FSDP, HSDP, FSDP+TP in Distributed Checkpointing #112541
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
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/112541
Note: Links to docs will display an error until the docs builds have been completed. ✅ You can merge normally! (1 Unrelated Failure)As of commit 044fb94 with merge base 6a3922d ( FLAKY - The following job failed but was likely due to flakiness present on trunk:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
||
return model, optim | ||
|
||
def _equal_state_dict(self, model_0, model_1): |
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.
@fegin Is your recommendation (https://github.com/pytorch/pytorch/blob/main/test/distributed/tensor/parallel/test_fsdp_2d_parallel.py#L638-L641) necessary here, or do you think this is sufficient?
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.
Assuming we'll need something similar to compare optimizers?
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.
Chien-Chin has some utils to compare state_dict here. See if anything is useful for you, and maybe we can just create a test utils for these so we can re-use these in tests. https://github.com/pytorch/pytorch/blob/main/test/distributed/checkpoint/test_state_dict.py#L56
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 believe since I can compare DTensor's directly with torch.equal
we don't really need this logic, so I left the model state dict comparison the same for now.
I also opted for a direct comparison of the optim state dict, since it was a bit simpler and that seems to work here as well -
self.assertEqual(optim.state_dict(), new_optim.state_dict()) |
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.
If you are comparing 2 identical state_dicts, this should be enough. However, if you need to compare with non-converted optimizer state_dict, a customized function is required as non-converted optimizer state use parameter id.
Adding a few tags. @LucasLLC Just FYI, the multi-gpu tests do not run by default. To enable the multi gpu tests, we need to add CI/periodic to the PR. |
return torch.rand(8, 8, device="cuda") | ||
|
||
|
||
class ModelType(Enum): |
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.
Noice!! Very clean!!
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.
Looks great! I would also include an example python / pytest command in the PR summary to include as a reference.
Will defer the approval stamp to the DCP experts :)
|
||
class TestE2ELoadAndSave(DTensorTestBase): | ||
def _create_model(self, compile, model_type): | ||
dummy_model = TestDummyModel().cuda() |
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.
nit: moving to cuda necessary? I thought FSDP does it
def test_e2e(self, compile, model_type): | ||
# first create and save a checkpoint | ||
model, optim = self._create_model(compile, model_type) | ||
model_state_dict_0, optim_state_dict_0 = get_state_dict(model, optimizers=optim) |
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 suggest that we use a non-parallelized model and directly call state_dict as the source of truth to compare.
- create a non-parallelized model
- create a parallelized model
- train both models 2 steps
- save the parallelized model
- create a new parallelized model
- load from the trained parallelized model to the new parallelized model
- train another step both the new parallelized model and the non-parallelized model and compare the accuracy.
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.
LGTM, we can land this first and improve it to compare the result with a non-parallelized model.
Please fix the lint issue and skip_if_lt_x_gpu issue @wz337 mentioned before landing.
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.
Thanks for having this ready! Super-duper fast!
With this PR, now we can mark our FSDP, HSDP, 2D checkpointing B/E ready on PT-D feature support matrix! Thanks @LucasLLC!
@pytorchbot merge |
Merge startedYour 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 |
Merge failedReason: 1 mandatory check(s) failed. The first few are: Dig deeper by viewing the failures on hud |
Try |
@pytorchbot merge |
Merge startedYour 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 |
) | ||
tp_mesh = mesh_2d["tp"] | ||
dp_mesh = mesh_2d["dp"] | ||
model = parallelize_module(dummy_model, tp_mesh, PairwiseParallel()) |
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.
As a follow up, we should probably switch PairwiseParallel
to Colwise + Rowwise
as we plan to deprecate the former soon
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.
For usage of Colwise + Rowwise, you can refer to this slide. https://docs.google.com/presentation/d/1e9TNYu_u_Hz9IpfhS4_R_77de59g5AnSWEf7U-FDphg/edit#slide=id.g28cb00a468a_0_16
So, for this model, we can specify a parallelize_plan for some of the layers, maybe layer 1 and layer 2.
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 since we use sequential in the module definition, I am not sure if PairwiseParallel
is working here. So using Colwise + Rowwise might be a necessary. Basically, you need to pass in a dictionary as a plan to parallelize_module
with its key equals to module's FQN and value is ColwiseParallel or RowwiseParallel.
…h#112541) Adds E2E tests for saving/loading distributed checkpoints. Supported so far are: - FSDP - HSDP - FSDP + TP Each method is also tested using `torch.compile` To run all tests: `python test/distributed/checkpoint/test/distributed/checkpoint/e2e/test_e2e_save_and_load.py` Pull Request resolved: pytorch#112541 Approved by: https://github.com/fegin, https://github.com/wz337
…h#112541) Adds E2E tests for saving/loading distributed checkpoints. Supported so far are: - FSDP - HSDP - FSDP + TP Each method is also tested using `torch.compile` To run all tests: `python test/distributed/checkpoint/test/distributed/checkpoint/e2e/test_e2e_save_and_load.py` Pull Request resolved: pytorch#112541 Approved by: https://github.com/fegin, https://github.com/wz337
Addresses the following comment - #112541 (comment) Changes the comparison of models in the checkpointing E2E test to compare a non-parallelized model against distribued model after training, saving, & loading. Pull Request resolved: #113181 Approved by: https://github.com/fegin
Addresses the following comment - #112541 (comment) Changes the comparison of models in the checkpointing E2E test to compare a non-parallelized model against distribued model after training, saving, & loading. Pull Request resolved: #113181 Approved by: https://github.com/fegin, https://github.com/huydhn, https://github.com/wz337
Adds E2E tests for saving/loading distributed checkpoints. Supported so far are:
Each method is also tested using
torch.compile
To run all tests:
python test/distributed/checkpoint/test/distributed/checkpoint/e2e/test_e2e_save_and_load.py