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

NameError: name 'init_empty_weights' is not defined #37326

Closed
4 tasks
icode opened this issue Apr 6, 2025 · 15 comments
Closed
4 tasks

NameError: name 'init_empty_weights' is not defined #37326

icode opened this issue Apr 6, 2025 · 15 comments
Labels

Comments

@icode
Copy link

icode commented Apr 6, 2025

System Info

python 3.13
M4 macos 15.4

Who can help?

No response

Information

  • The official example scripts
  • My own modified scripts

Tasks

  • An officially supported task in the examples folder (such as GLUE/SQuAD, ...)
  • My own task or dataset (give details below)

Reproduction

do just

if torch.cuda.is_available():
    device = torch.device("cuda")
else:
    device = torch.device("cpu")
model = CLIPModel.from_pretrained(MODEL_NAME).to(device)

Expected behavior

Using a slow image processor as `use_fast` is unset and a slow processor was saved with this model. `use_fast=True` will be the default behavior in v4.52, even if the model was saved with a slow processor. This will result in minor differences in outputs. You'll still be able to use a slow processor with `use_fast=False`.

Traceback (most recent call last):

  File "/Users/icode/Projects/self/fanfan/ai-backend/app.py", line 5, in <module>

    import handlers

  File "/Users/icode/Projects/self/fanfan/ai-backend/handlers.py", line 16, in <module>

    model = CLIPModel.from_pretrained(MODEL_NAME).to(device)

            ~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^

  File "/Users/icode/Projects/self/fanfan/ai-backend/.venv/lib/python3.13/site-packages/transformers/modeling_utils.py", line 279, in _wrapper

    return func(*args, **kwargs)

  File "/Users/icode/Projects/self/fanfan/ai-backend/.venv/lib/python3.13/site-packages/transformers/modeling_utils.py", line 4333, in from_pretrained

    model_init_context = cls.get_init_context(is_quantized, _is_ds_init_called)

  File "/Users/icode/Projects/self/fanfan/ai-backend/.venv/lib/python3.13/site-packages/transformers/modeling_utils.py", line 3736, in get_init_context

    init_contexts = [no_init_weights(), init_empty_weights()]

                                        ^^^^^^^^^^^^^^^^^^

NameError: name 'init_empty_weights' is not defined
@icode icode added the bug label Apr 6, 2025
@zbowling
Copy link

zbowling commented Apr 6, 2025

same issue. regression in transformers

@Ahajha
Copy link

Ahajha commented Apr 6, 2025

Caused by #37306.

@zbowling
Copy link

zbowling commented Apr 6, 2025

Maybe fixed by #37324

@Samoed
Copy link

Samoed commented Apr 6, 2025

Same issue #37311

@Vishesh-Mistry
Copy link

I was facing the same issue, and downgrading to transformers==4.50.3 resolved it for me.
I found this solution by referring to #37311 (comment)

@Ahajha
Copy link

Ahajha commented Apr 6, 2025

You can also add accelerate as a dependency. This issue pops up in the first place because init_empty_weights is from that library, and is only conditionally imported (if it exists).

@harupy
Copy link
Contributor

harupy commented Apr 7, 2025

Ran into the same error. Can 4.51.0 be yanked?

@ArthurZucker
Copy link
Collaborator

we will patch today

@ArthurZucker
Copy link
Collaborator

sorry everyone for this! cc @Cyrilvallez

@Cyrilvallez
Copy link
Member

This will be fixed in #37337! In the meantime, you can run pip install accelerate to solve it! Super sorry for the disturbance!

@ArthurZucker
Copy link
Collaborator

Closing as this was fixed on main #37337 patching asap

shaahji added a commit to microsoft/Olive that referenced this issue Apr 8, 2025
Latest version of transformers (v4.51.0) now depends on accelerate

This has been reported and fixed in transformers main branch and will be released as patch.
This is a stop gap solution to keep the CI builds working.
huggingface/transformers#37326

Specific errors when running tests:

File "/***/***-venv/lib/python3.10/site-packages/transformers/modeling_utils.py", line 4333, in from_pretrained
  model_init_context = cls.get_init_context(is_quantized, _is_ds_init_called)
File "/***/***-venv/lib/python3.10/site-packages/transformers/modeling_utils.py", line 3736, in get_init_context
  init_contexts = [no_init_weights(), init_empty_weights()]
NameError: name 'init_empty_weights' is not defined
@Ahajha
Copy link

Ahajha commented Apr 8, 2025

Can we get a patch release for this?

@RoyceAroc
Copy link

whats the eta on the patch

shaahji added a commit to microsoft/Olive that referenced this issue Apr 8, 2025
Latest version of transformers (v4.51.0) now depends on accelerate

This has been reported and fixed in transformers main branch and will be released as patch.
This is a stop gap solution to keep the CI builds working.
huggingface/transformers#37326

Specific errors when running tests:

File "/***/***-venv/lib/python3.10/site-packages/transformers/modeling_utils.py", line 4333, in from_pretrained
  model_init_context = cls.get_init_context(is_quantized, _is_ds_init_called)
File "/***/***-venv/lib/python3.10/site-packages/transformers/modeling_utils.py", line 3736, in get_init_context
  init_contexts = [no_init_weights(), init_empty_weights()]
NameError: name 'init_empty_weights' is not defined
@ArthurZucker
Copy link
Collaborator

1h max

@ArthurZucker
Copy link
Collaborator

Patch is out for 3 hours sorry for not mentionning !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

9 participants