Windows 上的 TorchServe¶
本文內容¶
先決條件¶
目前,它僅在 Windows Server 2019 上獲得認證,但應該可以在 Windows 10 上正常運作。
請確認您是管理員使用者或擁有管理員權限
這裡給出的指示將使用 Anaconda Powershell 終端機來安裝 torchserve
依照這裡的指示安裝 Anaconda
依照這裡的指示安裝 Git
安裝 openjdk17
下載 openjdk17
解壓縮並編輯/新增環境變數,例如 PATH 和 JAVA_HOME,例如
使用命令列
unzip jdk-17.0.3_windows-x64_bin.zip
或使用 GUI 介面編輯系統或使用者設定檔環境變數
PATH
值,並將路徑<your-openjdk17-path>\bin
附加到其中
安裝 nodejs
下載 nodejs
安裝後,請確認 nodejs 和 npm node 模組二進位檔存在於 PATH 環境變數中。
如果您的 'Anaconda Powershell Prompt' (APP) 無法偵測到 npm 或 nodejs 命令,您可能需要重新啟動 Windows
從二進位檔安裝¶
注意:目前,Windows 的 wheel 檔案在 PyPi 上不可用。但是,如果您有預先建立的適用於 Windows 的 torchserve wheel 檔案,也可以使用以下步驟。
以管理員使用者身分啟動 'Anaconda Powershell Prompt' (APP),也就是透過右鍵點擊 APP 並執行以下命令
git clone https://github.com/pytorch/serve.git
cd serve
python .\ts_scripts\install_dependencies.py
對於本機 wheel 檔案
pip install <your-torchserve-wheel-file-name>.whl
對於 PyPi 套件 (目前不適用)
pip install torchserve torch-model-archiver
啟動 torchserve
torchserve.exe --start --model-store <path-to-model-store>
後續步驟請參考部署模型。
從原始碼安裝¶
請確認系統或使用者設定檔環境變數名稱
JAVA_HOME
的值為<your-openjdk17-path>
路徑。安裝 Microsoft Visual C++ Redistributable for Visual Studio 2015, 2017 and 2019
注意:請務必在安裝上述 Visual C++ 元件後重新啟動系統
請確認
nvidia-smi.exe
在Path
環境變數中可用。通常,它應該在<your_install_drive>\Program Files\NVIDIA Corporation\NVSMI
之下,例如 C:\Program Files\NVIDIA Corporation\NVSMI,將這個路徑加到Path
環境變數中。以管理員使用者身分啟動 'Anaconda Powershell Prompt' (APP),也就是透過右鍵點擊 APP 並執行以下命令
git clone https://github.com/pytorch/serve.git
pip install click
cd serve
若用於生產環境,請使用以下指令:¶
python .\ts_scripts\install_dependencies.py --environment=prod
python .\ts_scripts\install_from_src.py
若用於開發目的,請使用以下指令:¶
如果您打算使用 TorchServe 進行開發並修改一些原始碼,以下指令將會有所幫助。install_dependencies 腳本會安裝一些開發和測試所需的額外相依性。
python .\ts_scripts\install_dependencies.py --environment=dev
python .\ts_scripts\install_from_src.py
問題排除¶
如果您是從原始碼建置,則可能需要更改 inference、management 和 metrics apis 的 port 號,如
frontend/server/src/test/resources/config.properties
、frontend/server/src/test/resources/snapshot/*
和frontend/server/src/main/java/org/pytorch/serve/util/ConfigManager.java
中所指定。如果
curl
指令執行失敗,請在 APP (anaconda powershell prompt) 上執行以下指令Remove-item alias:curl
詳細資訊請參考這個 SO answer。