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

[bitsandbbytes] follow-ups #9730

Merged
merged 13 commits into from
Oct 22, 2024
Merged

[bitsandbbytes] follow-ups #9730

merged 13 commits into from
Oct 22, 2024

Conversation

sayakpaul
Copy link
Member

@sayakpaul sayakpaul commented Oct 21, 2024

What does this PR do?

  1. Takes care of [Quantization] Add quantization support for bitsandbytes #9213 (comment)
  2. Move the test repos to hf-internal-testing
  3. Check bnb param shape
  4. Other minor nits

@sayakpaul sayakpaul marked this pull request as draft October 21, 2024 05:50
@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.

@sayakpaul sayakpaul changed the title [WIP][bitsandbbytes] follow-ups [bitsandbbytes] follow-ups Oct 21, 2024
@sayakpaul sayakpaul requested a review from DN6 October 21, 2024 09:54
@sayakpaul sayakpaul marked this pull request as ready for review October 21, 2024 10:18
"""
checks if the quantized param has expected shape.
"""
if not hasattr(self, "check_quantized_param_shape"):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Think this should be?

Suggested change
if not hasattr(self, "check_quantized_param_shape"):
if not hasattr(self, "check_if_quantized_param")::

Copy link
Member Author

Choose a reason for hiding this comment

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

Why?

Copy link
Collaborator

@DN6 DN6 Oct 22, 2024

Choose a reason for hiding this comment

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

The method is checking for itself? That can't be the case right? Because the subclass inherits it? So it should already be in there?

Copy link
Member Author

Choose a reason for hiding this comment

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

My bad. Have updated in 3298a04.

src/diffusers/models/model_loading_utils.py Outdated Show resolved Hide resolved
src/diffusers/models/model_loading_utils.py Outdated Show resolved Hide resolved
@sayakpaul
Copy link
Member Author

sayakpaul commented Oct 22, 2024

@stevhliu could you review the doc changes please?

@DN6 ready for your reviews. I have run the tests and they pass.

@sayakpaul sayakpaul requested a review from DN6 October 22, 2024 03:35
Once a model is quantized, you can push the model to the Hub with the [`~ModelMixin.push_to_hub`] method. The quantization `config.json` file is pushed first, followed by the quantized model weights.

```py
from diffusers import FluxTransformer2DModel, BitsAndBytesConfig

quantization_config = BitsAndBytesConfig(load_in_8bit=True)

model_8bit = FluxTransformer2DModel.from_pretrained(
"black-forest-labs/FLUX.1-dev",
subfolder="transformer",
quantization_config=quantization_config
)
```
Once a model is quantized, you can push the model to the Hub with the [`~ModelMixin.push_to_hub`] method. The quantization `config.json` file is pushed first, followed by the quantized model weights. You can also save the serialized 4-bit models locally with [`~ModelMixin.save_pretrained`].
Copy link
Member Author

Choose a reason for hiding this comment

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

To unify the content between 8bit and 4bit hfoption.

and hf_quantizer.check_if_quantized_param(model, param, param_name, state_dict, param_device=device)
):
hf_quantizer.check_quantized_param_shape(param_name, empty_state_dict[param_name].shape, param.shape)
elif not is_quant_method_bnb:
Copy link
Member Author

Choose a reason for hiding this comment

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

Could have done with else but I think it's a tad bit safer.

@sayakpaul sayakpaul merged commit 60ffa84 into main Oct 22, 2024
18 checks passed
@sayakpaul sayakpaul deleted the bnb-follow-up branch October 22, 2024 10:35
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