nlphuggingface-transformershuggingface

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?


Solution

  • Try using this version, it should resolve the issue.

    transformers==4.50.3