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

Changing __repr__ in torchao to show quantized Linear #34202

Merged
merged 8 commits into from
Nov 5, 2024

Conversation

MekkCyber
Copy link
Contributor

What does this PR do?

When a model is quantized using TorchAO and then loaded, the representation of its Linear layers is expected to be different compared to the standard representation. This pull request (PR) modifies the representation of these Linear layers to match the format used in TorchAO's implementation : https://github.com/pytorch/ao/blob/main/torchao/quantization/quant_api.py

Before :
Linear(in_features=4096, out_features=4096, bias=False)
After :

Linear(in_features=4096, out_features=4096, weight=AffineQuantizedTensor(shape=torch.Size([4096, 4096]), block_size=(1, 128), device=cuda:0, layout_type=TensorCoreTiledLayoutType(inner_k_tiles=8), layout_tensor_dtype=torch.int32, quant_min=0, quant_max=15))

Who can review?

cc @SunMarc

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.

Thanks for figuring out the issue @MekkCyber ! Left a few comments

src/transformers/quantizers/quantizer_torchao.py Outdated Show resolved Hide resolved
src/transformers/quantizers/quantizer_torchao.py Outdated Show resolved Hide resolved
@MekkCyber
Copy link
Contributor Author

cc @SunMarc for review ! Thank you !

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 ! Thanks for fixing this ! Just a nit. Also rebase the PR to fix the CI.

@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
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.

LGTM, quick q on perf!

@@ -46,6 +45,25 @@ def find_parent(model, name):
return parent


def _quantization_type(weight):
Copy link
Collaborator

Choose a reason for hiding this comment

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

do we want to put this on lru cache? Or is it smart enough to be fast ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would think it's smart enough to be fast, but I will try to do a benchmark to test that

@ArthurZucker
Copy link
Collaborator

We can merge in the mean time 🤗

@MekkCyber MekkCyber merged commit d2bae7e into huggingface:main Nov 5, 2024
22 of 23 checks passed
2015aroras pushed a commit to 2015aroras/transformers that referenced this pull request Nov 15, 2024
)

* Changing __repr__ in torchao

* small update

* make style

* small update

* add LinearActivationQuantizedTensor

* remove some cases

* update imports & handle return None

* update
BernardZach pushed a commit to BernardZach/transformers that referenced this pull request Dec 5, 2024
)

* Changing __repr__ in torchao

* small update

* make style

* small update

* add LinearActivationQuantizedTensor

* remove some cases

* update imports & handle return None

* update
BernardZach pushed a commit to innovationcore/transformers that referenced this pull request Dec 6, 2024
)

* Changing __repr__ in torchao

* small update

* make style

* small update

* add LinearActivationQuantizedTensor

* remove some cases

* update imports & handle return None

* update
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.

4 participants