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

Fix fsdp weight tying #1856

Merged
merged 10 commits into from
Jan 13, 2023
Merged

Fix fsdp weight tying #1856

merged 10 commits into from
Jan 13, 2023

Conversation

bcui19
Copy link
Contributor

@bcui19 bcui19 commented Jan 5, 2023

What does this PR do?

When initializing FSDP with device='meta' it undoes weight tying. This is a known issue in PyTorch with deferred initialization. Additionally, in order to address this, all weight tied modules have to be in the same FSDP module, as a result we try our best to force the FSDP parameters into the same module.

What issue(s) does this change relate to?

CO-1511

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)

Copy link
Contributor

@dakinggg dakinggg left a comment

Choose a reason for hiding this comment

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

LGTM as far as I can tell, will let abhi or other approve. Also, have you tested with the examples repo (without Vitaliy's recent fix)? I'd like to know two things 1) Does it properly respect the tied weights there? and 2) Does it change the memory/throughput?

tests/common/models.py Outdated Show resolved Hide resolved
composer/trainer/dist_strategy.py Outdated Show resolved Hide resolved
composer/trainer/dist_strategy.py Outdated Show resolved Hide resolved
composer/trainer/dist_strategy.py Outdated Show resolved Hide resolved
composer/trainer/dist_strategy.py Show resolved Hide resolved
composer/trainer/dist_strategy.py Outdated Show resolved Hide resolved
@bcui19
Copy link
Contributor Author

bcui19 commented Jan 9, 2023

  1. Does it properly respect the tied weights there? and 2) Does it change the memory/throughput?
  1. Yes so long as the tied modules end up in the same FSDP module, which can be subject to 'min_params'
  2. I checked the base memory usage of each model (for 125m params), without the fix it uses 2.69GB, with the fix it uses 2.23GB. Throughput is mildly affected https://wandb.ai/mosaic-ml/meta-tensors-python?workspace=user-bcui (< 1% change)

Copy link
Contributor

@vchiley vchiley left a comment

Choose a reason for hiding this comment

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

Left a comment, but it generally looks good.

Also whats the point of file composer/scratch?

composer/trainer/dist_strategy.py Outdated Show resolved Hide resolved
@bcui19 bcui19 merged commit 88356e3 into mosaicml:dev Jan 13, 2023
@bcui19 bcui19 deleted the fix_fsdp_weight_tying 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