[GH-ISSUE #55] Python库矛盾 #43

Closed
opened 2026-10-26 21:12:07 +00:00 by bsakaguchi · 15 comments
Owner

Originally created by @ResonanceForge on GitHub (Jan 23, 2025).
Original GitHub issue: https://github.com/deepseek-ai/DeepSeek-R1/issues/55

各相关版本信息

torch 2.5.1
transformers 4.48.1
Python 3.12.8 | packaged by Anaconda, Inc.
windows 10 1709 x64

使用Huggingface

# Use a pipeline as a high-level helper
from transformers import pipeline

messages = [
    {"role": "user", "content": "Who are you?"},
]
pipe = pipeline("text-generation", model="deepseek-ai/DeepSeek-R1", trust_remote_code=True)
pipe(messages)

错误信息

Traceback (most recent call last):
  File "my_main_script.py", line 7, in <module>
    pipe = pipeline("text-generation", model="deepseek-ai/DeepSeek-R1", trust_remote_code=True)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "my_python_path\Lib\site-packages\transformers\pipelines\__init__.py", line 940, in pipeline
    framework, model = infer_framework_load_model(
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "my_python_path\Lib\site-packages\transformers\pipelines\base.py", line 289, in infer_framework_load_model
    model = model_class.from_pretrained(model, **kwargs)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "my_python_path\Lib\site-packages\transformers\models\auto\auto_factory.py", line 553, in from_pretrained
    model_class = get_class_from_dynamic_module(
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "my_python_path\Lib\site-packages\transformers\dynamic_module_utils.py", line 553, in get_class_from_dynamic_module
    return get_class_in_module(class_name, final_module, force_reload=force_download)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "my_python_path\Lib\site-packages\transformers\dynamic_module_utils.py", line 250, in get_class_in_module
    module_spec.loader.exec_module(module)
  File "<frozen importlib._bootstrap_external>", line 999, in exec_module
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "my_user_dir\.cache\huggingface\modules\transformers_modules\deepseek-ai\DeepSeek-R1\4dc77d4932316bdaa6f255ee7ad2ea3733a8ca23\modeling_deepseek.py", line 44, in <module>
    from transformers.pytorch_utils import (
ImportError: cannot import name 'is_torch_greater_or_equal_than_1_13' from 'transformers.pytorch_utils' (D:\Programs\anaconda3\envs\ai\Lib\site-packages\transformers\pytorch_utils.py). Did you mean: 'is_torch_greater_or_equal_than_2_1'?

问题主要出现于modeling_deepseek.py 第44~47行

from transformers.pytorch_utils import (
    ALL_LAYERNORM_LAYERS,
    is_torch_greater_or_equal_than_1_13,
)
Originally created by @ResonanceForge on GitHub (Jan 23, 2025). Original GitHub issue: https://github.com/deepseek-ai/DeepSeek-R1/issues/55 各相关版本信息 ``` torch 2.5.1 transformers 4.48.1 Python 3.12.8 | packaged by Anaconda, Inc. windows 10 1709 x64 ``` 使用Huggingface ```python # Use a pipeline as a high-level helper from transformers import pipeline messages = [ {"role": "user", "content": "Who are you?"}, ] pipe = pipeline("text-generation", model="deepseek-ai/DeepSeek-R1", trust_remote_code=True) pipe(messages) ``` 错误信息 ``` Traceback (most recent call last): File "my_main_script.py", line 7, in <module> pipe = pipeline("text-generation", model="deepseek-ai/DeepSeek-R1", trust_remote_code=True) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "my_python_path\Lib\site-packages\transformers\pipelines\__init__.py", line 940, in pipeline framework, model = infer_framework_load_model( ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "my_python_path\Lib\site-packages\transformers\pipelines\base.py", line 289, in infer_framework_load_model model = model_class.from_pretrained(model, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "my_python_path\Lib\site-packages\transformers\models\auto\auto_factory.py", line 553, in from_pretrained model_class = get_class_from_dynamic_module( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "my_python_path\Lib\site-packages\transformers\dynamic_module_utils.py", line 553, in get_class_from_dynamic_module return get_class_in_module(class_name, final_module, force_reload=force_download) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "my_python_path\Lib\site-packages\transformers\dynamic_module_utils.py", line 250, in get_class_in_module module_spec.loader.exec_module(module) File "<frozen importlib._bootstrap_external>", line 999, in exec_module File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed File "my_user_dir\.cache\huggingface\modules\transformers_modules\deepseek-ai\DeepSeek-R1\4dc77d4932316bdaa6f255ee7ad2ea3733a8ca23\modeling_deepseek.py", line 44, in <module> from transformers.pytorch_utils import ( ImportError: cannot import name 'is_torch_greater_or_equal_than_1_13' from 'transformers.pytorch_utils' (D:\Programs\anaconda3\envs\ai\Lib\site-packages\transformers\pytorch_utils.py). Did you mean: 'is_torch_greater_or_equal_than_2_1'? ``` 问题主要出现于[modeling_deepseek.py 第44~47行](https://huggingface.co/deepseek-ai/DeepSeek-R1/blob/main/modeling_deepseek.py#L44) ```python from transformers.pytorch_utils import ( ALL_LAYERNORM_LAYERS, is_torch_greater_or_equal_than_1_13, ) ```
bsakaguchi 2026-10-26 21:12:07 +00:00
Author
Owner

@Huowuge commented on GitHub (Jan 24, 2025):

Same error, python version 3.12, windows 11.
I downgrade transformers version to 2.21 and python to 3.10, the error has disappeared, but a new one has appeared.
Need to install flash-attn, but no version can install successfully.

<!-- gh-comment-id:2612397346 --> @Huowuge commented on GitHub (Jan 24, 2025): Same error, python version 3.12, windows 11. I downgrade transformers version to 2.21 and python to 3.10, the error has disappeared, but a new one has appeared. Need to install flash-attn, but no version can install successfully.
Author
Owner

@zharry29 commented on GitHub (Jan 24, 2025):

Same issue!

<!-- gh-comment-id:2613449300 --> @zharry29 commented on GitHub (Jan 24, 2025): Same issue!
Author
Owner

@psychpsych commented on GitHub (Jan 27, 2025):

Hey,

Check out the doc:

Hugging Face's Transformers has not been directly supported yet.**

<!-- gh-comment-id:2616627983 --> @psychpsych commented on GitHub (Jan 27, 2025): Hey, Check out the doc: > Hugging Face's Transformers has not been directly supported yet.**
Author
Owner

@zharry29 commented on GitHub (Jan 27, 2025):

I got things to work using transformers==4.37.2 and flash_attn==1.0.5 (reference, reference). Hopefully the support for the latest version of Transformers would be implemented soon.

<!-- gh-comment-id:2616645797 --> @zharry29 commented on GitHub (Jan 27, 2025): I got things to work using transformers==4.37.2 and flash_attn==1.0.5 ([reference](https://github.com/huggingface/transformers/issues/35471), [reference](https://github.com/Dao-AILab/flash-attention/issues/246)). Hopefully the support for the latest version of Transformers would be implemented soon.
Author
Owner

@quanq666 commented on GitHub (Jan 27, 2025):

Got the same issue: ImportError: cannot import name 'is_torch_greater_or_equal_than_1_13' from 'transformers.pytorch_utils'

<!-- gh-comment-id:2616672332 --> @quanq666 commented on GitHub (Jan 27, 2025): Got the same issue: ImportError: cannot import name 'is_torch_greater_or_equal_than_1_13' from 'transformers.pytorch_utils'
Author
Owner

@quanq666 commented on GitHub (Jan 27, 2025):

Got the same issue: ImportError: cannot import name 'is_torch_greater_or_equal_than_1_13' from 'transformers.pytorch_utils'

Updated to is_torch_greater_or_equal_than_2_1 works for me.

<!-- gh-comment-id:2616734415 --> @quanq666 commented on GitHub (Jan 27, 2025): > Got the same issue: ImportError: cannot import name 'is_torch_greater_or_equal_than_1_13' from 'transformers.pytorch_utils' Updated to `is_torch_greater_or_equal_than_2_1` works for me.
Author
Owner

@ruidazeng commented on GitHub (Jan 28, 2025):

Got the same issue: ImportError: cannot import name 'is_torch_greater_or_equal_than_1_13' from 'transformers.pytorch_utils'

Updated to is_torch_greater_or_equal_than_2_1 works for me.

Which line did you fix it in?

<!-- gh-comment-id:2619153579 --> @ruidazeng commented on GitHub (Jan 28, 2025): > > Got the same issue: ImportError: cannot import name 'is_torch_greater_or_equal_than_1_13' from 'transformers.pytorch_utils' > > Updated to `is_torch_greater_or_equal_than_2_1` works for me. Which line did you fix it in?
Author
Owner

@ruidazeng commented on GitHub (Jan 28, 2025):

I got things to work using transformers==4.37.2 and flash_attn==1.0.5 (reference, reference). Hopefully the support for the latest version of Transformers would be implemented soon.

Did you fix the unknown quantization type, got fp8 issue?

<!-- gh-comment-id:2619157524 --> @ruidazeng commented on GitHub (Jan 28, 2025): > I got things to work using transformers==4.37.2 and flash_attn==1.0.5 ([reference](https://github.com/huggingface/transformers/issues/35471), [reference](https://github.com/Dao-AILab/flash-attention/issues/246)). Hopefully the support for the latest version of Transformers would be implemented soon. Did you fix the `unknown quantization type, got fp8` issue?
Author
Owner

@Jiadalee commented on GitHub (Jan 28, 2025):

Got the same issue: ImportError: cannot import name 'is_torch_greater_or_equal_than_1_13' from 'transformers.pytorch_utils'

Updated to is_torch_greater_or_equal_than_2_1 works for me.

Which line did you fix it in?

I fixed it. but as you mentioned, I also got the unknown quantization type, got fp8 issue

<!-- gh-comment-id:2619182833 --> @Jiadalee commented on GitHub (Jan 28, 2025): > > > Got the same issue: ImportError: cannot import name 'is_torch_greater_or_equal_than_1_13' from 'transformers.pytorch_utils' > > > > > > Updated to `is_torch_greater_or_equal_than_2_1` works for me. > > Which line did you fix it in? I fixed it. but as you mentioned, I also got the unknown quantization type, got fp8 issue
Author
Owner

@Jiadalee commented on GitHub (Jan 28, 2025):

Got the same issue: ImportError: cannot import name 'is_torch_greater_or_equal_than_1_13' from 'transformers.pytorch_utils'

Updated to is_torch_greater_or_equal_than_2_1 works for me.

pls change both lines 46 and 69 from _1_13 to _2_1

<!-- gh-comment-id:2619186460 --> @Jiadalee commented on GitHub (Jan 28, 2025): > > Got the same issue: ImportError: cannot import name 'is_torch_greater_or_equal_than_1_13' from 'transformers.pytorch_utils' > > Updated to `is_torch_greater_or_equal_than_2_1` works for me. pls change both lines 46 and 69 from _1_13 to _2_1
Author
Owner

@quanq666 commented on GitHub (Jan 28, 2025):

Got the same issue: ImportError: cannot import name 'is_torch_greater_or_equal_than_1_13' from 'transformers.pytorch_utils'

Updated to is_torch_greater_or_equal_than_2_1 works for me.

Which line did you fix it in?

I fixed it. but as you mentioned, I also got the unknown quantization type, got fp8 issue

Yeah I also got the fp8 exception, I think that's the default model loading from deepseek config.
Since I tried to run it on my Macbook (M1), so I need to override the quantization configuration during model loading. -> set device_map="auto"

<!-- gh-comment-id:2619658954 --> @quanq666 commented on GitHub (Jan 28, 2025): > > > > Got the same issue: ImportError: cannot import name 'is_torch_greater_or_equal_than_1_13' from 'transformers.pytorch_utils' > > > > > > > > > Updated to `is_torch_greater_or_equal_than_2_1` works for me. > > > > > > Which line did you fix it in? > > I fixed it. but as you mentioned, I also got the unknown quantization type, got fp8 issue Yeah I also got the fp8 exception, I think that's the default model loading from deepseek config. Since I tried to run it on my Macbook (M1), so I need to override the quantization configuration during model loading. -> set `device_map="auto"`
Author
Owner

@Jiadalee commented on GitHub (Jan 29, 2025):

Got the same issue: ImportError: cannot import name 'is_torch_greater_or_equal_than_1_13' from 'transformers.pytorch_utils'

Updated to is_torch_greater_or_equal_than_2_1 works for me.

Which line did you fix it in?

I fixed it. but as you mentioned, I also got the unknown quantization type, got fp8 issue

Yeah I also got the fp8 exception, I think that's the default model loading from deepseek config. Since I tried to run it on my Macbook (M1), so I need to override the quantization configuration during model loading. -> set device_map="auto"

@quanq666 you mean you fixed the fp8 issue by setting device_map="auto"?

<!-- gh-comment-id:2621765355 --> @Jiadalee commented on GitHub (Jan 29, 2025): > > > > > Got the same issue: ImportError: cannot import name 'is_torch_greater_or_equal_than_1_13' from 'transformers.pytorch_utils' > > > > > > > > > > > > Updated to `is_torch_greater_or_equal_than_2_1` works for me. > > > > > > > > > Which line did you fix it in? > > > > > > I fixed it. but as you mentioned, I also got the unknown quantization type, got fp8 issue > > Yeah I also got the fp8 exception, I think that's the default model loading from deepseek config. Since I tried to run it on my Macbook (M1), so I need to override the quantization configuration during model loading. -> set `device_map="auto"` @quanq666 you mean you fixed the fp8 issue by setting device_map="auto"?
Author
Owner

@yuxuan-z19 commented on GitHub (Feb 7, 2025):

Got the same issue: ImportError: cannot import name 'is_torch_greater_or_equal_than_1_13' from 'transformers.pytorch_utils'

Updated to is_torch_greater_or_equal_than_2_1 works for me.

Which line did you fix it in?

I fixed it. but as you mentioned, I also got the unknown quantization type, got fp8 issue

Yeah I also got the fp8 exception, I think that's the default model loading from deepseek config. Since I tried to run it on my Macbook (M1), so I need to override the quantization configuration during model loading. -> set device_map="auto"

@quanq666 you mean you fixed the fp8 issue by setting device_map="auto"?

Nope, it's not working on my Ubuntu Jammy + CUDA 12.1. Perhaps fp8 is not officially supported at the moment (see https://github.com/huggingface/transformers/issues/35471)

# rewritten by DeepSeek-r1
from transformers import AutoModelForCausalLM, AutoTokenizer

model = AutoModelForCausalLM.from_pretrained(
    "deepseek-ai/DeepSeek-V3",
    trust_remote_code=True,
    device_map="auto"
)
tokenizer = AutoTokenizer.from_pretrained("deepseek-ai/DeepSeek-V3")

messages = [{"role": "user", "content": "Who are you?"}]
inputs = tokenizer.apply_chat_template(messages, return_tensors="pt").to(model.device)
outputs = model.generate(inputs, max_new_tokens=100)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
<!-- gh-comment-id:2641854183 --> @yuxuan-z19 commented on GitHub (Feb 7, 2025): > > > > > > Got the same issue: ImportError: cannot import name 'is_torch_greater_or_equal_than_1_13' from 'transformers.pytorch_utils' > > > > > > > > > > > > > > > Updated to `is_torch_greater_or_equal_than_2_1` works for me. > > > > > > > > > > > > Which line did you fix it in? > > > > > > > > > I fixed it. but as you mentioned, I also got the unknown quantization type, got fp8 issue > > > > > > Yeah I also got the fp8 exception, I think that's the default model loading from deepseek config. Since I tried to run it on my Macbook (M1), so I need to override the quantization configuration during model loading. -> set `device_map="auto"` > > [@quanq666](https://github.com/quanq666) you mean you fixed the fp8 issue by setting device_map="auto"? Nope, it's not working on my Ubuntu Jammy + CUDA 12.1. Perhaps `fp8` is not officially supported at the moment (see https://github.com/huggingface/transformers/issues/35471) ```python # rewritten by DeepSeek-r1 from transformers import AutoModelForCausalLM, AutoTokenizer model = AutoModelForCausalLM.from_pretrained( "deepseek-ai/DeepSeek-V3", trust_remote_code=True, device_map="auto" ) tokenizer = AutoTokenizer.from_pretrained("deepseek-ai/DeepSeek-V3") messages = [{"role": "user", "content": "Who are you?"}] inputs = tokenizer.apply_chat_template(messages, return_tensors="pt").to(model.device) outputs = model.generate(inputs, max_new_tokens=100) print(tokenizer.decode(outputs[0], skip_special_tokens=True)) ```
Author
Owner

@github-actions[bot] commented on GitHub (Mar 16, 2025):

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you believe this issue is still relevant, please leave a comment to keep it open. Thank you for your contributions!

<!-- gh-comment-id:2727073434 --> @github-actions[bot] commented on GitHub (Mar 16, 2025): This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you believe this issue is still relevant, please leave a comment to keep it open. Thank you for your contributions!
Author
Owner

@github-actions[bot] commented on GitHub (Apr 12, 2025):

false

<!-- gh-comment-id:2798242102 --> @github-actions[bot] commented on GitHub (Apr 12, 2025): false
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
deepseek-ai/DeepSeek-R1#43
No description provided.