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

Fix regression loading dtype #34409

Merged
merged 6 commits into from
Oct 29, 2024
Merged

Fix regression loading dtype #34409

merged 6 commits into from
Oct 29, 2024

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
2015aroras pushed a commit to 2015aroras/transformers that referenced this pull request Nov 15, 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.

4 participants