安裝#
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 作為引擎以達到更高的吞吐量:
模型格式為
pytorch、gptq、awq、fp4、fp8或者bnb。當模型格式為
pytorch時,量化選項需為none。當模型格式為
awq時,量化選項需為Int4。當模型格式為
gptq時,量化選項需為Int3、Int4或者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,minicpm5-1b,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-chatcodestral-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_v2Baichuan-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-2504llama-3.2-vision,llama-3.2-vision-instructbaichuan-2,baichuan-2-chatInternLM2ForCausalLMqwen-chatmixtral-8x22B-instruct-v0.1,mixtral-instruct-v0.1,mixtral-v0.1cogagentglm-edge-chat,glm4-chat,glm4-chat-1mcodegeex4,glm-4vseallm_v2.5orion-chatqwen1.5-moe-chat,qwen2-moe-instructCohereForCausalLMdeepseek-v2-chat,deepseek-v2-chat-0628,deepseek-v2.5,deepseek-vl2deepseek-prover-v2,deepseek-r1,deepseek-r1-0528,deepseek-v3,deepseek-v3-0324,Deepseek-V3.1,moonlight-16b-a3b-instructdeepseek-r1-0528-qwen3,qwen3minicpm3-4binternlm3-instructgemma-3-1b-itglm4-0414minicpm-2b-dpo-bf16,minicpm-2b-dpo-fp16,minicpm-2b-dpo-fp32,minicpm-2b-sft-bf16,minicpm-2b-sft-fp32,minicpm4Ernie4.5Qwen3-Coder,Qwen3-Instruct,Qwen3-Thinkingglm-4.5,GLM-4.6,GLM-4.7gpt-ossseed-ossQwen3-Next-Instruct,Qwen3-Next-ThinkingDeepSeek-V3.2,DeepSeek-V3.2-ExpMiniMax-M2,MiniMax-M2.5,MiniMax-M2.7GLM-4.7-Flashglm-5,glm-5.1DeepSeek-V4-Flash,DeepSeek-V4-Pro
安裝 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]"