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

[Quantization] Quanto quantizer #29023

Merged
merged 58 commits into from
Mar 15, 2024
Merged

Conversation

SunMarc
Copy link
Member

@SunMarc SunMarc commented Feb 14, 2024

What does this PR do ?

This PR adds the quantization methods from quanto library. We will support inference + model quantization if the user perform weights only quantization since we don't require a calibration dataset.

TODO:

  • docs
  • tests
  • Guard against saving now since it is a bit complicated

@SunMarc SunMarc changed the title [Quantization] Quanto [Quantization] Quanto quantizer Feb 14, 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
Contributor

@younesbelkada younesbelkada left a comment

Choose a reason for hiding this comment

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

Clean work already ! Looking forward to merge the PR !

@younesbelkada
Copy link
Contributor

cc @dacorvo

@SunMarc
Copy link
Member Author

SunMarc commented Feb 22, 2024

Quick update, all tests are passing with the exception of safetensors tests. I've also implemented the quantization on the spot just like we do for bnb quantization. However, if the user wants to use cpu/disk offload, he will need to install the main branch of accelerate for now because of this PR.

@SunMarc SunMarc marked this pull request as ready for review February 28, 2024 23:05
@ArthurZucker
Copy link
Collaborator

LGTM, mostly concerned with quanto specific function addition, that should leave in quanto.py not in the modeling (as much as possible of course).

Copy link
Collaborator

@ArthurZucker ArthurZucker 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 iterating! 🔥 let's make quanto go brrr

Comment on lines +3752 to +3753
if hf_quantizer is not None:
missing_keys = hf_quantizer.update_missing_keys(model, missing_keys, prefix)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Alright no worries 🤗

tests/quantization/quanto_integration/test_quanto.py Outdated Show resolved Hide resolved
Copy link
Contributor

@younesbelkada younesbelkada left a comment

Choose a reason for hiding this comment

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

Thanks again @SunMarc - great work ! 🚀 let's 🚢 it

@SunMarc
Copy link
Member Author

SunMarc commented Mar 14, 2024

Note to the core mainteners and especially @ArthurZucker . I reverted a lot of changes I did for the serialization. I decided to postpone the serialization feature by setting the is_serializable property to False in this PR.

I will do a follow up PR for the serialization since the PR to make it compatible with safetensors or weight_only saving in quanto needs lots of changes in the way we load + save models in transformers.

Without serialization, this PR should still be good to merge !

@SunMarc SunMarc merged commit 28de2f4 into huggingface:main Mar 15, 2024
22 checks passed
itazap pushed a commit that referenced this pull request May 14, 2024
* start integration

* fix

* add and debug tests

* update tests

* make pytorch serialization works

* compatible with device_map and offload

* fix tests

* make style

* add ref

* guard against safetensors

* add float8 and style

* fix is_serializable

* Fix shard_checkpoint compatibility with quanto

* more tests

* docs

* adjust memory

* better

* style

* pass tests

* Update src/transformers/modeling_utils.py

Co-authored-by: Younes Belkada <[email protected]>

* add is_safe_serialization instead

* Update src/transformers/quantizers/quantizer_quanto.py

Co-authored-by: Younes Belkada <[email protected]>

* add QbitsTensor tests

* fix tests

* simplify activation list

* Update docs/source/en/quantization.md

Co-authored-by: David Corvoysier <[email protected]>

* better comment

* Update tests/quantization/quanto_integration/test_quanto.py

Co-authored-by: David Corvoysier <[email protected]>

* Update tests/quantization/quanto_integration/test_quanto.py

Co-authored-by: David Corvoysier <[email protected]>

* find and fix edge case

* Update docs/source/en/quantization.md

Co-authored-by: Arthur <[email protected]>

* pass weights_only_kwarg instead

* fix shard_checkpoint loading

* simplify update_missing_keys

* Update tests/quantization/quanto_integration/test_quanto.py

Co-authored-by: Arthur <[email protected]>

* recursion to get all tensors

* block serialization

* skip serialization tests

* fix

* change by cuda:0 for now

* fix regression

* update device_map

* fix doc

* add noteboon

* update torch_dtype

* update doc

* typo

* typo

* remove comm

---------

Co-authored-by: Younes Belkada <[email protected]>
Co-authored-by: David Corvoysier <[email protected]>
Co-authored-by: Arthur <[email protected]>
Co-authored-by: Younes Belkada <[email protected]>
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