AMD 支持¶
TorchServe 可以运行在任何操作系统和设备的组合上,只要该组合受 ROCm 支持。
ROCm 支持的版本¶
将支持当前稳定的 major.patch
ROCm 版本和之前的 path 版本。例如版本 N.2
和 N.1
,其中 N
是当前的 major 版本。
安装¶
请确保您的系统上已安装 python >= 3.8。
克隆仓库
git clone [email protected]:pytorch/serve.git
进入克隆的文件夹
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 索引整数字符串(表示加速器的 ID)来选择哪些加速器对 TorchServe 可见。
如果您有 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
示例用法¶
在安装了 TorchServe 以及 ROCm 所需的依赖项后,您应该可以开始服务您的模型了。
有关简单示例,请参考 serve/examples/image_classifier/mnist/
。