huggingface / transformers

πŸ€— Transformers: State-of-the-art Machine Learning for Pytorch, TensorFlow, and JAX.
https://huggingface.co/transformers
Apache License 2.0
131.91k stars 26.27k forks source link

TextToVideo tool raising name 'init_empty_weights' is not defined error #23380

Closed freddyaboulton closed 1 year ago

freddyaboulton commented 1 year ago

System Info

2023-05-15 21:13:50.400043: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Could not find TensorRT WARNING:tensorflow:From /usr/local/lib/python3.10/dist-packages/transformers/commands/env.py:63: is_gpu_available (from tensorflow.python.framework.test_util) is deprecated and will be removed in a future version. Instructions for updating: Use tf.config.list_physical_devices('GPU') instead. No GPU/TPU found, falling back to CPU. (Set TF_CPP_MIN_LOG_LEVEL=0 and rerun for more info.)

Copy-and-paste the text below in your GitHub issue and FILL OUT the two last points.

Who can help?

@LysandreJik

Information

Tasks

Reproduction

from transformers import Tool, OpenAiAgent, HfAgent

agent = HfAgent("https://api-inference.huggingface.co/models/bigcode/starcoder")
output = agent.run("Please make a video of `prompt`", prompt="a man eating spaghetti")
/usr/local/lib/python3.10/dist-packages/transformers/tools/python_interpreter.py:101 in          β”‚
β”‚ evaluate_ast                                                                                     β”‚
β”‚                                                                                                  β”‚
β”‚    98 β”‚   β”‚   return evaluate_assign(expression, state, tools)                                   β”‚
β”‚    99 β”‚   elif isinstance(expression, ast.Call):                                                 β”‚
β”‚   100 β”‚   β”‚   # Function call -> we return the value of the function call                        β”‚
β”‚ ❱ 101 β”‚   β”‚   return evaluate_call(expression, state, tools)                                     β”‚
β”‚   102 β”‚   elif isinstance(expression, ast.Constant):                                             β”‚
β”‚   103 β”‚   β”‚   # Constant -> just return the value                                                β”‚
β”‚   104 β”‚   β”‚   return expression.value                                                            β”‚
β”‚                                                                                                  β”‚
β”‚ /usr/local/lib/python3.10/dist-packages/transformers/tools/python_interpreter.py:167 in          β”‚
β”‚ evaluate_call                                                                                    β”‚
β”‚                                                                                                  β”‚
β”‚   164 β”‚   # Todo deal with args                                                                  β”‚
β”‚   165 β”‚   args = [evaluate_ast(arg, state, tools) for arg in call.args]                          β”‚
β”‚   166 β”‚   kwargs = {keyword.arg: evaluate_ast(keyword.value, state, tools) for keyword in call   β”‚
β”‚ ❱ 167 β”‚   return func(*args, **kwargs)                                                           β”‚
β”‚   168                                                                                            β”‚
β”‚   169                                                                                            β”‚
β”‚   170 def evaluate_subscript(subscript, state, tools):                                           β”‚
β”‚                                                                                                  β”‚
β”‚ /root/.cache/huggingface/modules/transformers_modules/huggingface-tools/text-to-video/15f8f33935 β”‚
β”‚ f9653aa806382d1536f8a48a0c6cc0/text_to_video.py:45 in __call__                                   β”‚
β”‚                                                                                                  β”‚
β”‚   42 β”‚                                                                                           β”‚
β”‚   43 β”‚   def __call__(self, prompt, seconds=2):                                                  β”‚
β”‚   44 β”‚   β”‚   if not self.is_initialized:                                                         β”‚
β”‚ ❱ 45 β”‚   β”‚   β”‚   self.setup()                                                                    β”‚
β”‚   46 β”‚   β”‚                                                                                       β”‚
β”‚   47 β”‚   β”‚   return self.pipeline(prompt, num_frames=8 * seconds).frames                         β”‚
β”‚   48                                                                                             β”‚
β”‚                                                                                                  β”‚
β”‚ /root/.cache/huggingface/modules/transformers_modules/huggingface-tools/text-to-video/15f8f33935 β”‚
β”‚ f9653aa806382d1536f8a48a0c6cc0/text_to_video.py:36 in setup                                      β”‚
β”‚                                                                                                  β”‚
β”‚   33 β”‚   β”‚   if self.device is None:                                                             β”‚
β”‚   34 β”‚   β”‚   β”‚   self.device = get_default_device()                                              β”‚
β”‚   35 β”‚   β”‚                                                                                       β”‚
β”‚ ❱ 36 β”‚   β”‚   self.pipeline = DiffusionPipeline.from_pretrained(                                  β”‚
β”‚   37 β”‚   β”‚   β”‚   self.default_checkpoint, variant="fp16"                                         β”‚
β”‚   38 β”‚   β”‚   )                                                                                   β”‚
β”‚   39 β”‚   β”‚   self.pipeline.to(self.device)                                                       β”‚
β”‚                                                                                                  β”‚
β”‚ /usr/local/lib/python3.10/dist-packages/diffusers/pipelines/pipeline_utils.py:1039 in            β”‚
β”‚ from_pretrained                                                                                  β”‚
β”‚                                                                                                  β”‚
β”‚   1036 β”‚   β”‚   β”‚   β”‚   loaded_sub_model = passed_class_obj[name]                                 β”‚
β”‚   1037 β”‚   β”‚   β”‚   else:                                                                         β”‚
β”‚   1038 β”‚   β”‚   β”‚   β”‚   # load sub model                                                          β”‚
β”‚ ❱ 1039 β”‚   β”‚   β”‚   β”‚   loaded_sub_model = load_sub_model(                                        β”‚
β”‚   1040 β”‚   β”‚   β”‚   β”‚   β”‚   library_name=library_name,                                            β”‚
β”‚   1041 β”‚   β”‚   β”‚   β”‚   β”‚   class_name=class_name,                                                β”‚
β”‚   1042 β”‚   β”‚   β”‚   β”‚   β”‚   importable_classes=importable_classes,                                β”‚
β”‚                                                                                                  β”‚
β”‚ /usr/local/lib/python3.10/dist-packages/diffusers/pipelines/pipeline_utils.py:445 in             β”‚
β”‚ load_sub_model                                                                                   β”‚
β”‚                                                                                                  β”‚
β”‚    442 β”‚                                                                                         β”‚
β”‚    443 β”‚   # check if the module is in a subdirectory                                            β”‚
β”‚    444 β”‚   if os.path.isdir(os.path.join(cached_folder, name)):                                  β”‚
β”‚ ❱  445 β”‚   β”‚   loaded_sub_model = load_method(os.path.join(cached_folder, name), **loading_kwar  β”‚
β”‚    446 β”‚   else:                                                                                 β”‚
β”‚    447 β”‚   β”‚   # else load from the root directory                                               β”‚
β”‚    448 β”‚   β”‚   loaded_sub_model = load_method(cached_folder, **loading_kwargs)                   β”‚
β”‚                                                                                                  β”‚
β”‚ /usr/local/lib/python3.10/dist-packages/transformers/modeling_utils.py:2608 in from_pretrained   β”‚
β”‚                                                                                                  β”‚
β”‚   2605 β”‚   β”‚   β”‚   logger.info("Detected DeepSpeed ZeRO-3: activating zero.init() for this mode  β”‚
β”‚   2606 β”‚   β”‚   β”‚   init_contexts = [deepspeed.zero.Init(config_dict_or_path=deepspeed_config())  β”‚
β”‚   2607 β”‚   β”‚   elif load_in_8bit or low_cpu_mem_usage:                                           β”‚
β”‚ ❱ 2608 β”‚   β”‚   β”‚   init_contexts.append(init_empty_weights())                                    β”‚
β”‚   2609 β”‚   β”‚                                                                                     β”‚
β”‚   2610 β”‚   β”‚   with ContextManagers(init_contexts):                                              β”‚
β”‚   2611 β”‚   β”‚   β”‚   model = cls(config, *model_args, **model_kwargs)                              β”‚
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
NameError: name 'init_empty_weights' is not defined

Same behavior calling the tool directly,

from transformers.tools import load_tool
tool = load_tool("huggingface-tools/text-to-video")
tool(prompt="a man eating spaghetti")

Expected behavior

The tool does not error

LysandreJik commented 1 year ago

Thanks for reporting @freddyaboulton! Do you have accelerate installed? If so, which version?

github-actions[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the contributing guidelines are likely to be ignored.