ComfyUI调用GPU失败报错,求助设置PATH及其他解决方法
--- Applied providers: ['CPUExecutionProvider'], with options: {'CPUExecutionProvider': {}}
find model: E:\ComfyUI_windows_portable\ComfyUI\models\insightface\models\antelopev2\glintr100.onnx recognition ['None', 3, 112, 112] 127.5 127.5
2024-08-05 08:11:43.6520467 [E:onnxruntime:Default, provider_bridge_ort.cc:1745 onnxruntime::TryGetProviderInfo_CUDA] D:\a_work\1\s\onnxruntime\core\session\provider_bridge_ort.cc:1426 onnxruntime::ProviderLibrary::Get [ONNXRuntimeError] : 1 : FAIL : LoadLibrary failed with error 126 "" when trying to load "E:\ComfyUI_windows_portable\python_embeded\Lib\site-packages\onnxruntime\capi\onnxruntime_providers_cuda.dll"
一、临时设置PATH环境变量的操作步骤
- 按下Win+R,输入
cmd回车打开命令提示符 - 复制粘贴以下命令执行(注意:如果你的CUDA版本不是v10.1,替换路径中的版本号为实际安装的版本):
SET PATH=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\extras\CUPTI\lib64;%PATH% - 在同一个命令提示符窗口中,找到ComfyUI的NVIDIA GPU启动脚本(如
run_nvidia_gpu.bat),将其拖到窗口中回车启动
二、其他排查与修复方案
- 版本兼容性检查
- 确认
onnxruntime-gpu版本与CUDA版本匹配:CUDA 11.x对应onnxruntime-gpu 1.10及以上,CUDA 12.x需更高版本 - 便携版ComfyUI可通过以下命令查看当前版本:
E:\ComfyUI_windows_portable\python_embeded\python.exe -m pip list | findstr onnxruntime - 版本不兼容则卸载重装:
E:\ComfyUI_windows_portable\python_embeded\python.exe -m pip uninstall onnxruntime onnxruntime-gpu E:\ComfyUI_windows_portable\python_embeded\python.exe -m pip install onnxruntime-gpu==对应版本号
- 确认
- 安装CUDNN依赖
- 下载对应CUDA版本的CUDNN,解压后将bin、include、lib/x64下的文件分别复制到CUDA安装目录的对应文件夹中
- 更新NVIDIA驱动
- 通过GeForce Experience或NVIDIA官网下载安装最新显卡驱动,旧驱动可能无法适配当前CUDA版本
- 确认启动脚本正确性
- 确保运行的是
run_nvidia_gpu.bat而非CPU启动脚本,该脚本默认配置了GPU运行所需的环境变量
- 确保运行的是
- 修复缺失DLL文件
- 用Dependency Walker工具打开
onnxruntime_providers_cuda.dll,查看缺失的依赖文件,从CUDA安装目录或微软VC++运行库中补充
- 用Dependency Walker工具打开
内容的提问来源于stack exchange,提问作者user26646123

