Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NameError: name 'init_empty_weights' is not defined while using hugging face models

I am trying to set up hugging face locally and im running into this issue.

NameError: name 'init_empty_weights' is not defined

Here is the code I have tested my installation with

from transformers import pipeline
classifier = pipeline("sentiment-analysis")
text = "I love using Hugging Face Transformers!"
result = classifier(text)
print(result)


transformers: 4.51.0
tokenizers: 0.21.1
accelerate: 1.6.0
sentence-transformers: 4.0.2
huggingface_hub: 0.30.1
I am currently using pytorch-metal mac M3 pro.

What causes this, and how can I fix it?

like image 541
cosm1c v1bes Avatar asked Apr 17 '26 09:04

cosm1c v1bes


2 Answers

I have the same issue. The issue is related to https://github.com/huggingface/transformers/pull/37337

In my case, installing accelerate fix the issue, as the workaround.

pip install accelerate
like image 134
kenma Avatar answered Apr 19 '26 13:04

kenma


Try using this version, it should resolve the issue.

transformers==4.50.3
like image 44
Kamalpreet Kaur Avatar answered Apr 19 '26 13:04

Kamalpreet Kaur