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] Fix use_orig_params=True, CPU offload, no_sync() #100180

Closed
wants to merge 3 commits into from

Conversation

awgu
Copy link
Contributor

@awgu awgu commented Apr 27, 2023

Stack from ghstack (oldest at bottom):

This should fix #98494. We follow a similar approach as in past PRs for mismatched dtype or size from running in no_sync().

@pytorch-bot
Copy link

pytorch-bot bot commented Apr 27, 2023

🔗 Helpful Links

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

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

✅ No Failures

As of commit b4d402e:
💚 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 Apr 27, 2023
awgu added a commit that referenced this pull request Apr 27, 2023
ghstack-source-id: 8102bea96ec3551b1041a299b005e6e47f3cbbba
Pull Request resolved: #100180
@@ -117,12 +117,6 @@ def _test_grad_acc(
point to prefetch the next layer's full parameters during the
backward pass, if at all.
"""
# Gradient accumulation outside `no_sync()` is not currently compatible
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Previously, we were skipping all CPU offloading tests since every tested config included use_no_sync == False 😢

That is why I thought use_orig_params=True worked with CPUOffload(True), but we were actually skipping the test.

@awgu awgu added the topic: bug fixes topic category label Apr 27, 2023
awgu added a commit that referenced this pull request Apr 27, 2023
ghstack-source-id: 8102bea96ec3551b1041a299b005e6e47f3cbbba
Pull Request resolved: #100180
This should fix #98494. We follow a similar approach as in past PRs for mismatched dtype or size from running in `no_sync()`.

[ghstack-poisoned]
awgu added a commit that referenced this pull request Apr 27, 2023
ghstack-source-id: 4d6ae641b0016ae04de6b5ee4fc81777eeef0496
Pull Request resolved: #100180
@awgu awgu added the ciflow/trunk Trigger trunk jobs on your pull request label Apr 27, 2023
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.

LGTM, thanks for the fix!


NOTE: Gradient accumulation without using the ``no_sync()`` context
manager is not currently compatible with CPU offloading, so those tests
just return directly.
manager is not currently compatible with CPU offloading.
Copy link
Member

Choose a reason for hiding this comment

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

curious, how do we error here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We do not error. It is silently incorrect if I understand correctly.

)

@skip_if_lt_x_gpu(2)
@parametrize("use_orig_params", [False, True])
Copy link
Member

Choose a reason for hiding this comment

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

should we put this as a subtest?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we can avoid subtesting major config differences, where we actually expect based on the implementation there may be a difference. At least that is what I have been doing so far.

# NOTE: This is a hack using `.data` to side step the check
# that parameter/gradient sizes/dtypes/devices match. From
# calling `reshard()`, `param` has the sharded size, the full
# precision dtype, and is on CPU. Thus, one or more 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.

is on CPU only if CPU offloading?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes.

# calling `reshard()`, `param` has the sharded size, the full
# precision dtype, and is on CPU. Thus, one or more of the
# following cases can hold when in `no_sync()`:
# 1. `view` can have the unsharded size.
Copy link
Member

Choose a reason for hiding this comment

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

view is the grad here right, can we clarify that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let me do it in a follow-up to avoid re-triggering CI.

@awgu
Copy link
Contributor Author

awgu commented May 1, 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

valentinandrei pushed a commit to valentinandrei/pytorch that referenced this pull request May 2, 2023
…100180)

This should fix pytorch#98494. We follow a similar approach as in past PRs for mismatched dtype or size from running in `no_sync()`.
Pull Request resolved: pytorch#100180
Approved by: https://github.com/rohan-varma
@facebook-github-bot facebook-github-bot deleted the gh/awgu/396/head branch June 8, 2023 15:40
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 merging release notes: distributed (fsdp) release notes category topic: bug fixes topic category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants