AMD 支援¶
TorchServe 可以在 ROCm 支援的任何作業系統和裝置組合上執行。
支援的 ROCm 版本¶
將支援 ROCm 的目前穩定 major.patch
版本和先前的 patch 版本。例如版本 N.2
和 N.1
,其中 N
是目前的 major 版本。
安裝¶
請確保您的系統已安裝 python >= 3.8。
複製儲存庫
git clone git@github.com:pytorch/serve.git
cd 進入複製的資料夾
cd serve
為 python 建立虛擬環境
python -m venv venv
啟用虛擬環境。如果您使用另一個 shell (fish、csh、powershell),請使用
/venv/bin/
中的相關選項source venv/bin/activate
安裝 ROCm 支援所需的依賴項。
python ./ts_scripts/install_dependencies.py --rocm=rocm61 python ./ts_scripts/install_from_src.py
在 python 虛擬環境中啟用 amd-smi
sudo chown -R $USER:$USER /opt/rocm/share/amd_smi/ pip install -e /opt/rocm/share/amd_smi/
使用 HIP_VISIBLE_DEVICES
選擇加速器¶
如果您在執行 TorchServe 的系統上有多個加速器,您可以透過將環境變數 HIP_VISIBLE_DEVICES
設定為以 0 為索引、逗號分隔的整數字串,來選擇哪些加速器對 TorchServe 可見,這些整數代表加速器的 ID。
如果您有 8 個加速器,但只想讓 TorchServe 看到最後四個,請執行 export HIP_VISIBLE_DEVICES=4,5,6,7
。
ℹ️ 不設定
HIP_VISIBLE_DEVICES
將導致 TorchServe 使用其執行系統上的所有可用加速器。
⚠️ 如果您將
HIP_VISIBLE_DEVICES
設定為空字串,可能會遇到問題。例如:export HIP_VISIBLE_DEVICES=
或export HIP_VISIBLE_DEVICES=""
。如果您想要移除其影響,請使用unset HIP_VISIBLE_DEVICES
。
⚠️ 同時設定
CUDA_VISIBLE_DEVICES
和HIP_VISIBLE_DEVICES
可能會導致非預期的行為,應避免這樣做。未來這樣做可能會導致例外情況。
Docker¶
開發中
Dockerfile.rocm
為 TorchServe 提供初步的 ROCm 支援。
建置和執行 dev-image
docker build --file docker/Dockerfile.rocm --target dev-image -t torch-serve-dev-image-rocm --build-arg USE_ROCM_VERSION=rocm62 --build-arg BUILD_FROM_SRC=true .
docker run -it --rm --device=/dev/kfd --device=/dev/dri torch-serve-dev-image-rocm bash
使用範例¶
使用 ROCm 的必要相依性安裝 TorchServe 後,您應該就可以開始提供您的模型了。
對於一個簡單的範例,請參考 serve/examples/image_classifier/mnist/
。