從原始碼構建 generate() API

先決條件

  • cmake
  • .NET6(如果構建 C#)

克隆 onnxruntime-genai 倉庫

git clone https://github.com/microsoft/onnxruntime-genai
cd onnxruntime-genai

構建 generate() API

此步驟假定您位於 onnxruntime-genai 倉庫的根目錄。

下面所有構建命令都有一個 --config 引數,該引數接受以下選項

  • Release 構建釋出二進位制檔案
  • Debug 構建帶除錯符號的二進位制檔案
  • RelWithDebInfo 構建帶除錯資訊的釋出二進位制檔案

構建 Python API

Windows CPU 構建

python build.py --config Release

Windows DirectML 構建

python build.py --use_dml --config Release

Linux 構建

python build.py --config Release

Linux CUDA 構建

python build.py --use_cuda --config Release

Mac 構建

python build.py --config Release

構建 Java API

python build.py --build_java --config Release

為 Android 構建

如果在 Windows 上構建,請安裝 ninja

pip install ninja

執行構建指令碼。

python build.py --build_java --android --android_home <path to your Android SDK> --android_ndk_path <path to your NDK installation> --android_abi  [armeabi-v7a|arm64-v8a|x86|x86_64] --config Release

將庫安裝到您的應用程式中

安裝 Python wheel

# Change dir to the folder containing the onnxruntime-genai wheel
# Example for Linux: cd build/Linux/Release/wheel/
pip install *.whl

安裝 NuGet

即將推出

安裝 JAR

build/Windows/Release/src/java/build/libs/*.jar 複製到您的應用程式中。

安裝 AAR

build/Android/Release/src/java/build/android/outputs/aar/onnxruntime-genai-release.aar 複製到您的應用程式中。

安裝 C/C++ 標頭檔案和庫

Windows

使用 src\ort_genai.h 中的標頭檔案和 build\Windows\Release 中的庫

Linux

使用 src/ort_genai.h 中的標頭檔案和 build/Linux/Release 中的庫