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

RuntimeError: Failed to import transformers.generation.utils because of the following error (look up to see its traceback): cannot import name 'GenerateOutput' from partially initialized module 'transformers.generation.utils' (most likely due to a circular import) #30888

Open
4 tasks
sysuls1 opened this issue May 18, 2024 · 2 comments

Comments

@sysuls1
Copy link

sysuls1 commented May 18, 2024

System Info

  • transformers version: 4.40.2
  • Platform: Linux-6.5.0-28-generic-x86_64-with-glibc2.35
  • Python version: 3.10.14
  • Huggingface_hub version: 0.20.3
  • Safetensors version: 0.4.2
  • Accelerate version: 0.30.1
  • Accelerate config: not found
  • PyTorch version (GPU?): 2.1.2 (True)
  • Tensorflow version (GPU?): not installed (NA)
  • Flax version (CPU?/GPU?/TPU?): not installed (NA)
  • Jax version: not installed
  • JaxLib version: not installed
  • Using GPU in script?:
  • Using distributed or parallel set-up in script?:

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

Traceback (most recent call last):
File "/root/lspkg/profile.py", line 35, in
model = AutoModelForCausalLM.from_pretrained(
File "/root/anaconda3/envs/qianwen/lib/python3.10/site-packages/transformers/models/auto/auto_factory.py", line 550, in from_pretrained
model_class = get_class_from_dynamic_module(
File "/root/anaconda3/envs/qianwen/lib/python3.10/site-packages/transformers/dynamic_module_utils.py", line 489, in get_class_from_dynamic_module
final_module = get_cached_module_file(
File "/root/anaconda3/envs/qianwen/lib/python3.10/site-packages/transformers/dynamic_module_utils.py", line 315, in get_cached_module_file
modules_needed = check_imports(resolved_module_file)
File "/root/anaconda3/envs/qianwen/lib/python3.10/site-packages/transformers/dynamic_module_utils.py", line 175, in check_imports
importlib.import_module(imp)
File "/root/anaconda3/envs/qianwen/lib/python3.10/importlib/init.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 1050, in _gcd_import
File "", line 1027, in _find_and_load
File "", line 1006, in _find_and_load_unlocked
File "", line 688, in _load_unlocked
File "", line 883, in exec_module
File "", line 241, in _call_with_frames_removed
File "/root/anaconda3/envs/qianwen/lib/python3.10/site-packages/transformers_stream_generator/init.py", line 1, in
from .main import init_stream_support
File "/root/anaconda3/envs/qianwen/lib/python3.10/site-packages/transformers_stream_generator/main.py", line 1, in
from transformers import (
File "", line 1075, in _handle_fromlist
File "/root/anaconda3/envs/qianwen/lib/python3.10/site-packages/transformers/utils/import_utils.py", line 1501, in getattr
value = getattr(module, name)
File "/root/anaconda3/envs/qianwen/lib/python3.10/site-packages/transformers/utils/import_utils.py", line 1500, in getattr
module = self._get_module(self._class_to_module[name])
File "/root/anaconda3/envs/qianwen/lib/python3.10/site-packages/transformers/utils/import_utils.py", line 1512, in _get_module
raise RuntimeError(
RuntimeError: Failed to import transformers.generation.utils because of the following error (look up to see its traceback):
cannot import name 'GenerateOutput' from partially initialized module 'transformers.generation.utils' (most likely due to a circular import) (/root/anaconda3/envs/qianwen/lib/python3.10/site-packages/transformers/generation/utils.py)

Expected behavior

尝试了不同版本的transformers,都是报同样的错误,transformers_stream_generator==0.0.4

@amyeroberts
Copy link
Collaborator

cc @gante @zucchini-nlp

@zucchini-nlp
Copy link
Member

@sysuls1 hey! The reason might be in the way you name the python file. If it has the same name as the package you're trying to import, you have to rename it

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

No branches or pull requests

3 participants