解決 ONNX Runtime generate() API 的問題

安裝問題

Windows Conda 匯入錯誤

ImportError: DLL load failed while importing onnxruntime_genai: A dynamic link library (DLL) initialization routine failed.

如果您在 Windows 上的 Conda 環境中遇到此問題,則需要升級 Visual Studio 的 C++ 執行時。在 Conda 環境中,執行以下命令

conda install conda-forge::vs2015_runtime

執行此額外步驟後,onnxruntime-genai Python 包應能無錯誤執行。

Windows CUDA 匯入錯誤

DLL load failed while importing onnxruntime_genai

在 Windows 上完成 CUDA 工具包安裝後,請確保已將 CUDA_PATH 系統環境變數設定為工具包的安裝路徑。在 Windows 上匯入 onnxruntime_genai Python 模組時將使用此變數。未設定或設定不正確的 CUDA_PATH 變數可能導致匯入 onnxruntime_genaiDLL 載入失敗

Transformers / Tokenizers 與 ONNX Runtime generate() 的不相容性

RuntimeError: [json.exception.type_error.302] type must be string, but is array

僅在使用模型構建器生成模型時發生,不適用於下載的模型。

HuggingFace transformers 版本 4.45.0 中有一個更改,導致與 onnxruntime-genai 0.4.0 及更早版本不相容,此問題已在 0.5.0 版本中解決。您可以採用兩種替代方法來解決此問題

  • 選項 1:將 transformers 版本降級到低於 v4.45.0(即引入上述更改的版本)
  • 選項 2:從原始碼構建 onnxruntime-genai,使用這些說明:從原始碼構建