You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

仅CPU环境运行PyTorch时[WinError 127]错误的解决方法

无GPU环境下运行CodWOE模型的解决步骤
  • 彻底清理CUDA相关Torch残留
    先完全卸载现有PyTorch相关包:

    # Conda环境
    conda uninstall torch torchvision torchaudio -y
    # Pip环境
    pip uninstall torch torchvision torchaudio -y
    

    手动删除Anaconda环境目录下的Lib\site-packages\torch文件夹,再清理缓存:

    pip cache purge
    conda clean -a -y
    
  • 重新安装纯CPU版PyTorch
    推荐安装兼容性更好的PyTorch 2.x纯CPU版本:

    pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
    

    若坚持使用1.8.1版本,执行:

    pip install torch==1.8.1+cpu torchvision==0.9.1+cpu torchaudio==0.8.1 -f https://download.pytorch.org/whl/torch_stable.html
    

    安装完成后验证:运行import torch; print(torch.cuda.is_available()),输出应为False。

  • 强制模型使用CPU运行

    • 遍历代码中所有设备指定逻辑,直接替换为device = torch.device('cpu'),删除所有cuda相关的条件判断
    • 模型加载时添加map_location='cpu'参数,示例:
      model = torch.load('model_path.pth', map_location='cpu')
      
    • 注释或删除所有涉及CUDA的操作代码,比如torch.cuda.empty_cache()
  • 排查依赖冲突
    用pip list查看环境包列表,确保torch、torchvision、torchaudio均为带+cpu后缀的版本;若存在其他依赖包强制引入CUDA版Torch,需卸载后重新安装其CPU兼容版本。

内容的提问来源于stack exchange,提问作者user11652533

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.09 22:22:32