Skip to content

Fix quantization w/ DeepSpeed not working#32640

Closed
muellerzr wants to merge 2 commits into
mainfrom
muellerzr-enable-quant
Closed

Fix quantization w/ DeepSpeed not working#32640
muellerzr wants to merge 2 commits into
mainfrom
muellerzr-enable-quant

Conversation

@muellerzr

Copy link
Copy Markdown
Contributor

What does this PR do?

This PR tweaks the logic check introduced in #32299 to specifically exclude when Zero-3 is enabled and we're using a quantization method (which skips this chunk of the zero3 init use)

Fixes # (issue)

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 can you check if what I've done here makes sense given the comment we're trying to fix?

#32299 (comment)

I believe so and I think the test makes sense, but you're quant eyes would be appreciated :)

@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

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.

@jphme

jphme commented Aug 13, 2024

Copy link
Copy Markdown
Contributor

This fixed the issue with finetuning I reported here, thanks!

@SunMarc SunMarc left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for fixing this ! Left a comment

Comment on lines +441 to +445
if (
not (hasattr(model, "hf_quantizer") and model.hf_quantizer.is_trainable)
and is_deepspeed_zero3_enabled()
and not getattr(model, "_transformers_zero3_init_used", True)
):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What's the difference when the model is quantized vs no quantized ?

@amyeroberts

Copy link
Copy Markdown
Contributor

For my own understanding - why doesn't the user need to create the model after TrainingArguments in the quantized case but does in the unquantized case?

@muellerzr

muellerzr commented Aug 13, 2024

Copy link
Copy Markdown
Contributor Author

Quantized weights aren't thrown into the zero_init context manager and instead are using init_empty_weights (I think this answers both your questions)

@muellerzr

Copy link
Copy Markdown
Contributor Author

Closing since we're doing a full revert

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.

5 participants