Python ONNX-GPU 使用记录

1,313 阅读2分钟

「这是我参与2022首次更文挑战的第17天,活动详情查看:2022首次更文挑战」。

Microsoft 和合作伙伴社区创建了 ONNX 作为表示机器学习模型的开放标准。 许多框架(包括 TensorFlow、PyTorch、SciKit-Learn、Keras、Chainer、MXNet、MATLAB 和 SparkML)中的模型都可以导出或转换为标准 ONNX 格式。 模型采用 ONNX 格式后,可在各种平台和设备上运行。 本文记录Python 平台 ONNX-GPU 相关内容。

简介

ONNX Runtime是一个跨平台的推理和训练机器学习加速器。

支持Linux和Windows平台CPU和GPU运算,对mac和手机终端也有相应支持。

SystemCPUGPUEPs
WindowsBuild StatusBuild StatusBuild Status
LinuxBuild Status Build Status Build Status Build Status Build StatusBuild Status Build Status Build Status Build StatusBuild Status Build Status
MacBuild Status Build Status
AndroidBuild Status
iOSBuild Status
WebAssemblyBuild Status
  • ONNX Runtime inference

ONNX运行时推断可以实现更快的客户体验和更低的成本,支持来自深度学习框架(如PyTorch和TensorFlow/Keras)的模型,以及经典的机器学习库(如scikit learn、LightGBM、XGBoost等)。ONNX运行时与不同的硬件、驱动程序和操作系统兼容,并通过在适用的情况下利用硬件加速器以及图形优化和转换提供最佳性能。

官方文档:www.onnxruntime.ai/docs/#onnx-…

ONNX Runtime training

通过对现有PyTorch培训脚本进行单行添加,ONNX Runtime培训可加快多节点NVIDIA GPU上变压器模型的模型培训时间。

官方文档:www.onnxruntime.ai/docs/#onnx-…

安装

  • 在Python下安装,CPU版:
pip install onnxruntime
  • 在Python下安装,GPU版:
pip install onnxruntime-gpu

版本要求

onnx与onnxruntime版本关系

官方链接:github.com/microsoft/o…

ONNX Runtime release versionONNX release versionONNX opset versionONNX ML opset versionSupported ONNX IR versionWindows ML Availability
1.8.01.8 down to 1.21327Windows AI 1.8+
1.7.01.8 down to 1.21327Windows AI 1.7+
1.6.01.8 down to 1.21327Windows AI 1.6+
1.5.31.7 down to 1.21227Windows AI 1.5+
1.5.21.7 down to 1.21227Windows AI 1.5+
1.5.11.7 down to 1.21227Windows AI 1.5+
1.4.01.7 down to 1.21227Windows AI 1.4+
1.3.11.7 down to 1.21227Windows AI 1.4+
1.3.01.7 down to 1.21227Windows AI 1.3+
1.2.0 1.1.2 1.1.1 1.1.01.6 down to 1.21126Windows AI 1.3+
1.0.01.6 down to 1.21126Windows AI 1.3+
0.5.01.5 down to 1.21015Windows AI 1.3+
0.4.01.5 down to 1.21015Windows AI 1.3+
0.3.1 0.3.01.4 down to 1.2913Windows 10 2004+
0.2.1 0.2.01.3 down to 1.2813Windows 10 1903+
0.1.5 0.1.41.3 down to 1.2813Windows 10 1809+

onnxruntime 与 CUDA cuDNN版本要求

官方链接:www.onnxruntime.ai/docs/refere…

ONNX RuntimeCUDAcuDNNNotes
1.811.0.38.0.4 (Linux) 8.0.2.39 (Windows)libcudart 11.0.221 libcufft 10.2.1.245 libcurand 10.2.1.245 libcublasLt 11.2.0.252 libcublas 11.2.0.252 libcudnn 8.0.4 libcupti.so 2020.1.1
1.711.0.38.0.4 (Linux) 8.0.2.39 (Windows)libcudart 11.0.221 libcufft 10.2.1.245 libcurand 10.2.1.245 libcublasLt 11.2.0.252 libcublas 11.2.0.252 libcudnn 8.0.4
1.5-1.610.28.0.3CUDA 11 can be built from source
1.2-1.410.17.6.5Requires cublas10-10.2.1.243; cublas 10.1.x will not work
1.0-1.110.07.6.4CUDA versions from 9.1 up to 10.1, and cuDNN versions from 7.1 up to 7.4 should also work with Visual Studio 2017

参考资料