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

[FSDP] Support unfreezing params for reshard-only hook #104186

Closed
wants to merge 2 commits into from

Conversation

awgu
Copy link
Contributor

@awgu awgu commented Jun 26, 2023

Stack from ghstack (oldest at bottom):

This fixes #104148 (unfreezing parameters after n steps).

  • This fixes a bug where we did not delete the post-backward hook state properly for the requires_grad=False case.
  • This makes the already_resharded correct for SHARD_GRAD_OP.
  • This generalizes _clear_grads_if_needed() to _reset_flat_param_grad_info_if_needed() to additionally include propagating the original parameters' requires_grad to the flat parameter.

@pytorch-bot
Copy link

pytorch-bot bot commented Jun 26, 2023

🔗 Helpful Links

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

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

✅ No Failures

As of commit 2b5c8f1:
💚 Looks good so far! There are no failures yet. 💚

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

@pytorch-bot pytorch-bot bot added the release notes: distributed (fsdp) release notes category label Jun 26, 2023
awgu added a commit that referenced this pull request Jun 26, 2023
ghstack-source-id: acd123f95b2c3fd90555aeef08274292c0c30f9d
Pull Request resolved: #104186
@awgu awgu marked this pull request as draft June 26, 2023 11:58
awgu added a commit that referenced this pull request Jun 26, 2023
ghstack-source-id: 487b4b9611d6a7f307c03682b463ed48ed35c0b9
Pull Request resolved: #104186
@awgu awgu added the topic: improvements topic category label Jun 26, 2023
@awgu awgu marked this pull request as ready for review June 26, 2023 14:48
@speediedan
Copy link
Contributor

Thanks for the timely and adroit (as always!) fix/enhancement @awgu! 🎉 🚀

Copy link
Member

@rohan-varma rohan-varma left a comment

Choose a reason for hiding this comment

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

thanks for the quick fix!

for param in seq[i * 2].parameters(recurse=False):
param.requires_grad = False
return seq
for param in seq[i * 2].parameters(recurse=True):
Copy link
Member

Choose a reason for hiding this comment

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

doesn't .parameters(recurse=True) the default?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep. This recurse=True is unnecessary. I will leave it to avoid triggering CI.

def _reset_flat_param_grad_info_if_needed(self):
"""
When ``use_orig_params=True``:
(1) sets the underlying ``flat_param.grad`` to ``None`` if *all* of the
Copy link
Member

Choose a reason for hiding this comment

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

Does this mean we need a unittest to ensure the flat_param.grad is None appropriately?

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 is the existing behavior, which we already have unit tests for in test_fsdp_use_orig_params.py.

@awgu
Copy link
Contributor Author

awgu commented Jun 28, 2023

@pytorchbot merge

@pytorch-bot pytorch-bot bot added the ciflow/trunk Trigger trunk jobs on your pull request label Jun 28, 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

@pytorchmergebot
Copy link
Collaborator

Merge failed

Reason: 1 jobs have failed, first few of them are: trunk / win-vs2019-cuda11.8-py3 / build

Details for Dev Infra team Raised by workflow job

@awgu
Copy link
Contributor Author

awgu commented Jun 28, 2023

@pytorchbot merge

@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

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 release notes: distributed (fsdp) release notes category topic: improvements topic category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants