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

Fixing name 'torch' is not defined in bitsandbytes integration #31243

Merged
merged 1 commit into from
Jun 5, 2024
Merged

Fixing name 'torch' is not defined in bitsandbytes integration #31243

merged 1 commit into from
Jun 5, 2024

Conversation

jamesbraza
Copy link
Contributor

With transformers==4.41.2 and this:

from transformers import AutoModelForCausalLM, QuantoConfig

AutoModelForCausalLM.from_pretrained(
    "microsoft/phi-2", low_cpu_mem_usage=True, quantization_config=QuantoConfig(weights="int8")
)

I hit this traceback:

  File "/Users/user/code/repo/venv/lib/python3.12/site-packages/transformers/integrations/bitsandbytes.py", line 331, in <module>
    def dequantize_bnb_weight(weight: torch.nn.Parameter, state=None):
                                      ^^^^^
NameError: name 'torch' is not defined

An alternate would be requiring importers to first run import torch

Cc @younesbelkada @SunMarc @amyeroberts @ArthurZucker based on recent PR reviewers for this file

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.

I can reproduce. Thanks for fixing, this would need a patch cc @younesbelkada
We can also just import torch if torch is available

@ArthurZucker
Copy link
Collaborator

Failing test is unrelated!

@ArthurZucker ArthurZucker merged commit 63fb253 into huggingface:main Jun 5, 2024
19 of 21 checks passed
@jamesbraza jamesbraza deleted the fixing-torch-definition branch June 5, 2024 06:15
@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.

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