微信扫码
添加专属顾问
我要投稿
掌握Xinference本地部署,解决部署难题。 核心内容: 1. 基础环境配置:Docker与NVIDIA驱动验证,CUDA工具链配置 2. Docker容器化部署:镜像拉取、容器启动、GPU加速模式 3. Windows系统特殊配置:网络栈支持问题及修复方案
核心步骤:
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 穿透:
docker exec xinference 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 调用:
from xinference.client import Client
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", "PyTorch", "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 |
53AI,企业落地大模型首选服务商
产品:场景落地咨询+大模型应用平台+行业解决方案
承诺:免费场景POC验证,效果验证后签署服务协议。零风险落地应用大模型,已交付160+中大型企业
2025-02-04
2025-02-04
2024-09-18
2024-07-11
2024-07-09
2024-07-11
2024-07-26
2025-02-05
2025-01-27
2025-02-01
2025-04-27
2025-04-27
2025-04-23
2025-04-20
2025-04-01
2025-03-31
2025-03-20
2025-03-16