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

1. 详细步骤

1.1 安装
复制代码
# 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 直接启动
简洁命令
复制代码
xinference-local --host 0.0.0.0 --port 9997
多参数命令

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

复制代码
# 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
复制代码
# 格式
xinference-supervisor -H 当前服务器IP(主服务器IP) --port 9997

# 示例
xinference-supervisor -H 192.168.31.100 --port 9997
1.2.2.2 其他服务器启动 Worker
复制代码
# 格式
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

相关推荐
ZHOU_WUYI4 小时前
一个简单的分布式追踪系统
分布式
码不停蹄的玄黓8 小时前
MySQL分布式ID冲突详解:场景、原因与解决方案
数据库·分布式·mysql·id冲突
王小王-1238 小时前
基于Hadoop的公共自行车数据分布式存储和计算平台的设计与实现
大数据·hive·hadoop·分布式·hadoop公共自行车·共享单车大数据分析·hadoop共享单车
要开心吖ZSH10 小时前
《Spring 中上下文传递的那些事儿》Part 4:分布式链路追踪 —— Sleuth + Zipkin 实践
java·分布式·spring
幼稚园的山代王11 小时前
RabbitMQ 4.1.1初体验
分布式·rabbitmq·ruby
百锦再11 小时前
RabbitMQ用法的6种核心模式全面解析
分布式·rabbitmq·路由·消息·通道·交换机·代理
一路向北North11 小时前
RabbitMQ简单消息监听和确认
分布式·rabbitmq·ruby
一路向北North18 小时前
使用reactor-rabbitmq库监听Rabbitmq
分布式·rabbitmq·ruby
Amy187021118231 天前
赋能低压分布式光伏“四可”建设,筑牢电网安全新防线
分布式
June bug1 天前
【软考中级·软件评测师】下午题·面向对象测试之架构考点全析:分层、分布式、微内核与事件驱动
经验分享·分布式·职场和发展·架构·学习方法·测试·软考