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

Fixup Zero3 + save_model #3146

Merged
merged 3 commits into from
Oct 10, 2024
Merged

Fixup Zero3 + save_model #3146

merged 3 commits into from
Oct 10, 2024

Conversation

muellerzr
Copy link
Collaborator

What does this PR do?

When save_model is called under Zero3 only a single rank has all of the parameters. As a result Accelerator.save_model will throw an error under zero3 saying 'NoneType' object has no attribute 'items' because in this case the state_dict of the model on non-0-ranks won't exist.

Fixes #2985

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

@SunMarc @BenjaminBossan

@muellerzr muellerzr added the deepspeed DS related issues/PRs label Oct 8, 2024
@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Copy link
Member

@BenjaminBossan BenjaminBossan 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 fixing this bug. The failing test looks unrelated.

Just a nit, I would move the directory creation code below the newly introduced early return, as it's an unnecessary side effect if we're not saving anything, right?

Copy link
Member

@SunMarc SunMarc left a comment

Choose a reason for hiding this comment

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

LGTM ! Left a small suggestion but feel free to ignore.

Comment on lines +2857 to +2859
# Case: DeepSpeed zero3 gets gathered and `state_dict` is empty
if state_dict is None:
return
Copy link
Member

Choose a reason for hiding this comment

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

We can maybe make it more specific to deepspeed ?
In their code, this is how they do this: https://github.com/microsoft/DeepSpeed/blob/f3943cf9109226ed3ecf2d5dbb639a11cd925555/deepspeed/runtime/engine.py#L3414
Seems like the model only gets saved on rank 0

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I went more generic just in case somehow this happens in other places that we don't know yet (so we enable and don't block them)

@muellerzr muellerzr merged commit 1d2ca74 into main Oct 10, 2024
27 of 28 checks passed
@muellerzr muellerzr deleted the fix-stage3-save-model branch October 10, 2024 16:54
muellerzr added a commit that referenced this pull request Oct 12, 2024
* Fixup + test

* Easier diff

* Move os.makedirs to under return statement
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deepspeed DS related issues/PRs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

conflict in deepsepped frame and accelerate.save_mdoel
4 participants