用于设备端训练的构建
先决条件
- Python 3.x
- CMake
训练阶段的构建说明
-
克隆仓库
git clone --recursive https://github.com/Microsoft/onnxruntime.git cd onnxruntime
-
构建用于
设备端训练
的 ONNX Runtimea. 对于 Windows
.\build.bat --config RelWithDebInfo --cmake_generator "Visual Studio 17 2022" --build_shared_lib --parallel --enable_training_apis
b. 对于 Linux
./build.sh --config RelWithDebInfo --build_shared_lib --parallel --enable_training_apis
c. 对于 Android
请参阅Android 构建说明并添加
--enable_training_apis
构建标志。d. 对于 macOS
请参阅macOS 推理构建说明并添加
--enable_training_apis
构建标志。e. 对于 iOS
请参阅iOS 构建说明并添加
--enable_training_apis
构建标志。f. 对于 Web
请参阅Web 构建说明。
注意
要构建 C# 绑定,请在上面的构建命令中添加
--build_nuget
标志。- 要构建 Python wheel
- 在上面的构建命令中添加
--build_wheel
标志。- 使用
python -m pip install build/Linux/RelWithDebInfo/dist/*.whl
安装 wheel
config
标志可以是Debug
、RelWithDebInfo
、Release
、MinSizeRel
中的一个。请使用适合您用例的配置。
--enable_training_apis
标志可以与--minimal_build
标志结合使用。生成训练构件的离线阶段只能使用 Python 完成(通过使用
--build_wheel
标志)。- 上面的构建命令仅构建用于 CPU 执行提供程序。要构建用于 CUDA 执行提供程序,请添加以下标志:
--use_cuda
--cuda_home {您的 cuda 主目录,例如 /usr/local/cuda/}
--cudnn_home {您的 cuda 主目录,例如 /usr/local/cuda/}
--cuda_version={版本,例如 11.8}
用于大型模型训练的构建
目录
Linux
./build.sh --config RelWithDebInfo --build_shared_lib --parallel --enable_training
GPU / CUDA
先决条件
默认的 NVIDIA GPU 构建需要系统上安装 CUDA 运行时库
构建说明
-
使用以下命令检出此代码仓库
git clone https://github.com/microsoft/onnxruntime cd onnxruntime
- 设置环境变量:根据您的构建机器上的位置调整路径
export CUDA_HOME=<location for CUDA libs> # e.g. /usr/local/cuda export CUDNN_HOME=<location for cuDNN libs> # e.g. /usr/local/cuda export CUDACXX=<location for NVCC> #e.g. /usr/local/cuda/bin/nvcc
-
创建 ONNX Runtime Python wheel
./build.sh --config=RelWithDebInfo --enable_training --build_wheel --use_cuda --cuda_home {location of cuda libs eg. /usr/local/cuda/} --cudnn_home {location of cudnn libs eg./usr/local/cuda/} --cuda_version={version for eg. 11.8}
-
在
./build/Linux/RelWithDebInfo/dist
中安装用于 ONNX Runtime Training 的 .whl 文件。python -m pip install build/Linux/RelWithDebInfo/dist/*.whl
就是这样!构建完成后,您就可以在您的项目中使用 ONNX Runtime 库和可执行文件了。请注意,这些步骤是通用的,可能需要根据您的具体环境和要求进行调整。欲了解更多信息,您可以在 ONNX Runtime GitHub 社区寻求帮助。
GPU / ROCm
先决条件
默认的 AMD GPU 构建需要系统上安装 ROCm 软件工具包
- ROCm 6.0.0
构建说明
-
使用以下命令检出此代码仓库
git clone https://github.com/microsoft/onnxruntime cd onnxruntime
-
创建 ONNX Runtime Python wheel
./build.sh --config Release --enable_training --build_wheel --parallel --skip_tests --use_rocm --rocm_home /opt/rocm
-
在
./build/Linux/RelWithDebInfo/dist
中安装用于 ONNX Runtime Training 的 .whl 文件。python -m pip install build/Linux/RelWithDebInfo/dist/*.whl
DNNL 和 MKLML
构建说明
Linux
./build.sh --enable_training --use_dnnl
Windows
.\build.bat --enable_training --use_dnnl
添加 --build_wheel
以构建 ONNX Runtime wheel。
这将在 build/Linux/RelWithDebInfo/dist
中生成一个用于 ONNX Runtime Training 的 .whl 文件。