Skip to content

NameError: name 'init_empty_weights' is not defined #37326

@icode

Description

@icode

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions