LLM | Xinference 安装使用(支持CPU、Metal、CUDA推理和分布式部署)

1. 详细步骤

1.1 安装

bash 复制代码
# CUDA/CPU
pip install "xinference[transformers]"
pip install "xinference[vllm]"
pip install "xinference[sglang]"

# Metal(MPS)
pip install "xinference[mlx]"
CMAKE_ARGS="-DLLAMA_METAL=on" pip install llama-cpp-python

注:可能是 nvcc 版本等个人环境配置原因,llama-cpp-python 在 CUDA 上无法使用(C/C++ 环境上是正常的),Metal 的 llama-cpp-python 正常。如需安装 flashinfer 等依赖见官方安装文档:https://inference.readthedocs.io/zh-cn/latest/getting_started/installation.html

1.2 启动

1.2.1 直接启动

简洁命令
bash 复制代码
xinference-local --host 0.0.0.0 --port 9997
多参数命令

设置模型缓存路径模型来源(Hugging Face/Modelscope)

bash 复制代码
# CUDA/CPU
XINFERENCE_HOME=/path/.xinference XINFERENCE_MODEL_SRC=modelscope xinference-local --host 0.0.0.0 --port 9997

# Metal(MPS)
XINFERENCE_HOME=/path/.xinference XINFERENCE_MODEL_SRC=modelscope PYTORCH_ENABLE_MPS_FALLBACK=1 xinference-local --host 0.0.0.0 --port 9997

1.2.2 集群部署

通过 ifconfig 查看当前服务器IP

1.2.2.1 主服务器启动 Supervisor
bash 复制代码
# 格式
xinference-supervisor -H 当前服务器IP(主服务器IP) --port 9997

# 示例
xinference-supervisor -H 192.168.31.100 --port 9997
1.2.2.2 其他服务器启动 Worker
bash 复制代码
# 格式
xinference-worker -e "http://${主服务器IP}:9997" -H 当前服务器IP(子服务器IP)

# 示例
xinference-worker -e "http://192.168.31.100:9997" -H 192.168.31.101

注:按需添加XINFERENCE_HOMEXINFERENCE_MODEL_SRCPYTORCH_ENABLE_MPS_FALLBACK等环境变量(启动时参数)

1.3 使用

访问 http://主服务器IP:9997/docs 查看接口文档,访问 http://主服务器IP:9997 正常使用

2. 参考资料

2.1 Xinference

2.1.1 部署文档
本地运行 Xinference

https://inference.readthedocs.io/zh-cn/latest/getting_started/using_xinference.html#run-xinference-locally

集群中部署 Xinference

https://inference.readthedocs.io/zh-cn/latest/getting_started/using_xinference.html#deploy-xinference-in-a-cluster

2.1.2 安装文档
官方页面

https://inference.readthedocs.io/zh-cn/latest/getting_started/installation.html

Transformers 引擎

https://inference.readthedocs.io/zh-cn/latest/getting_started/installation.html#transformers-backend

vLLM 引擎

https://inference.readthedocs.io/zh-cn/latest/getting_started/installation.html#vllm-backend

Llama.cpp 引擎

https://inference.readthedocs.io/zh-cn/latest/getting_started/installation.html#llama-cpp-backend

MLX 引擎

https://inference.readthedocs.io/zh-cn/latest/getting_started/installation.html#mlx-backend

3. 资源

3.1 Xinference

3.1.1 GitHub
官方页面

https://github.com/xorbitsai/inference

https://github.com/xorbitsai/inference/blob/main/README_zh_CN.md

3.1.2 安装文档
SGLang 引擎

https://inference.readthedocs.io/zh-cn/latest/getting_started/installation.html#sglang-backend

其他平台(在昇腾 NPU 上安装)

https://inference.readthedocs.io/zh-cn/latest/getting_started/installation.html#other-platforms

https://inference.readthedocs.io/zh-cn/latest/getting_started/installation_npu.html#installation-npu

相关推荐
洛阳泰山7 小时前
MaxKB4j Docker Compose 部署指南
java·docker·llm·springboot·rag·maxkb4j
cuguanren10 小时前
MuleRun vs OpenClaw vs 网页服务:云端安全与本地自由的取舍之道
安全·大模型·llm·agent·智能体·openclaw·mulerun
大数据AI人工智能培训专家培训讲师叶梓10 小时前
FaithLens:8B 参数大模型幻觉检测器,性能超 GPT-4.1 且低成本可解释
大模型·llm·大模型幻觉·人工智能讲师·大模型讲师·大模型培训·llm幻觉
星始流年11 小时前
AI Agent 开发系列 之 01 🔎重新认识 LLM
人工智能·llm·agent
_张一凡11 小时前
【大语言模型学习】一文详解阿里Qwen3大模型以及全参量微调入门实战教程(代码完整)
llm·aigc·大语言模型·多模态·qwen3·大语言模型微调·全参量微调
supersolon17 小时前
OpenClaw接入飞书(channel)
ai·llm·飞书·openclaw·龙虾
每天都要写算法(努力版)17 小时前
【大模型的原理架构对比解析】Encoder-Decoder 架构与 Decoder-Only 架构的输入输出详解
llm·encoder-decoder·decoder-only
8Qi817 小时前
Hello-Agents学习笔记--旅行助手智能体案例
人工智能·llm·agent·智能体·tavily
chaors1 天前
从零学RAG0x0d:AdvancedRAG检索后优化
langchain·llm·ai编程
CoderJia程序员甲1 天前
GitHub 热榜项目 - 日榜(2026-03-18)
ai·大模型·llm·github·ai教程