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

Clear the Optimizer before wrapping with FSDP #1732

Merged
merged 6 commits into from
Nov 15, 2022

Conversation

bcui19
Copy link
Contributor

@bcui19 bcui19 commented Nov 15, 2022

What does this PR do?

If a model is created on device 'cpu' instead of 'meta,' the optimizer holds references to unsharded modules on GPU, thus causing the GPU to OOM when a model could fit onto memory.

We now clear the optimizer param groups and states before wrapping the model with FSDP.

Testing
Link to the gist where we now OOM on the forwards pass but not in the model wrapping:

https://gist.github.com/bcui19/c972aa2743e2149baf631b5f71a9fae8

What issue(s) does this change relate to?

Fixes CO-1409

Before submitting

  • Have you read the contributor guidelines?
  • Is this change a documentation change or typo fix? If so, skip the rest of this checklist.
  • Was this change discussed/approved in a GitHub issue first? It is much more likely to be merged if so.
  • Did you update any related docs and document your change?
  • Did you update any related tests and add any new tests related to your change? (see testing)
  • Did you run the tests locally to make sure they pass?
  • Did you run pre-commit on your change? (see the pre-commit section of prerequisites)

@bcui19 bcui19 changed the title Fsdp optim clear Clear the Optimizer before wrapping with FSDP Nov 15, 2022
Copy link
Contributor

@abhi-mosaic abhi-mosaic left a comment

Choose a reason for hiding this comment

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

Looks good to me, thank you!

Copy link
Contributor

@bandish-shah bandish-shah left a comment

Choose a reason for hiding this comment

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

👍

@bcui19 bcui19 merged commit 03bd7f3 into mosaicml:dev Nov 15, 2022
bandish-shah pushed a commit to bandish-shah/composer that referenced this pull request Nov 15, 2022
* Adding in performance registration

* clearing optimizer param groups before FSDP wrapping

* fixing comments

Co-authored-by: Brandon Cui <bcui@Brandons-MBP.hsd1.ca.comcast.net>
@bcui19 bcui19 deleted the FSDP_optim_clear branch March 10, 2023 18:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants