这篇博客详细介绍了如何在 windows、ubuntu环境下搭建 onnxruntime-gpu 环境,并进行 ONNX 模型的部署。以下是对该文章内容的总结和补充:

安装 onnxruntimeonnxruntime-gpu

  1. 安装 onnxruntime
    如果你仅需要在 CPU 上进行推理,可以使用以下命令安装:

    pip install onnxruntime
    
  2. 安装 onnxruntime-gpu
    若要在 GPU 上加速推理,需要安装 onnxruntime-gpu。可以有两种方法:
    不依赖于本地主机上的 CUDA 和 cuDNN**

    • 创建 Conda 环境并安装所需版本的 onnxruntime-gpu,CUDA 和 cuDNN:
    conda create -n torch python=3.8
    conda activate torch
     pip install -i https://pypi.tuna.tsinghua.edu.cn/simple  onnxruntime-gpu==1.17.1 numpy <2.0
     conda install   cudnn== 8.9.2.26 
    conda install  pytorch torchvision torchaudio cudatoolkit  -c pytorch -c conda-forge
    

onnx 推理报错:onnxruntime.capi.onnxruntime_pybind11_state.Fail: [ONNXRuntimeError] : 1 : FAIL

    conda install pybind11>=2.12  cudnn

注意事项

  • 确保 onnxruntime-gpu、CUDA 和 cuDNN 的版本兼容,详细的版本对应关系可以参考 ONNX Runtime 的官方文档
  • 实时监控 GPU 使用情况可以使用 watch -n 0.1 nvidia-smi 命令。

希望这些信息能帮助你顺利完成 onnxruntime-gpu 的安装和测试。如果有其他问题或需要进一步帮助,请随时告诉我!

更多推荐