安装#
Xinference 在 Linux, Windows, MacOS 上都可以通过 pip 来安装。如果需要使用 Xinference 进行模型推理,可以根据不同的模型指定不同的引擎。
如果你希望能够推理所有支持的模型,可以用以下命令安装所有需要的依赖:
pip install "xinference[all]"
备注
如果你想使用 GGML 格式的模型,建议根据当前使用的硬件手动安装所需要的依赖,以充分利用硬件的加速能力。更多细节可以参考 Llama.cpp 引擎 这一章节。
如果你只想安装必要的依赖,接下来是如何操作的详细步骤。
Transformers 引擎#
PyTorch(transformers) 引擎支持几乎有所的最新模型,这是 Pytorch 模型默认使用的引擎:
pip install "xinference[transformers]"
vLLM 引擎#
vLLM 是一个支持高并发的高性能大模型推理引擎。当满足以下条件时,Xinference 会自动选择 vllm 作为引擎来达到更高的吞吐量:
模型格式为
pytorch,gptq或者awq。当模型格式为
pytorch时,量化选项需为none。当模型格式为
awq时,量化选项需为Int4。当模型格式为
gptq时,量化选项需为Int3、Int4或者Int8。操作系统为 Linux 并且至少有一个支持 CUDA 的设备
自定义模型的
model_family字段和内置模型的model_name字段在 vLLM 的支持列表中。
目前,支持的模型包括:
llama-2,llama-3,llama-2-chat,llama-3-instructbaichuan,baichuan-chat,baichuan-2-chatinternlm-16k,internlm-chat-7b,internlm-chat-8k,internlm-chat-20bmistral-v0.1,mistral-instruct-v0.1,mistral-instruct-v0.2Yi,Yi-chatcode-llama,code-llama-python,code-llama-instructc4ai-command-r-v01,c4ai-command-r-v01-4bitvicuna-v1.3,vicuna-v1.5internlm2-chatqwen-chatmixtral-instruct-v0.1,mixtral-8x22B-instruct-v0.1chatglm3,chatglm3-32k,chatglm3-128kdeepseek-chat,deepseek-coder-instructqwen1.5-chat,qwen1.5-moe-chatcodeqwen1.5-chatgemma-itorion-chat,orion-chat-rag
安装 xinference 和 vLLM:
pip install "xinference[vllm]"
Llama.cpp 引擎#
Xinference 通过 llama-cpp-python 支持 gguf 和 ggml 格式的模型。建议根据当前使用的硬件手动安装依赖,从而获得最佳的加速效果。
初始步骤:
pip install xinference
不同硬件的安装方式:
Apple M系列
CMAKE_ARGS="-DLLAMA_METAL=on" pip install llama-cpp-python
英伟达显卡:
CMAKE_ARGS="-DLLAMA_CUBLAS=on" pip install llama-cpp-python
AMD 显卡:
CMAKE_ARGS="-DLLAMA_HIPBLAS=on" pip install llama-cpp-python
SGLang 引擎#
SGLang 具有基于 RadixAttention 的高性能推理运行时。它通过在多个调用之间自动重用KV缓存,显著加速了复杂 LLM 程序的执行。它还支持其他常见推理技术,如连续批处理和张量并行处理。
初始步骤:
pip install 'xinference[sglang]'