完美解决错误 AutoModelForCausalLM requires the PyTorch library but it was not found in your environment

 使用python本地部署DeepSeek。

model = AutoModelForCausalLM.from_pretrained(model_name) 

运行到上述代码时报错:AutoModelForCausalLM requires the PyTorch library but it was not found in your environment

"D:\Program Files\Python38\python.exe" E:\projects\www.i075.com\AI\deepseek-1.5b.py 
None of PyTorch, TensorFlow >= 2.0, or Flax have been found. Models won't be available and only tokenizers, configuration and file/data utilities can be used.
Traceback (most recent call last):
  File "E:\projects\www.i075.com\AI\deepseek-1.5b.py", line 17, in <module>
    model = AutoModelForCausalLM.from_pretrained(model_name, cache_dir=model_path)
  File "D:\Program Files\Python38\lib\site-packages\transformers\utils\import_utils.py", line 1651, in __getattribute__
    requires_backends(cls, cls._backends)
  File "D:\Program Files\Python38\lib\site-packages\transformers\utils\import_utils.py", line 1639, in requires_backends
    raise ImportError("".join(failed))
ImportError: 
AutoModelForCausalLM requires the PyTorch library but it was not found in your environment. Checkout the instructions on the
installation page: https://pytorch.org/get-started/locally/ and follow the ones that match your environment.
Please note that you may need to restart your runtime after installation.

问题原因

这个错误的原因是缺少 PyTorch 库。你的代码中尝试加载模型 AutoModelForCausalLM.from_pretrained("deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B"),该方法依赖于 PyTorch 库来加载模型权重,但在你的 Python 环境中并未安装 PyTorch。

解决办法

使用如下命令安装依赖包 torch 。

pip install torch

 然后执行 DeepSeek 相关代码,完美运行!

解决疑难问题,心情美美哒~O(∩_∩)O~

开心的时候就想分享福利:领券网

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

喜-喜

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值