Xinference (Xorbits Inference): sirve LLMs, modelos de voz y multimodales con un solo comando
2026/9/15 16:18:46 网站建设 项目流程

Xinference (Xorbits Inference): sirve LLMs, modelos de voz y multimodales con un solo comando

【免费下载链接】inferenceSwap GPT for any LLM by changing a single line of code. Xinference lets you run open-source, speech, and multimodal models on cloud, on-prem, or your laptop — all through one unified, production-ready inference API.项目地址: https://gitcode.com/GitHub_Trending/in/inference

Xorbits Inference(简称 Xinference)是一个开源的分布式推理框架,专为"让模型服务变得简单"而设计:无论是大语言模型(LLM)、语音识别与语音合成、OCR、图像生成、向量嵌入还是多模态与世界模型,都可以通过一条命令完成部署,并以统一的、兼容 OpenAI 的生产级推理 API 对外提供服务。读完本文,你将掌握 Xinference 的核心能力模型、四种使用方式(Web UI / cURL / CLI / Python 客户端)、Docker 与 Kubernetes 部署方案、模型生命周期管理,以及本地与多节点集群两种运行模式。

¿Qué es Xinference?

Xinference 是 Xorbits Inference 的开源实现,定位为"性能强大且功能全面的分布式推理框架"。它把大语言模型、语音识别模型、多模态模型等的部署流程大幅简化:一个命令即可完成模型的部署工作,研究者、开发者与数据科学家都可以借助它与前沿开源模型对接,而无需关心底层引擎的差异。

从仓库结构可以直接看到框架对模型类型的覆盖范围(xinference/model):

模型类型仓库目录典型能力
大语言模型(LLM)xinference/model/llmchat / generate / 函数调用
语音(ASR / TTS / 音乐)xinference/model/audio语音识别、语音合成、音乐生成
嵌入(Embedding)xinference/model/embedding文本向量化
重排(Rerank)xinference/model/rerank检索结果重排序
图像(文生图 / 图像编辑 / OCR)xinference/model/image文生图、图像编辑、OCR
视频xinference/model/video视频生成
世界模型xinference/model/world交互式世界模拟

Funcionalidades principales

  • Servir modelos con facilidad:简化 LLM、语音识别与多模态模型的部署,测试与生产环境的模型都可以用一条命令配置并启动。
  • Modelos de vanguardia accesibles:内置大量前沿开源模型,一条命令即可体验,内置模型列表持续更新。
  • Aprovechamiento de hardware heterogéneo:通过 ggml 等方案同时利用 GPU 与 CPU 进行推理,降低延迟、提高吞吐。
  • APIs y interfaces flexibles:提供 OpenAI 兼容的 RESTful API(含 Function Calling)、RPC、命令行(CLI)、Web UI 等多种使用接口。
  • Despliegue distribuido:支持跨设备、跨机器的分布式推理,内置资源调度器可将不同规模的模型按需调度到不同机器,充分利用集群资源。
  • Integraciones de terceros:与 LangChain、LlamaIndex、Dify、Chatbox、RAGFlow、MaxKB 等流行生态无缝对接。

¿Por qué elegir Xinference?

项目官方文档给出了如下与同类方案(FastChat、OpenLLM、RayLLM)的能力对比表,便于快速定位 Xinference 的差异化能力:

FunciónXinferenceFastChatOpenLLMRayLLM
API RESTful compatible con OpenAI
Integración vLLM
Diversos motores de inferencia (GGML, TensorRT)
Diversas plataformas (CPU, Metal)
Despliegue en clúster multi-nodo
Modelos de imagen (Texto→Imagen)
Modelos de embedding de texto
Modelos multimodales
Modelos de voz
Funcionalidad OpenAI (Function Calling)

从源码结构看,上述能力都有对应的实现支撑:OpenAI 兼容的 API 路由集中在 xinference/api/routers(llm、embeddings、rerank、images、audio、videos、worlds 等);vLLM 引擎适配位于 xinference/model/llm/vllm 与 xinference/model/image/vllm;GGML/llama.cpp 引擎适配位于 xinference/model/llm/llama_cpp。

Novedades destacadas del framework

Mejoras del framework

  • Xinference 3.0.0:已发布,包含迁移说明与不兼容变更(破坏性变更)说明。
  • Agente nativo(Xagent):与 Xagent 深度集成,支持动态规划、工具调用与多步自主推理,突破传统静态流程的限制。
  • Batching automático:多个并发请求会被自动合批处理,大幅提升吞吐量。相关参数(XINFERENCE_BATCH_SIZEXINFERENCE_BATCH_INTERVAL)与合批调度实现可分别在 xinference/constants.py 与 xinference/model/scheduler/batch.py 中找到。
  • Xllamacpp:由 Xinference 团队维护的 llama.cpp Python binding,支持持续并行(continuous batching),更面向生产环境。
  • Inferencia distribuida:支持在多个 worker 上运行大尺寸模型。
  • Mejoras en vLLM:支持跨副本共享 KV-Cache。

Nuevos modelos integrados

按类型归纳(模型名称以项目文档为准):

  • LLM:MiniCPM5-2B、Kimi-K3、GLM-5.2、Ornith 1.5(35B-A3B / 397B)、Qwen3.8(27B / 2.4T-A95B)、DeepSeek-V4-Flash-0731、SenseNova-U1.5-8B-MoT、jina-reranker-m0(重排)。
  • 语音 / 音乐:Fish Audio 系列(S1-mini、S2-Pro)、Breeze-TTS-2、FireRedTTS3、MiniMax-Music3、MiniMax-H3 Lightning LoRA。
  • OCR:MonkeyOCR、dots.ocr、NaviDC-OCR。
  • 图像:JoyAI 图像编辑系列(Edit、Edit Plus)、GLM-Image、HiDream-O1 系列(Image、Image-Dev、Image-Dev-2604)、Ideogram4、Krea 2 系列(Raw、Turbo)、ACE-Step 1.5。
  • 嵌入(Embedding):WeMM-Embedding 系列(2B、4B、9B)。
  • 世界模型:Matrix-Game-3.0-5B、HY-WorldPlay-5B、Astra。

以上能力在仓库中均有对应实现文件可查证,例如 xinference/model/audio/fish_speech.py(Fish Audio)、xinference/model/image/hidream_o1.py(HiDream-O1)、xinference/model/world/hy_worldplay_runner.py(世界模型),内置模型清单可查看 xinference/model/llm/llm_family.json。

Integraciones con ecosistemas

  • Xagent:企业级 Agent 平台,提供规划、记忆与工具调用能力。
  • Dify:LLMOps 平台,用于快速构建带可视化控制的应用。
  • FastGPT:基于 LLM 的知识库平台,支持数据处理与模型调用。
  • RAGFlow:基于深度文档理解的开源 RAG 引擎。
  • MaxKB:基于大语言模型与 RAG 的开源知识库问答系统。

Instalación y arranque local (Quickstart)

安装 Xinference 最简单的方式是使用 pip:

pip install "xinference[all]"

[all]会安装支持全部模型类型所需的依赖。若只想安装部分后端,官方安装文档(doc/source/getting_started/installation.rst)给出了更细的拆分:

# 仅 transformers 后端(PyTorch,支持 pytorch/gptq/awq/bnb/fp4 格式) pip install "xinference[transformers]" # AWQ/GPTQ 量化格式需要特殊依赖 pip install "xinference[transformers_quantization]" --no-build-isolation # 单独使用 sglang 引擎 pip install 'xinference[sglang]'

启动一个本地实例只需一条命令:

$ xinference-local

该命令在 xinference/deploy/cmdline.py 中定义。常用启动参数如下:

参数简写默认值说明
--host-H127.0.0.1服务监听地址(本地模式默认仅本机可访问)
--port-p9997服务端口(Web UI / API 共用)
--log-levelINFO日志级别:DEBUG > INFO > WARNING > ERROR > CRITICAL
--metrics-exporter-host/-MH--host指标导出服务监听地址
--metrics-exporter-port/-mp指标导出服务端口

默认监听地址与端口在 xinference/constants.py 中定义为XINFERENCE_DEFAULT_LOCAL_HOST = "127.0.0.1"XINFERENCE_DEFAULT_ENDPOINT_PORT = 9997。框架的默认数据目录为~/.xinference(可通过环境变量XINFERENCE_HOME覆盖),模型、缓存、日志、虚拟环境等数据都会集中存放于此(见 xinference/constants.py)。

服务启动后,可以通过 Web UI、cURL、CLI 或 Python 客户端四种方式使用:

Despliegue con Docker

NVIDIA GPU 用户可以直接使用官方 Docker 镜像(确保已安装 Docker 与 CUDA):

docker run --name xinference -d -p 9997:9997 -e XINFERENCE_HOME=/data -v </on/your/host>:/data --gpus all xprobe/xinference:latest xinference-local -H 0.0.0.0

仓库中的 xinference/deploy/docker/docker-compose.yml 提供了更完整的编排示例,值得关注的配置项包括:

  • --gpus all/ GPU 保留deploy.resources.reservations.devices声明capabilities: [gpu]driver: nvidiacount: all,以启用全部 GPU。
  • 共享内存shm_size:默认8gb,多 GPU 推理需要更大的共享内存段。
  • 端口映射:默认9997:9997,可用环境变量XINFERENCE_PORT覆盖。
  • 数据持久化XINFERENCE_HOME_DIR(默认卷xinference_home,映射到容器内/root/.xinference)、XINFERENCE_HF_CACHE_DIR(Hugging Face 缓存)、XINFERENCE_MODELSCOPE_CACHE_DIR(ModelScope 缓存)。
  • 模型下载源XINFERENCE_MODEL_SRC:默认auto(自动探测 Hugging Face 可达性并回退到 ModelScope),也可显式设为huggingfacemodelscope
  • 健康检查:通过python3 -c "...urllib.request.urlopen('http://localhost:9997/status')"每 30 秒探测一次。
  • 离线部署docker compose --profile offline up -d会额外启动内置私有 PyPI 服务(xinference-pypiserver),配合offline.env实现无外网安装。
# CPU-only 主机 docker compose -f docker-compose.yml -f docker-compose.cpu.yml up -d # 在线默认启动 docker compose up -d

Despliegue en Kubernetes con Helm

在 Kubernetes 集群启用 GPU 支持后,可通过 Helm 安装:

# 新增 xinference 仓库 helm repo add xinference https://xorbitsai.github.io/xinference-helm-charts # 更新仓库,查询可安装的版本 helm repo update xinference helm search repo xinference/xinference --devel --versions # 在 K8s 中安装 xinference helm install xinference xinference/xinference -n xinference --version 0.0.1-v<xinference_release_version>

更多定制化安装方式可参考文档 doc/source/getting_started/using_kubernetes.rst。

Lanzamiento de modelos

Desde la línea de comandos

以内置模型qwen2.5-instruct为例,通过 CLI 启动(示例来自 doc/source/getting_started/using_xinference.rst):

xinference launch --model-engine <inference_engine> -n qwen2.5-instruct -s 0_5 -f pytorch

launch命令的完整参数定义位于 xinference/deploy/cmdline.py,常用参数包括:

参数简写默认值说明
--model-name-n必填模型名称
--model-type-tLLM模型类型(LLM / embedding / rerank / image / audio / video / world / flexible)
--model-engine-en推理引擎(transformers / vllm / llama.cpp / sglang 等),LLM 必填
--model-uid-u模型名模型唯一标识,缺省时与模型名一致
--size-in-billions-s模型参数量(如0_57
--model-format-f模型格式(pytorch / ggufv2 / gptq / awq 等)
--quantization-q量化配置
--replica-r1模型副本数
--n-worker1使用的 worker 数量
--n-gpuautoGPU 数量;n-worker>1时表示每个 worker 的 GPU 数
--worker-ip-w分布式环境下指定模型运行的 worker IP
--gpu-idx指定 worker 上可用的 GPU 编号(逗号分隔)
--endpoint-ehttp://127.0.0.1:9997服务端点(可用环境变量XINFERENCE_ENDPOINT覆盖)

部分引擎需要额外参数,可以直接在命令行追加并透传给引擎,例如 vLLM 的显存利用率:

xinference launch --model-engine vllm -n qwen2.5-instruct -s 0_5 -f pytorch --gpu_memory_utilization 0.9

也可以按需下载模型源(如 ModelScope):

XINFERENCE_MODEL_SRC=modelscope xinference-local --host 0.0.0.0 --port 9997

Desde cURL y el cliente Python

用 cURL 启动同一模型:

curl -X 'POST' \ 'http://127.0.0.1:9997/v1/models' \ -H 'accept: application/json' \ -H 'Content-Type: application/json' \ -d '{ "model_engine": "<inference_engine>", "model_name": "qwen2.5-instruct", "model_format": "pytorch", "size_in_billions": "0_5" }'

用 Python 客户端:

from xinference.client import RESTfulClient client = RESTfulClient("http://127.0.0.1:9997") model_uid = client.launch_model( model_engine="<inference_engine>", model_name="qwen2.5-instruct", model_format="pytorch", size_in_billions="0_5", ) print('Model uid: ' + model_uid)

API compatible con OpenAI y Anthropic

模型运行后即可通过 OpenAI 兼容接口调用(Xinference 可作为 OpenAI API 的本地替代品,仅需修改base_url):

from openai import OpenAI client = OpenAI(base_url="http://127.0.0.1:9997/v1", api_key="not used actually") response = client.chat.completions.create( model="qwen2.5-instruct", messages=[ {"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "What is the largest animal?"} ] ) print(response)

支持以下 OpenAI API 子集:Chat CompletionsCompletionsEmbeddings。此外还支持 Anthropic 协议(base URL 为http://127.0.0.1:9997/anthropic),因此可以直接接入 Claude Code 等工具。

通过 cURL 调用对话接口:

curl -X 'POST' \ 'http://127.0.0.1:9997/v1/chat/completions' \ -H 'accept: application/json' \ -H 'Content-Type: application/json' \ -d '{ "model": "qwen2.5-instruct", "messages": [ {"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "What is the largest animal?"} ] }'

Gestión del ciclo de vida de los modelos

Xinference 提供 CLI / cURL / Python 三种方式管理模型的完整生命周期:

列出可启动的某类型模型注册表:

xinference registrations -t LLM curl http://127.0.0.1:9997/v1/model_registrations/LLM
client.list_model_registrations(model_type='LLM')

查看当前运行中的模型:

xinference list curl http://127.0.0.1:9997/v1/models
client.list_models()

终止不再需要的模型以释放资源:

xinference terminate --model-uid "qwen2.5-instruct" curl -X DELETE http://127.0.0.1:9997/v1/models/qwen2.5-instruct
client.terminate_model(model_uid="qwen2.5-instruct")

此外,CLI 还提供register/unregister/cached/remove-cache等命令(见 xinference/deploy/cmdline.py),用于注册自定义模型、注销模型以及管理模型缓存文件。

Despliegue distribuido en clúster

要将 Xinference 部署到集群,需要在服务器上启动一个 supervisor,在其他服务器上启动 worker(命令定义见 xinference/deploy/cmdline.py 与 xinference/deploy/cmdline.py):

启动 Supervisor:

xinference-supervisor -H "${supervisor_host}"

Supervisor 的 Web UI 地址为http://${supervisor_host}:9997/ui,OpenAPI 文档地址为http://${supervisor_host}:9997/docs。分布式模式下默认监听地址为0.0.0.0(见 xinference/constants.py 中的XINFERENCE_DEFAULT_DISTRIBUTED_HOST)。

启动 Worker(每台 worker 服务器执行):

xinference-worker -e "http://${supervisor_host}:9997" -H "${worker_host}"
# 集群模式下远程启动模型 xinference launch -n qwen2.5-instruct -s 0_5 -f pytorch -e "http://${supervisor_host}:9997"

框架内置资源调度器,可将不同大小的模型按需调度到不同机器(可通过--worker-ip--gpu-idx指定目标节点与 GPU,或用--n-worker将单个大模型切分到多个 worker 上运行),从而充分利用集群资源;关于分布式推理的架构细节可进一步阅读 doc/source/user_guide/distributed_inference.rst。

Referencias para profundizar

  • 官方使用指南:doc/source/getting_started/using_xinference.rst(启动、调用、管理、集群部署)
  • 安装文档:doc/source/getting_started/installation.rst(后端拆装与量化依赖)
  • 命令行实现:xinference/deploy/cmdline.py(全部 CLI 命令与参数)
  • Docker 编排:xinference/deploy/docker/docker-compose.yml
  • 客户端 API:xinference/client/restful/restful_client.py 与 xinference/client/restful/async_restful_client.py

Cómo citar el proyecto

若此项目对你的工作有帮助,官方建议以下列格式引用(出自 READMES/README_es.md):

@inproceedings{lu2024xinference, title = "Xinference: Making Large Model Serving Easy", author = "Lu, Weizheng and Xiong, Lingfeng and Zhang, Feng and Qin, Xuye and Chen, Yueguo", booktitle = "Proceedings of the 2024 Conference on Empirical Methods in Natural Language Processing: System Demonstrations", month = nov, year = "2024", pages = "291--300", }

【免费下载链接】inferenceSwap GPT for any LLM by changing a single line of code. Xinference lets you run open-source, speech, and multimodal models on cloud, on-prem, or your laptop — all through one unified, production-ready inference API.项目地址: https://gitcode.com/GitHub_Trending/in/inference

创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考

需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询