在 Windows 上構建 Torch-TensorRT¶
Torch-TensorRT 使用 CMake 在 Windows 平台上獲得社群支援
先決條件
Microsoft VS 2022 工具
Bazelisk
CUDA
構建步驟¶
開啟應用程式「適用於 VS 2022 的 x64 原生工具命令提示字元」- 請注意,可能需要管理員權限
確保 Bazelisk(Bazel 啟動器)已安裝在您的機器上,並且可以從命令列使用。可以使用 Chocolatey 等套件安裝程式來安裝 Bazelisk
安裝最新版本的 Torch(例如,使用 pip install –pre torch –index-url https://download.pytorch.org/whl/nightly/cu124)
複製 Torch-TensorRT 儲存庫並導航到其根目錄
執行 pip install ninja wheel setuptools
執行 pip install –pre -r py/requirements.txt
執行 set DISTUTILS_USE_SDK=1
執行 python setup.py bdist_wheel
執行 pip install dist/*.whl
進階設定和疑難排解¶
在 WORKSPACE 檔案中,cuda_win、libtorch_win 和 tensorrt_win 是 Windows 特定的模組,可以自訂。例如,如果您想使用不同版本的 CUDA 構建,或者您的 CUDA 安裝在非標準位置,請更新 cuda_win 模組中的 path。
同樣地,如果您想使用不同版本的 pytorch 或 tensorrt,請分別自訂 libtorch_win 和 tensorrt_win 模組中的 urls。
這些套件的本地版本也可以在 Windows 上使用。請參閱 toolchainsci_workspacesWORKSPACE.win.release.tmpl,以瞭解在 Windows 上使用本地版本的 TensorRT 的範例。