使用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~
开心的时候就想分享福利:领券网