Skip to content

Conversation

@SunMarc
Copy link
Member

@SunMarc SunMarc commented Oct 25, 2024

What does this PR do?

This PR fixes the regression that @BenjaminBossan found out. It was caused by this PR. Basically, old_param was always going to be None with the current logic. Hence, we don't set the correct dtype to the parameter param = param.to(old_param.dtype). This caused a dtype mismatch with torchao.

[...]
    return torch.nn.functional.linear(input_tensor, weight_tensor, bias)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: self and mat2 must have the same dtype, but got Float and Half

To reproduce

import torch
from transformers import AutoModelForCausalLM, TorchAoConfig

quantization_config = TorchAoConfig(quant_type="int8_dynamic_activation_int8_weight")
model_id = "facebook/opt-125m"
model = AutoModelForCausalLM.from_pretrained(model_id, quantization_config=quantization_config)
inputs = torch.arange(10).view(-1, 1)
model(inputs)

I tested that hqq serialization and the new test that I added both passed

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.

I don't have enough background to judge if the fix is good, but the test should cover it, as the generate call itself would raise an error without the fix.

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

Thanks, noting as it will be in a patch

Comment on lines +946 to +947
# We shouldn't hit the default value unless for quant methods like hqq that modifies expected_keys.
old_param = getattr(old_param, split, None)
Copy link
Collaborator

Choose a reason for hiding this comment

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

😅 I knew it!
It was a bit too specific

@ArthurZucker ArthurZucker merged commit 004530a into main Oct 29, 2024
23 of 27 checks passed
@ArthurZucker ArthurZucker deleted the fix-regression-loading branch October 29, 2024 10:41
ArthurZucker pushed a commit that referenced this pull request Oct 29, 2024
* fix regression

* add test for torchao

* expected output

* better fix
BernardZach pushed a commit to BernardZach/transformers that referenced this pull request Dec 5, 2024
* fix regression

* add test for torchao

* expected output

* better fix
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