AMD支持¶
TorchServe 可以在任何由 ROCm 支持的操作系统和设备组合上运行。 支持的 ROCm
支持的ROCm版本¶
当前稳定的major.patch版本的ROCm以及之前的路径版本将被支持。例如,版本N.2和N.1中N是当前的主要版本。
安装¶
确保您的系统上已安装 Python >= 3.8。
克隆这个仓库
git clone git@github.com: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索引整数字符串来选择哪些加速器应被TorchServe可见。
如果您有8个加速器,但只想让TorchServe看到最后四个,请执行export HIP_VISIBLE_DEVICES=4,5,6,7。
ℹ️ Not setting
HIP_VISIBLE_DEVICESwill cause TorchServe to use all available accelerators on the system it is running on.
⚠️ You can run into trouble if you set
HIP_VISIBLE_DEVICESto an empty string. eg.export HIP_VISIBLE_DEVICES=orexport HIP_VISIBLE_DEVICES=""useunset HIP_VISIBLE_DEVICESif you want to remove its effect.
⚠️ Setting both
CUDA_VISIBLE_DEVICESandHIP_VISIBLE_DEVICESmay cause unintended behaviour and should be avoided. Doing so may cause an exception in the future.
Docker¶
在开发中
Dockerfile.rocm 提供初步的ROCm支持用于TorchServe。
构建和运行 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/。