安装 — Xinference (original) (raw)

安装#

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

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

pip install "xinference[all]"

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

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]"

vLLM 引擎#

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

目前,支持的模型包括:

安装 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 开始,该后端已被移除。

初始步骤:

xllamacpp 的安装说明:

SGLang 引擎#

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

初始步骤:

pip install "xinference[sglang]"

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

MLX 引擎#

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

初始步骤:

pip install "xinference[mlx]"

其他平台#