安装#

Xinference 在 Linux, Windows, MacOS 上都可以通过 pip 来安装。如果需要使用 Xinference 进行模型推理,可以根据不同的模型指定不同的引擎。

如果你希望能够推理所有支持的模型,可以用以下命令安装所有需要的依赖:

pip install "xinference[all]"

在 v1.8.1 版本发生变更: 由于 vllm 和 sglang 在包依赖上无法调和,因此,我们从 all 里移除了 sglang,如果要使用 sglang,请使用 pip install 'xinference[sglang]'

某些使用场景需要特别注意。

GGUF 格式 配合 llama.cpp 引擎 使用

在这种情况下,建议根据您的硬件规格手动安装其依赖项以启用加速。更多详情请参见 Llama.cpp 引擎 部分。

AWQ 或 GPTQ 格式 配合 transformers 引擎 使用

本节内容新增于 v1.6.0。

这是因为此阶段的依赖项需要特殊选项,并且安装起来比较困难。请提前运行以下命令

pip install "xinference[transformers_quantization]" --no-build-isolation

某些依赖项,如 transformers,可能会被降级,您可以之后运行 pip install "xinference[all]"

如果你只想安装必要的依赖,接下来是如何操作的详细步骤。

Transformers 引擎#

PyTorch(transformers) 引擎支持几乎有所的最新模型,这是 Pytorch 模型默认使用的引擎:

pip install "xinference[transformers]"

注意:

  • Transformers引擎支持 pytorch / gptq / awq / bnb / fp4 格式。

  • FP4格式需要支持FPQuantConfig的transformers库。若遇到导入错误,请将transformers升级至新版本。

vLLM 引擎#

vLLM 是一个支持高并发的高性能大模型推理引擎。当满足以下条件时,Xinference 会自动选择 vllm 作为引擎来达到更高的吞吐量:

  • 模型格式为 pytorchgptqawqfp4fp8 或者 bnb

  • 当模型格式为 pytorch 时,量化选项需为 none

  • 当模型格式为 awq 时,量化选项需为 Int4

  • 当模型格式为 gptq 时,量化选项需为 Int3Int4 或者 Int8

  • 操作系统为 Linux 并且至少有一个支持 CUDA 的设备

  • 自定义模型的 model_family 字段和内置模型的 model_name 字段在 vLLM 的支持列表中。

目前,支持的模型包括:

  • code-llama, code-llama-instruct, code-llama-python, deepseek, deepseek-chat, deepseek-coder, deepseek-coder-instruct, deepseek-r1-distill-llama, gorilla-openfunctions-v2, HuatuoGPT-o1-LLaMA-3.1, llama-2, llama-2-chat, llama-3, llama-3-instruct, llama-3.1, llama-3.1-instruct, llama-3.3-instruct, tiny-llama, wizardcoder-python-v1.0, wizardmath-v1.0, Yi, Yi-1.5, Yi-1.5-chat, Yi-1.5-chat-16k, Yi-200k, Yi-chat

  • codestral-v0.1, mistral-instruct-v0.1, mistral-instruct-v0.2, mistral-instruct-v0.3, mistral-large-instruct, mistral-nemo-instruct, mistral-v0.1, openhermes-2.5, seallm_v2

  • Baichuan-M2, codeqwen1.5, codeqwen1.5-chat, deepseek-r1-distill-qwen, DianJin-R1, fin-r1, HuatuoGPT-o1-Qwen2.5, KAT-V1, marco-o1, qwen1.5-chat, qwen2-instruct, qwen2.5, qwen2.5-coder, qwen2.5-coder-instruct, qwen2.5-instruct, qwen2.5-instruct-1m, qwenLong-l1, QwQ-32B, QwQ-32B-Preview, seallms-v3, skywork-or1, skywork-or1-preview, XiYanSQL-QwenCoder-2504

  • llama-3.2-vision, llama-3.2-vision-instruct

  • baichuan-2, baichuan-2-chat

  • InternLM2ForCausalLM

  • qwen-chat

  • mixtral-8x22B-instruct-v0.1, mixtral-instruct-v0.1, mixtral-v0.1

  • cogagent

  • glm-edge-chat, glm4-chat, glm4-chat-1m

  • codegeex4, glm-4v

  • seallm_v2.5

  • orion-chat

  • qwen1.5-moe-chat, qwen2-moe-instruct

  • CohereForCausalLM

  • deepseek-v2-chat, deepseek-v2-chat-0628, deepseek-v2.5, deepseek-vl2

  • deepseek-prover-v2, deepseek-r1, deepseek-r1-0528, deepseek-v3, deepseek-v3-0324, Deepseek-V3.1, moonlight-16b-a3b-instruct

  • deepseek-r1-0528-qwen3, qwen3

  • minicpm3-4b

  • internlm3-instruct

  • gemma-3-1b-it

  • glm4-0414

  • minicpm-2b-dpo-bf16, minicpm-2b-dpo-fp16, minicpm-2b-dpo-fp32, minicpm-2b-sft-bf16, minicpm-2b-sft-fp32, minicpm4

  • Ernie4.5

  • Qwen3-Coder, Qwen3-Instruct, Qwen3-Thinking

  • glm-4.5, GLM-4.6, GLM-4.7

  • gpt-oss

  • seed-oss

  • Qwen3-Next-Instruct, Qwen3-Next-Thinking

  • DeepSeek-V3.2, DeepSeek-V3.2-Exp

  • MiniMax-M2, MiniMax-M2.5, MiniMax-M2.7

  • glm-5, glm-5.1

安装 xinference 和 vLLM:

pip install "xinference[vllm]"

# FlashInfer is optional but required for specific functionalities such as sliding window attention with Gemma 2.
# For CUDA 12.4 & torch 2.4 to support sliding window attention for gemma 2 and llama 3.1 style rope
pip install flashinfer -i https://flashinfer.ai/whl/cu124/torch2.4
# For other CUDA & torch versions, please check https://docs.flashinfer.ai/installation.html

Llama.cpp 引擎#

Xinference 通过 xllamacpp 支持 gguf 格式的模型。xllamacpp 由 Xinference 团队开发,并从 v1.6.0 开始成为 llama.cpp 的唯一后端。

警告

自 Xinference v1.5.0 起,llama-cpp-python 被弃用;在 Xinference 从 v1.6.0 开始,该后端已被移除。

初始步骤:

pip install "xinference[llama_cpp]"

更多的 xllamacpp 安装说明以便开启 GPU 加速,请参考:xorbitsai/xllamacpp

SGLang 引擎#

SGLang 具有基于 RadixAttention 的高性能推理运行时。它通过在多个调用之间自动重用KV缓存,显著加速了复杂 LLM 程序的执行。它还支持其他常见推理技术,如连续批处理和张量并行处理。

初始步骤:

pip install "xinference[sglang]"

MLX 引擎#

MLX-lm 用来在苹果 silicon 芯片上提供高效的 LLM 推理。

初始步骤:

pip install "xinference[mlx]"

其他平台#