text-embeddings-inference documentation
在 AMD Instinct GPU(ROCm)上使用 TEI
在 AMD Instinct GPU(ROCm)上使用 TEI
Text Embeddings Inference 支持使用 ROCm 的 AMD Instinct GPU(MI200、MI300 系列)。
先决条件
- 主机上配备 ROCm 驱动的 AMD Instinct GPU(MI200、MI300 系列)
选项 A:Docker(推荐)
在 AMD GPU 上运行 TEI 最简单的方法是使用预构建的 Docker 镜像:
model=BAAI/bge-base-en-v1.5 volume=$PWD/data # share a volume to avoid re-downloading weights docker run \ --device /dev/kfd --device /dev/dri/renderD128 \ --group-add video \ --ipc=host \ -p 8080:80 \ -v $volume:/data \ --pull always \ ghcr.io/huggingface/text-embeddings-inference:rocm-latest \ --model-id $model --dtype bfloat16
然后测试它:
curl http://localhost:8080/v1/embeddings \
-H 'Content-Type: application/json' \
-d '{
"input": "What is Deep Learning?",
"model": "text-embeddings-inference",
"encoding_format": "float"
}'选项 B:在 TEI ROCm 镜像内从源代码构建
如果您希望修改 TEI 并重新构建,请使用官方的 TEI ROCm 镜像(即下方固定的镜像)作为基础环境,而不是 AMD 的 rocm/pytorch 镜像。该镜像已内置 TEI 所需的精确 ROCm 版本 PyTorch、flash-attn、计算内核以及已安装的 Python 后端,因此您可以完全跳过 PyTorch/依赖项的配置,并避免版本不匹配的问题——您只需重新构建所修改的部分即可。
步骤 1:启动容器
从您检出的仓库根目录挂载该目录,并覆盖入口点以获取 shell。
镜像摘要固定了此处使用的 rocm-latest 构建版本;在使用不同的 TEI 版本时,请选择匹配的镜像:
docker run -it --device=/dev/kfd --device=/dev/dri/renderD128 \ --group-add video --ipc=host --shm-size 8g \ -v "$PWD:/workspace" -w /workspace \ --entrypoint bash \ ghcr.io/huggingface/text-embeddings-inference@sha256:9b3f24f8740d4c3fa656666e07a383a50a9e4f3273d3856980841cd8d45e727f
PyTorch (ROCm)、flash-attn、计算内核以及 text-embeddings-server Python 后端已预装在此镜像中,并且预编译的 text-embeddings-router 已位于 PATH 中。以下步骤仅涵盖在编辑源代码后重新构建的操作。
步骤 2:安装 Rust(仅在需要重新构建路由器时才需要)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
source "$HOME/.cargo/env"
# Required by the router's protobuf build step.
apt-get update && apt-get install -y protobuf-compiler pkg-config libssl-dev步骤 3:从您的源代码重新构建 Rust 路由器
cargo build --release \
--no-default-features \
--features python,http \
--bin text-embeddings-router如果您同时更改了 Python 后端,请在以可编辑模式重新安装之前,先在已挂载的检出目录中生成 protobuf 存根。镜像中已安装的包不会填充新检出目录中被忽略的 text_embeddings_server/pb 目录。子 shell 会在仓库根目录保留其余命令。
( cd backends/python/server make gen-server pip install --no-deps -e . )
步骤 4:启动您的构建
model=BAAI/bge-base-en-v1.5 ./target/release/text-embeddings-router --model-id $model --dtype bfloat16 --port 8080
服务器就绪后,您可以通过一个简单的嵌入请求来测试它:
curl http://localhost:8080/v1/embeddings \
-H 'Content-Type: application/json' \
-d '{
"input": "What is Deep Learning?",
"model": "text-embeddings-inference",
"encoding_format": "float"
}'验证 GPU 检测
启动后,您应该能看到一行日志,确认已检测到 ROCm:
INFO text_embeddings_server::utils::device: ROCm / HIP version: X.Y.Z您也可以通过 Python 进行验证:
import torch
print(torch.cuda.is_available()) # True
print(torch.version.hip) # e.g. 6.2.12345-...备注
这是一项正在进行中的工作——针对 AMD GPU 的更多模型支持和优化操作即将推出。
Update on GitHub