核心步骤:
docker --version # 需 ≥24.0.5(2025年兼容性要求)
nvidia-smi | grep"Driver Version"# 输出示例:Driver Version: 571.96.03
sudo apt install -y nvidia-driver-570-server # 企业级稳定版驱动
关键操作:
# 重建 CUDA 仓库(针对 Ubuntu 24.04)
sudo tee /etc/apt/sources.list.d/cuda.list <<EOF
deb https://developer.download.nvidia.cn/compute/cuda/repos/ubuntu2404/x86_64/ /
EOF
# 迁移密钥至新规范路径(适配 APT 密钥管理策略)
sudo mkdir -p /etc/apt/keyrings && sudo cp /etc/apt/trusted.gpg /etc/apt/keyrings/nvidia-cuda.gpg
sudo apt update
GPU 加速模式:
docker run -d --name xinference \
-e XINFERENCE_MODEL_SRC=modelscope \ # 指定模型来源
-p 9998:9997 \ # 端口映射(宿主机:容器)
--gpus all \ # 启用 GPU 穿透
-v /host/cuda/libs:/usr/lib/x86_64-linux-gnu:ro \ # 驱动文件挂载
xprobe/xinference:latest \
xinference-local -H 0.0.0.0 --log-level debug
验证 GPU 穿透:
dockerexecxinference nvidia-smi # 输出应与宿主机一致
问题根源:
0.0.0.0支持有限,需改用127.0.0.1# 容器启动命令调整(PowerShell)
docker run -d --name xinference `
-v C:\xinference:/xinference ` # Windows 路径挂载
-p 9997:9997 `
--gpus all `
xprobe/xinference:latest `
xinference-local -H 127.0.0.1 --log-level debug
防火墙配置:
netsh advfirewall firewall add rule name="Xinference" dir=in action=allow protocol=TCP localport=9997
步骤详解:
docker cp qwen2.5-instruct/ xinference:/xinference/models/ # 宿主机到容器
xinference launch -n qwen2.5-instruct -f pytorch -s 0_5 # 指定框架与版本
curl http://localhost:9997/v1/models # 检查状态是否为 "Running"
Python SDK 调用:
fromxinference.clientimportClient
client = Client("http://localhost:9998") # 注意宿主机映射端口
model_uid = client.launch_model(
"rerank-chinese",
framework="transformers",
max_memory=4096# 防 OOM 限制
)
response = client.rerank(
model_uid,
query="深度学习框架",
documents=["TensorFlow","
yTorch","Xinference"]
)
print(response.scores) # 输出相关性得分
docker run -d --restart unless-stopped \ # 自动重启
-v xinference_data:/root/.xinference \ # 数据持久化
xprobe/xinference:latest
sed -i's|developer.download.nvidia.com|mirrors.aliyun.com/nvidia|g'/etc/apt/sources.list.d/cuda.list # 国内加速
watch -n 1 nvidia-smi --query-gpu=utilization.gpu,memory.used --format=csv
xinference profile -m rerank-chinese -o profile.html # 定位推理瓶颈
| Ubuntu 24.04 | -v /usr/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu:ro | ls /usr/lib/x86_64-linux-gnu/libcuda* |
| Windows 11 | -H 127.0.0.1,目录挂载:-v C:\xinference:/xinference | docker logs xinference --tail 100 |
| 欢迎光临 链载Ai (https://www.lianzai.com/) | Powered by Discuz! X3.5 |