Problem - NameError: name 'init_empty_weights' is not defined

#8
by artyomboyko - opened

Hello. I try

! pip install accelerate>=0.12.0 transformers[torch]==4.25.1
print("OK")

OK

and

! pip install accelerate>=0.12.0 transformers[torch]==4.25.1
print("OK")

NameError Traceback (most recent call last)
Cell In[10], line 4
1 import torch
2 from transformers import pipeline
----> 4 generate_text = pipeline(model="databricks/dolly-v2-7b", torch_dtype=torch.bfloat16, trust_remote_code=True, device_map="auto")

File ~/.local/lib/python3.9/site-packages/transformers/pipelines/init.py:779, in pipeline(task, model, config, tokenizer, feature_extractor, image_processor, framework, revision, use_fast, use_auth_token, device, device_map, torch_dtype, trust_remote_code, model_kwargs, pipeline_class, **kwargs)
775 # Infer the framework from the model
776 # Forced if framework already defined, inferred if it's None
777 # Will load the correct model if possible
778 model_classes = {"tf": targeted_task["tf"], "pt": targeted_task["pt"]}
--> 779 framework, model = infer_framework_load_model(
780 model,
781 model_classes=model_classes,
782 config=config,
783 framework=framework,
784 task=task,
785 **hub_kwargs,
786 **model_kwargs,
787 )
789 model_config = model.config
790 hub_kwargs["_commit_hash"] = model.config._commit_hash

File ~/.local/lib/python3.9/site-packages/transformers/pipelines/base.py:262, in infer_framework_load_model(model, config, model_classes, task, framework, **model_kwargs)
256 logger.warning(
257 "Model might be a PyTorch model (ending with .bin) but PyTorch is not available. "
258 "Trying to load the model with Tensorflow."
259 )
261 try:
--> 262 model = model_class.from_pretrained(model, **kwargs)
263 if hasattr(model, "eval"):
264 model = model.eval()

File ~/.local/lib/python3.9/site-packages/transformers/models/auto/auto_factory.py:471, in _BaseAutoModelClass.from_pretrained(cls, pretrained_model_name_or_path, *model_args, **kwargs)
469 elif type(config) in cls._model_mapping.keys():
470 model_class = _get_model_class(config, cls._model_mapping)
--> 471 return model_class.from_pretrained(
472 pretrained_model_name_or_path, *model_args, config=config, **hub_kwargs, **kwargs
473 )
474 raise ValueError(
475 f"Unrecognized configuration class {config.class} for this kind of AutoModel: {cls.name}.\n"
476 f"Model type should be one of {', '.join(c.name for c in cls._model_mapping.keys())}."
477 )

File ~/.local/lib/python3.9/site-packages/transformers/modeling_utils.py:2626, in PreTrainedModel.from_pretrained(cls, pretrained_model_name_or_path, *model_args, **kwargs)
2624 init_contexts = [deepspeed.zero.Init(config_dict_or_path=deepspeed_config())] + init_contexts
2625 elif load_in_8bit or low_cpu_mem_usage:
-> 2626 init_contexts.append(init_empty_weights())
2628 with ContextManagers(init_contexts):
2629 model = cls(config, *model_args, **model_kwargs)

NameError: name 'init_empty_weights' is not defined

I have transformers 4.28.1 installed and 24 GB VideoRAM.

I didn't find solution in google... Can someone help?

Databricks org

Is this on Databricks?
Can you try installing the latest requirements.txt?
I suspect you have an mismatched pytorch version and that could be causing this.
If so I think we need to update the code snippets to show you have to fix a certain torch version too.

So, I must update Pytorch? I have Pytorch 2.0.0+cu117 installed.

I download model from HuggingFace Hub. I use WSL2 Debian.

Databricks org

Oh no, downgrade. Use 1.13.1

I undestan. Thanks for you help. I create new WSL2 for this...

artyomboyko changed discussion status to closed

Sign up or log in to comment