跳过内容

支持的模型

vLLM 支持生成池化模型,涵盖各种任务。如果一个模型支持多于一种任务,您可以通过 --task 参数设置任务。

对于每项任务,我们列出了已在 vLLM 中实现的模型架构。在每个架构旁边,我们列出了一些使用它的热门模型。

模型实现

vLLM

如果 vLLM 原生支持某个模型,其实现可在 vllm/model_executor/models 中找到。

这些模型列于支持的纯文本模型支持的多模态模型中。

Transformers

vLLM 也支持 Transformers 中可用的模型实现。目前并非所有模型都支持,但大多数解码器语言模型都已支持,并且正在计划支持视觉语言模型!

要检查建模后端是否为 Transformers,您可以简单地这样做

from vllm import LLM
llm = LLM(model=..., task="generate")  # Name or path of your model
llm.apply_model(lambda model: print(type(model)))

如果它是 TransformersForCausalLM,则表示它基于 Transformers!

提示

您可以通过为离线推理设置 model_impl="transformers" 或为兼容 OpenAI 的服务设置 --model-impl transformers 来强制使用 TransformersForCausalLM

注意

vLLM 可能无法完全优化 Transformers 实现,因此在 vLLM 中比较原生模型与 Transformers 模型时,您可能会看到性能下降。

自定义模型

如果一个模型既不是 vLLM 原生支持,也不是 Transformers 支持,它仍然可以在 vLLM 中使用!

模型若要与 vLLM 的 Transformers 后端兼容,必须满足以下条件:

  • 是 Transformers 兼容的自定义模型(参见Transformers - 自定义模型
    • 模型目录必须具有正确的结构(例如存在 config.json)。
    • config.json 必须包含 auto_map.AutoModel
  • 是兼容 vLLM Transformers 后端的模型(参见编写自定义模型
    • 自定义应在基础模型中进行(例如在 MyModel 中,而不是 MyModelForCausalLM 中)。

如果兼容的模型位于

这意味着,借助 vLLM 的 Transformers 后端,可以在新模型正式在 Transformers 或 vLLM 中得到支持之前使用它们!

编写自定义模型

本节详细介绍了使 Transformers 兼容的自定义模型与 vLLM 的 Transformers 后端兼容所需的修改。(我们假设已经创建了一个 Transformers 兼容的自定义模型,参见Transformers - 自定义模型)。

要使您的模型与 Transformers 后端兼容,它需要

  1. kwargsMyModel 传递到 MyAttention 的所有模块。
  2. MyAttention 必须使用 ALL_ATTENTION_FUNCTIONS 来调用注意力。
  3. MyModel 必须包含 _supports_attention_backend = True
modeling_my_model.py
from transformers import PreTrainedModel
from torch import nn

class MyAttention(nn.Module):

    def forward(self, hidden_states, **kwargs):
        ...
        attention_interface = ALL_ATTENTION_FUNCTIONS[self.config._attn_implementation]
        attn_output, attn_weights = attention_interface(
            self,
            query_states,
            key_states,
            value_states,
            **kwargs,
        )
        ...

class MyModel(PreTrainedModel):
    _supports_attention_backend = True

加载此模型时,后台发生的情况如下:

  1. 配置被加载。
  2. MyModel Python 类从 config 中的 auto_map 加载,并且我们检查模型是否 is_backend_compatible()
  3. MyModel 加载到 TransformersForCausalLM 中(参见 vllm/model_executor/models/transformers.py) 中,这会设置 self.config._attn_implementation = "vllm",以便使用 vLLM 的注意力层。

就是这样!

为了让您的模型兼容 vLLM 的张量并行和/或流水线并行功能,您必须将 base_model_tp_plan 和/或 base_model_pp_plan 添加到您模型的 config 类中

configuration_my_model.py
from transformers import PretrainedConfig

class MyConfig(PretrainedConfig):
    base_model_tp_plan = {
        "layers.*.self_attn.k_proj": "colwise",
        "layers.*.self_attn.v_proj": "colwise",
        "layers.*.self_attn.o_proj": "rowwise",
        "layers.*.mlp.gate_proj": "colwise",
        "layers.*.mlp.up_proj": "colwise",
        "layers.*.mlp.down_proj": "rowwise",
    }
    base_model_pp_plan = {
        "embed_tokens": (["input_ids"], ["inputs_embeds"]),
        "layers": (["hidden_states", "attention_mask"], ["hidden_states"]),
        "norm": (["hidden_states"], ["hidden_states"]),
    }
  • base_model_tp_plan 是一个 dict,将完全限定的层名称模式映射到张量并行样式(目前仅支持 "colwise""rowwise")。
  • base_model_pp_plan 是一个 dict,将直接子层名称映射到由 str 列表组成的 tuple
    • 您只需对并非存在于所有流水线阶段的层进行此操作
    • vLLM 假设只有一个 nn.ModuleList,它分布在各个流水线阶段
    • 元组中第一个元素中的 list 包含输入参数的名称
    • 元组中最后一个元素中的 list 包含层在您的建模代码中输出的变量名称

加载模型

Hugging Face Hub

默认情况下,vLLM 从Hugging Face (HF) Hub 加载模型。要更改模型的下载路径,可以设置 HF_HOME 环境变量;更多详细信息,请参考他们的官方文档

要确定给定模型是否原生支持,您可以检查 HF 仓库中的 config.json 文件。如果 "architectures" 字段包含下面列出的模型架构,那么它应该原生支持。

模型并非原生支持才能在 vLLM 中使用。Transformers 后端使您能够直接使用其 Transformers 实现(甚至 Hugging Face Model Hub 上的远程代码!)运行模型。

提示

检查您的模型在运行时是否真正支持的最简单方法是运行以下程序

from vllm import LLM

# For generative models (task=generate) only
llm = LLM(model=..., task="generate")  # Name or path of your model
output = llm.generate("Hello, my name is")
print(output)

# For pooling models (task={embed,classify,reward,score}) only
llm = LLM(model=..., task="embed")  # Name or path of your model
output = llm.encode("Hello, my name is")
print(output)

如果 vLLM 成功返回文本(对于生成模型)或隐藏状态(对于池化模型),则表示您的模型受支持。

否则,请参考添加新模型获取如何在 vLLM 中实现模型的说明。或者,您可以在GitHub 上提交一个 issue来请求 vLLM 支持。

下载模型

如果您愿意,可以使用 Hugging Face CLI下载模型或从模型仓库下载特定文件

# Download a model
huggingface-cli download HuggingFaceH4/zephyr-7b-beta

# Specify a custom cache directory
huggingface-cli download HuggingFaceH4/zephyr-7b-beta --cache-dir ./path/to/cache

# Download a specific file from a model repo
huggingface-cli download HuggingFaceH4/zephyr-7b-beta eval_results.json

列出已下载的模型

使用 Hugging Face CLI管理本地缓存中存储的模型

# List cached models
huggingface-cli scan-cache

# Show detailed (verbose) output
huggingface-cli scan-cache -v

# Specify a custom cache directory
huggingface-cli scan-cache --dir ~/.cache/huggingface/hub

删除缓存的模型

使用 Hugging Face CLI 以交互方式从缓存中删除已下载的模型

# The `delete-cache` command requires extra dependencies to work with the TUI.
# Please run `pip install huggingface_hub[cli]` to install them.

# Launch the interactive TUI to select models to delete
$ huggingface-cli delete-cache
? Select revisions to delete: 1 revisions selected counting for 438.9M.
  ○ None of the following (if selected, nothing will be deleted).
Model BAAI/bge-base-en-v1.5 (438.9M, used 1 week ago)
❯ ◉ a5beb1e3: main # modified 1 week ago

Model BAAI/bge-large-en-v1.5 (1.3G, used 1 week ago)
  ○ d4aa6901: main # modified 1 week ago

Model BAAI/bge-reranker-base (1.1G, used 4 weeks ago)
  ○ 2cfc18c9: main # modified 4 weeks ago

Press <space> to select, <enter> to validate and <ctrl+c> to quit without modification.

# Need to confirm after selected
? Select revisions to delete: 1 revision(s) selected.
? 1 revisions selected counting for 438.9M. Confirm deletion ? Yes
Start deletion.
Done. Deleted 1 repo(s) and 0 revision(s) for a total of 438.9M.

使用代理

以下是一些使用代理从 Hugging Face 加载/下载模型的提示

  • 为您的会话全局设置代理(或在配置文件中设置)
export http_proxy=http://your.proxy.server:port
export https_proxy=http://your.proxy.server:port
  • 仅为当前命令设置代理
https_proxy=http://your.proxy.server:port huggingface-cli download <model_name>

# or use vllm cmd directly
https_proxy=http://your.proxy.server:port  vllm serve <model_name> --disable-log-requests
  • 在 Python 解释器中设置代理
import os

os.environ['http_proxy'] = 'http://your.proxy.server:port'
os.environ['https_proxy'] = 'http://your.proxy.server:port'

ModelScope

要使用ModelScope 而不是 Hugging Face Hub 中的模型,请设置一个环境变量

export VLLM_USE_MODELSCOPE=True

并与 trust_remote_code=True 一起使用。

from vllm import LLM

llm = LLM(model=..., revision=..., task=..., trust_remote_code=True)

# For generative models (task=generate) only
output = llm.generate("Hello, my name is")
print(output)

# For pooling models (task={embed,classify,reward,score}) only
output = llm.encode("Hello, my name is")
print(output)

功能状态图例

  • ✅︎ 表示该模型支持此功能。

  • 🚧 表示该功能已计划但该模型尚未支持。

  • ⚠️ 表示该功能可用但可能存在已知问题或限制。

纯文本语言模型列表

生成模型

请参阅 此页面 获取有关如何使用生成模型的更多信息。

文本生成

使用 --task generate 指定。

架构 模型 示例 HF 模型 LoRA PP
AquilaForCausalLM Aquila, Aquila2 BAAI/Aquila-7BBAAI/AquilaChat-7B 等。 ✅︎ ✅︎
ArcticForCausalLM Arctic Snowflake/snowflake-arctic-baseSnowflake/snowflake-arctic-instruct 等。 ✅︎
BaiChuanForCausalLM Baichuan2, Baichuan baichuan-inc/Baichuan2-13B-Chatbaichuan-inc/Baichuan-7B 等。 ✅︎ ✅︎
BambaForCausalLM Bamba ibm-ai-platform/Bamba-9B-fp8ibm-ai-platform/Bamba-9B ✅︎ ✅︎
BloomForCausalLM BLOOM, BLOOMZ, BLOOMChat bigscience/bloombigscience/bloomz 等。 ✅︎
BartForConditionalGeneration BART facebook/bart-basefacebook/bart-large-cnn 等。
ChatGLMModelChatGLMForConditionalGeneration ChatGLM THUDM/chatglm2-6bTHUDM/chatglm3-6bShieldLM-6B-chatglm3 等。 ✅︎ ✅︎
CohereForCausalLMCohere2ForCausalLM Command-R CohereForAI/c4ai-command-r-v01CohereForAI/c4ai-command-r7b-12-2024 等。 ✅︎ ✅︎
DbrxForCausalLM DBRX databricks/dbrx-basedatabricks/dbrx-instruct 等。 ✅︎
DeciLMForCausalLM DeciLM nvidia/Llama-3_3-Nemotron-Super-49B-v1 等。 ✅︎ ✅︎
DeepseekForCausalLM DeepSeek deepseek-ai/deepseek-llm-67b-basedeepseek-ai/deepseek-llm-7b-chat 等。 ✅︎
DeepseekV2ForCausalLM DeepSeek-V2 deepseek-ai/DeepSeek-V2deepseek-ai/DeepSeek-V2-Chat 等。 ✅︎
DeepseekV3ForCausalLM DeepSeek-V3 deepseek-ai/DeepSeek-V3-Basedeepseek-ai/DeepSeek-V3 等。 ✅︎
ExaoneForCausalLM EXAONE-3 LGAI-EXAONE/EXAONE-3.0-7.8B-Instruct 等。 ✅︎ ✅︎
FalconForCausalLM Falcon tiiuae/falcon-7btiiuae/falcon-40btiiuae/falcon-rw-7b 等。 ✅︎
FalconMambaForCausalLM FalconMamba tiiuae/falcon-mamba-7btiiuae/falcon-mamba-7b-instruct 等。 ✅︎
FalconH1ForCausalLM Falcon-H1 tiiuae/Falcon-H1-34B-Basetiiuae/Falcon-H1-34B-Instruct 等。 ✅︎ ✅︎
GemmaForCausalLM Gemma google/gemma-2bgoogle/gemma-1.1-2b-it 等。 ✅︎ ✅︎
Gemma2ForCausalLM Gemma 2 google/gemma-2-9bgoogle/gemma-2-27b 等。 ✅︎ ✅︎
Gemma3ForCausalLM Gemma 3 google/gemma-3-1b-it 等。 ✅︎ ✅︎
GlmForCausalLM GLM-4 THUDM/glm-4-9b-chat-hf 等。 ✅︎ ✅︎
Glm4ForCausalLM GLM-4-0414 THUDM/GLM-4-32B-0414 等。 ✅︎ ✅︎
GPT2LMHeadModel GPT-2 gpt2gpt2-xl 等。 ✅︎
GPTBigCodeForCausalLM StarCoder, SantaCoder, WizardCoder bigcode/starcoderbigcode/gpt_bigcode-santacoderWizardLM/WizardCoder-15B-V1.0 等。 ✅︎ ✅︎
GPTJForCausalLM GPT-J EleutherAI/gpt-j-6bnomic-ai/gpt4all-j 等。 ✅︎
GPTNeoXForCausalLM GPT-NeoX, Pythia, OpenAssistant, Dolly V2, StableLM EleutherAI/gpt-neox-20bEleutherAI/pythia-12bOpenAssistant/oasst-sft-4-pythia-12b-epoch-3.5databricks/dolly-v2-12bstabilityai/stablelm-tuned-alpha-7b 等。 ✅︎
GraniteForCausalLM Granite 3.0, Granite 3.1, PowerLM ibm-granite/granite-3.0-2b-baseibm-granite/granite-3.1-8b-instructibm/PowerLM-3b 等。 ✅︎ ✅︎
GraniteMoeForCausalLM Granite 3.0 MoE, PowerMoE ibm-granite/granite-3.0-1b-a400m-baseibm-granite/granite-3.0-3b-a800m-instructibm/PowerMoE-3b 等。 ✅︎ ✅︎
GraniteMoeHybridForCausalLM Granite 4.0 MoE Hybrid ibm-granite/granite-4.0-tiny-preview 等。 ✅︎ ✅︎
GraniteMoeSharedForCausalLM Granite MoE Shared ibm-research/moe-7b-1b-active-shared-experts(测试模型) ✅︎ ✅︎
GritLM GritLM parasail-ai/GritLM-7B-vllm. ✅︎ ✅︎
Grok1ModelForCausalLM Grok1 hpcai-tech/grok-1. ✅︎ ✅︎
InternLMForCausalLM InternLM internlm/internlm-7binternlm/internlm-chat-7b 等。 ✅︎ ✅︎
InternLM2ForCausalLM InternLM2 internlm/internlm2-7binternlm/internlm2-chat-7b 等。 ✅︎ ✅︎
InternLM3ForCausalLM InternLM3 internlm/internlm3-8b-instruct 等。 ✅︎ ✅︎
JAISLMHeadModel Jais inceptionai/jais-13binceptionai/jais-13b-chatinceptionai/jais-30b-v3inceptionai/jais-30b-chat-v3 等。 ✅︎
JambaForCausalLM Jamba ai21labs/AI21-Jamba-1.5-Largeai21labs/AI21-Jamba-1.5-Miniai21labs/Jamba-v0.1 等。 ✅︎ ✅︎
LlamaForCausalLM Llama 3.1, Llama 3, Llama 2, LLaMA, Yi meta-llama/Meta-Llama-3.1-405B-Instructmeta-llama/Meta-Llama-3.1-70Bmeta-llama/Meta-Llama-3-70B-Instructmeta-llama/Llama-2-70b-hf01-ai/Yi-34B 等。 ✅︎ ✅︎
MambaForCausalLM Mamba state-spaces/mamba-130m-hfstate-spaces/mamba-790m-hfstate-spaces/mamba-2.8b-hf 等。 ✅︎
MiniCPMForCausalLM MiniCPM openbmb/MiniCPM-2B-sft-bf16openbmb/MiniCPM-2B-dpo-bf16openbmb/MiniCPM-S-1B-sft 等。 ✅︎ ✅︎
MiniCPM3ForCausalLM MiniCPM3 openbmb/MiniCPM3-4B 等。 ✅︎ ✅︎
MistralForCausalLM Mistral, Mistral-Instruct mistralai/Mistral-7B-v0.1mistralai/Mistral-7B-Instruct-v0.1 等。 ✅︎ ✅︎
MixtralForCausalLM Mixtral-8x7B, Mixtral-8x7B-Instruct mistralai/Mixtral-8x7B-v0.1mistralai/Mixtral-8x7B-Instruct-v0.1mistral-community/Mixtral-8x22B-v0.1 等。 ✅︎ ✅︎
MPTForCausalLM MPT, MPT-Instruct, MPT-Chat, MPT-StoryWriter mosaicml/mpt-7bmosaicml/mpt-7b-storywritermosaicml/mpt-30b 等。 ✅︎
NemotronForCausalLM Nemotron-3, Nemotron-4, Minitron nvidia/Minitron-8B-Basemgoin/Nemotron-4-340B-Base-hf-FP8 等。 ✅︎ ✅︎
OLMoForCausalLM OLMo allenai/OLMo-1B-hfallenai/OLMo-7B-hf 等。 ✅︎
OLMo2ForCausalLM OLMo2 allenai/OLMo-2-0425-1B 等。 ✅︎
OLMoEForCausalLM OLMoE allenai/OLMoE-1B-7B-0924allenai/OLMoE-1B-7B-0924-Instruct 等。 ✅︎
OPTForCausalLM OPT, OPT-IML facebook/opt-66bfacebook/opt-iml-max-30b 等。 ✅︎
OrionForCausalLM Orion OrionStarAI/Orion-14B-BaseOrionStarAI/Orion-14B-Chat 等。 ✅︎
PhiForCausalLM Phi microsoft/phi-1_5microsoft/phi-2 等。 ✅︎ ✅︎
Phi3ForCausalLM Phi-4, Phi-3 microsoft/Phi-4-mini-instructmicrosoft/Phi-4microsoft/Phi-3-mini-4k-instructmicrosoft/Phi-3-mini-128k-instructmicrosoft/Phi-3-medium-128k-instruct 等。 ✅︎ ✅︎
Phi3SmallForCausalLM Phi-3-Small microsoft/Phi-3-small-8k-instructmicrosoft/Phi-3-small-128k-instruct 等。 ✅︎
PhiMoEForCausalLM Phi-3.5-MoE microsoft/Phi-3.5-MoE-instruct 等。 ✅︎ ✅︎
PersimmonForCausalLM Persimmon adept/persimmon-8b-baseadept/persimmon-8b-chat 等。 ✅︎
Plamo2ForCausalLM PLaMo2 pfnet/plamo-2-1bpfnet/plamo-2-8b 等。
QWenLMHeadModel Qwen Qwen/Qwen-7BQwen/Qwen-7B-Chat 等。 ✅︎ ✅︎
Qwen2ForCausalLM QwQ, Qwen2 Qwen/QwQ-32B-PreviewQwen/Qwen2-7B-InstructQwen/Qwen2-7B 等。 ✅︎ ✅︎
Qwen2MoeForCausalLM Qwen2MoE Qwen/Qwen1.5-MoE-A2.7BQwen/Qwen1.5-MoE-A2.7B-Chat 等。 ✅︎
Qwen3ForCausalLM Qwen3 Qwen/Qwen3-8B 等。 ✅︎ ✅︎
Qwen3MoeForCausalLM Qwen3MoE Qwen/Qwen3-30B-A3B 等。 ✅︎
StableLmForCausalLM StableLM stabilityai/stablelm-3b-4e1tstabilityai/stablelm-base-alpha-7b-v2 等。
Starcoder2ForCausalLM Starcoder2 bigcode/starcoder2-3bbigcode/starcoder2-7bbigcode/starcoder2-15b 等。 ✅︎
SolarForCausalLM Solar Pro upstage/solar-pro-preview-instruct 等。 ✅︎ ✅︎
TeleChat2ForCausalLM TeleChat2 Tele-AI/TeleChat2-3BTele-AI/TeleChat2-7BTele-AI/TeleChat2-35B 等。 ✅︎ ✅︎
TeleFLMForCausalLM TeleFLM CofeAI/FLM-2-52B-Instruct-2407CofeAI/Tele-FLM 等。 ✅︎ ✅︎
XverseForCausalLM XVERSE xverse/XVERSE-7B-Chatxverse/XVERSE-13B-Chatxverse/XVERSE-65B-Chat 等。 ✅︎ ✅︎
MiniMaxText01ForCausalLM MiniMax-Text MiniMaxAI/MiniMax-Text-01 等。
Zamba2ForCausalLM Zamba2 Zyphra/Zamba2-7B-instructZyphra/Zamba2-2.7B-instructZyphra/Zamba2-1.2B-instruct 等。

注意

目前,vLLM 的 ROCm 版本仅支持 Mistral 和 Mixtral,上下文长度最大为 4096。

池化模型

请参阅此页面获取有关如何使用池化模型的更多信息。

警告

由于某些模型架构同时支持生成和池化任务,您应该显式指定任务类型,以确保模型以池化模式而不是生成模式使用。

文本嵌入

使用 --task embed 指定。

架构 模型 示例 HF 模型 LoRA PP
BertModel 基于 BERT BAAI/bge-base-en-v1.5Snowflake/snowflake-arctic-embed-xs 等。
Gemma2Model 基于 Gemma 2 BAAI/bge-multilingual-gemma2 等。 ✅︎
GritLM GritLM parasail-ai/GritLM-7B-vllm. ✅︎ ✅︎
GteModel Arctic-Embed-2.0-M Snowflake/snowflake-arctic-embed-m-v2.0.
GteNewModel mGTE-TRM(参见注释) Alibaba-NLP/gte-multilingual-base 等。
ModernBertModel 基于 ModernBERT Alibaba-NLP/gte-modernbert-base 等。
NomicBertModel Nomic BERT nomic-ai/nomic-embed-text-v1nomic-ai/nomic-embed-text-v2-moeSnowflake/snowflake-arctic-embed-m-long 等。
LlamaModelLlamaForCausalLMMistralModel 等。 基于 Llama intfloat/e5-mistral-7b-instruct 等。 ✅︎ ✅︎
Qwen2ModelQwen2ForCausalLM 基于 Qwen2 ssmits/Qwen2-7B-Instruct-embed-base(参见注释)、Alibaba-NLP/gte-Qwen2-7B-instruct(参见注释)等。 ✅︎ ✅︎
RobertaModelRobertaForMaskedLM 基于 RoBERTa sentence-transformers/all-roberta-large-v1 等。

注意

ssmits/Qwen2-7B-Instruct-embed-base 的 Sentence Transformers 配置定义不正确。您需要通过传递 --override-pooler-config '{"pooling_type": "MEAN"}' 手动设置均值池化。

注意

对于 Alibaba-NLP/gte-Qwen2-*,您需要启用 --trust-remote-code 以便加载正确的分词器。参见 HF Transformers 上的相关 issue

注意

jinaai/jina-embeddings-v3 通过 lora 支持多种任务,而 vllm 暂时只通过合并 lora 权重支持文本匹配任务。

注意

第二代 GTE 模型 (mGTE-TRM) 被命名为 NewModel。名称 NewModel 太通用了,您应该设置 --hf-overrides '{"architectures": ["GteNewModel"]}' 来指定使用 GteNewModel 架构。

如果您的模型不在上述列表中,我们将尝试使用 as_embedding_model 自动转换模型。默认情况下,整个 prompt 的嵌入是从与最后一个 token 对应的归一化隐藏状态中提取的。

奖励建模

使用 --task reward 指定。

架构 模型 示例 HF 模型 LoRA PP
InternLM2ForRewardModel 基于 InternLM2 internlm/internlm2-1_8b-rewardinternlm/internlm2-7b-reward 等。 ✅︎ ✅︎
LlamaForCausalLM 基于 Llama peiyi9979/math-shepherd-mistral-7b-prm 等。 ✅︎ ✅︎
Qwen2ForRewardModel 基于 Qwen2 Qwen/Qwen2.5-Math-RM-72B 等。 ✅︎ ✅︎

如果您的模型不在上述列表中,我们将尝试使用 as_reward_model 自动转换模型。默认情况下,我们直接返回每个 token 的隐藏状态。

警告

对于诸如 peiyi9979/math-shepherd-mistral-7b-prm 之类的过程监督奖励模型,应显式设置池化配置,例如:--override-pooler-config '{"pooling_type": "STEP", "step_tag_id": 123, "returned_token_ids": [456, 789]}'

分类

使用 --task classify 指定。

架构 模型 示例 HF 模型 LoRA PP
JambaForSequenceClassification Jamba ai21labs/Jamba-tiny-reward-dev 等。 ✅︎ ✅︎

如果您的模型不在上述列表中,我们将尝试使用 as_classification_model 自动转换模型。默认情况下,类别概率是从与最后一个 token 对应的 softmaxed 隐藏状态中提取的。

句子对评分

使用 --task score 指定。

架构 模型 示例 HF 模型
BertForSequenceClassification 基于 BERT cross-encoder/ms-marco-MiniLM-L-6-v2 等。
RobertaForSequenceClassification 基于 RoBERTa cross-encoder/quora-roberta-base 等。
XLMRobertaForSequenceClassification 基于 XLM-RoBERTa BAAI/bge-reranker-v2-m3 等。

多模态语言模型列表

根据模型支持以下模态

  • Text(文本)
  • Image(图像)
  • Video(视频)
  • Audio(音频)

支持由 + 连接的任何模态组合。

  • 例如:T + I 表示模型支持纯文本、纯图像以及文本+图像输入。

另一方面,由 / 分隔的模态是互斥的。

  • 例如:T / I 表示模型支持纯文本和纯图像输入,但不支持文本+图像输入。

请参阅此页面了解如何将多模态输入传递给模型。

警告

要在 vLLM V0 中为每个文本 prompt 启用多个多模态项目,您必须设置 limit_mm_per_prompt(离线推理)或 --limit-mm-per-prompt(在线服务)。例如,要为每个文本 prompt 启用最多传递 4 张图像

离线推理

from vllm import LLM

llm = LLM(
    model="Qwen/Qwen2-VL-7B-Instruct",
    limit_mm_per_prompt={"image": 4},
)

在线服务

vllm serve Qwen/Qwen2-VL-7B-Instruct --limit-mm-per-prompt '{"image":4}'

如果您使用 vLLM V1,则不再需要此设置。

注意

vLLM 目前仅支持向多模态模型的语言主干添加 LoRA。

生成模型

请参阅 此页面 获取有关如何使用生成模型的更多信息。

文本生成

使用 --task generate 指定。

架构 模型 输入 示例 HF 模型 LoRA PP V1
AriaForConditionalGeneration Aria T + I+ rhymes-ai/Aria ✅︎
AyaVisionForConditionalGeneration Aya Vision T + I+ CohereForAI/aya-vision-8bCohereForAI/aya-vision-32b 等。 ✅︎ ✅︎
Blip2ForConditionalGeneration BLIP-2 T + IE Salesforce/blip2-opt-2.7bSalesforce/blip2-opt-6.7b 等。 ✅︎ ✅︎
ChameleonForConditionalGeneration Chameleon T + I facebook/chameleon-7b 等。 ✅︎ ✅︎
DeepseekVLV2ForCausalLM^ DeepSeek-VL2 T + I+ deepseek-ai/deepseek-vl2-tinydeepseek-ai/deepseek-vl2-smalldeepseek-ai/deepseek-vl2 等。 ✅︎ ✅︎
Florence2ForConditionalGeneration Florence-2 T + I microsoft/Florence-2-basemicrosoft/Florence-2-large 等。
FuyuForCausalLM Fuyu T + I adept/fuyu-8b 等。 ✅︎ ✅︎
Gemma3ForConditionalGeneration Gemma 3 T + I+ google/gemma-3-4b-itgoogle/gemma-3-27b-it 等。 ✅︎ ✅︎ ⚠️
GLM4VForCausalLM^ GLM-4V T + I THUDM/glm-4v-9bTHUDM/cogagent-9b-20241220 等。 ✅︎ ✅︎ ✅︎
GraniteSpeechForConditionalGeneration Granite Speech T + A ibm-granite/granite-speech-3.3-8b ✅︎ ✅︎ ✅︎
H2OVLChatModel H2OVL T + IE+ h2oai/h2ovl-mississippi-800mh2oai/h2ovl-mississippi-2b 等。 ✅︎ ✅︎*
Idefics3ForConditionalGeneration Idefics3 T + I HuggingFaceM4/Idefics3-8B-Llama3 等。 ✅︎ ✅︎
InternVLChatModel InternVL 3.0, InternVideo 2.5, InternVL 2.5, Mono-InternVL, InternVL 2.0 T + IE+ + (VE+) OpenGVLab/InternVL3-9BOpenGVLab/InternVideo2_5_Chat_8BOpenGVLab/InternVL2_5-4BOpenGVLab/Mono-InternVL-2BOpenGVLab/InternVL2-4B 等。 ✅︎ ✅︎
KimiVLForConditionalGeneration Kimi-VL-A3B-Instruct, Kimi-VL-A3B-Thinking T + I+ moonshotai/Kimi-VL-A3B-Instructmoonshotai/Kimi-VL-A3B-Thinking ✅︎
Llama4ForConditionalGeneration Llama 4 T + I+ meta-llama/Llama-4-Scout-17B-16E-Instructmeta-llama/Llama-4-Maverick-17B-128E-Instruct-FP8meta-llama/Llama-4-Maverick-17B-128E-Instruct 等。 ✅︎ ✅︎
LlavaForConditionalGeneration LLaVA-1.5 T + IE+ llava-hf/llava-1.5-7b-hfTIGER-Lab/Mantis-8B-siglip-llama3(参见注释)等。 ✅︎ ✅︎
LlavaNextForConditionalGeneration LLaVA-NeXT T + IE+ llava-hf/llava-v1.6-mistral-7b-hfllava-hf/llava-v1.6-vicuna-7b-hf 等。 ✅︎ ✅︎
LlavaNextVideoForConditionalGeneration LLaVA-NeXT-视频 T + V llava-hf/LLaVA-NeXT-Video-7B-hf 等。 ✅︎ ✅︎
LlavaOnevisionForConditionalGeneration LLaVA-Onevision T + I+ + V+ llava-hf/llava-onevision-qwen2-7b-ov-hfllava-hf/llava-onevision-qwen2-0.5b-ov-hf 等。 ✅︎ ✅︎
MiniCPMO MiniCPM-O T + IE+ + VE+ + AE+ openbmb/MiniCPM-o-2_6 等。 ✅︎ ✅︎ ✅︎
MiniCPMV MiniCPM-V T + IE+ + VE+ openbmb/MiniCPM-V-2(参见注释)、openbmb/MiniCPM-Llama3-V-2_5openbmb/MiniCPM-V-2_6 等。 ✅︎ ✅︎
MiniMaxVL01ForConditionalGeneration MiniMax-VL T + IE+ MiniMaxAI/MiniMax-VL-01 等。 ✅︎
Mistral3ForConditionalGeneration Mistral3 T + I+ mistralai/Mistral-Small-3.1-24B-Instruct-2503 等。 ✅︎ ✅︎ ✅︎
MllamaForConditionalGeneration Llama 3.2 T + I+ meta-llama/Llama-3.2-90B-Vision-Instructmeta-llama/Llama-3.2-11B-Vision 等。
MolmoForCausalLM Molmo T + I+ allenai/Molmo-7B-D-0924allenai/Molmo-7B-O-0924 等。 ✅︎ ✅︎ ✅︎
NVLM_D_Model NVLM-D 1.0 T + I+ nvidia/NVLM-D-72B 等。 ✅︎ ✅︎
Ovis Ovis2, Ovis1.6 T + I+ AIDC-AI/Ovis2-1BAIDC-AI/Ovis1.6-Llama3.2-3B 等。 ✅︎ ✅︎
PaliGemmaForConditionalGeneration PaliGemma, PaliGemma 2 T + IE google/paligemma-3b-pt-224google/paligemma-3b-mix-224google/paligemma2-3b-ft-docci-448 等。 ✅︎ ⚠️
Phi3VForCausalLM Phi-3-Vision, Phi-3.5-Vision T + IE+ microsoft/Phi-3-vision-128k-instructmicrosoft/Phi-3.5-vision-instruct 等。 ✅︎ ✅︎
Phi4MMForCausalLM Phi-4-多模态 T + I+ / T + A+ / I+ + A+ microsoft/Phi-4-multimodal-instruct 等。 ✅︎ ✅︎ ✅︎
PixtralForConditionalGeneration Pixtral T + I+ mistralai/Mistral-Small-3.1-24B-Instruct-2503mistral-community/pixtral-12b 等。 ✅︎ ✅︎
QwenVLForConditionalGeneration^ Qwen-VL T + IE+ Qwen/Qwen-VLQwen/Qwen-VL-Chat 等。 ✅︎ ✅︎ ✅︎
Qwen2AudioForConditionalGeneration Qwen2-音频 T + A+ Qwen/Qwen2-Audio-7B-Instruct ✅︎ ✅︎
Qwen2VLForConditionalGeneration QVQ, Qwen2-VL T + IE+ + VE+ Qwen/QVQ-72B-PreviewQwen/Qwen2-VL-7B-InstructQwen/Qwen2-VL-72B-Instruct 等。 ✅︎ ✅︎ ✅︎
Qwen2_5_VLForConditionalGeneration Qwen2.5-VL T + IE+ + VE+ Qwen/Qwen2.5-VL-3B-InstructQwen/Qwen2.5-VL-72B-Instruct 等。 ✅︎ ✅︎ ✅︎
Qwen2_5OmniThinkerForConditionalGeneration Qwen2.5-Omni T + IE+ + VE+ + A+ Qwen/Qwen2.5-Omni-7B ✅︎ ✅︎*
SkyworkR1VChatModel Skywork-R1V-38B T + I Skywork/Skywork-R1V-38B ✅︎ ✅︎
SmolVLMForConditionalGeneration SmolVLM2 T + I SmolVLM2-2.2B-Instruct ✅︎ ✅︎

^ 您需要通过 --hf-overrides 设置架构名称以匹配 vLLM 中的名称。
    • 例如,使用 DeepSeek-VL2 系列模型
      --hf-overrides '{"architectures": ["DeepseekVLV2ForCausalLM"]}'
E 可以为此模态输入预计算的嵌入。
+ 对于此模态,每个文本 prompt 可以输入多个项目。

警告

V0 和 V1 都支持 Gemma3ForConditionalGeneration 用于纯文本输入。但是,它们处理文本 + 图像输入的方式存在差异

V0 正确实现了模型的注意力模式: - 使用同一图像对应的图像 token 之间的双向注意力 - 对其他 token 使用因果注意力 - 通过(朴素的)PyTorch SDPA 和掩码张量实现 - 注意:对于包含图像的长 prompt 可能会占用大量内存

V1 目前使用简化的注意力模式: - 对所有 token(包括图像 token)使用因果注意力 - 生成合理输出,但不匹配原始模型对文本 + 图像输入的注意力模式,尤其是在 {"do_pan_and_scan": true} 时 - 将在未来更新以支持正确行为

存在此限制是因为 vLLM 的注意力后端尚不支持模型的混合注意力模式(图像使用双向注意力,否则使用因果注意力)。

注意

目前只有使用 Qwen2.5 文本主干的 InternVLChatModelOpenGVLab/InternVL3-2BOpenGVLab/InternVL2.5-1B 等)支持视频输入。

注意

一旦我们支持头大小 80,h2oai/h2ovl-mississippi-2b 将在 V1 中可用。

注意

要使用 TIGER-Lab/Mantis-8B-siglip-llama3,在运行 vLLM 时必须传递 --hf_overrides '{"architectures": ["MantisForConditionalGeneration"]}'

警告

AllenAI/Molmo-7B-D-0924 的输出质量(特别是在目标定位任务中)在最近的更新中有所下降。

为了获得最佳结果,我们建议使用以下依赖版本(在 A10 和 L40 上测试通过)

# Core vLLM-compatible dependencies with Molmo accuracy setup (tested on L40)
torch==2.5.1
torchvision==0.20.1
transformers==4.48.1
tokenizers==0.21.0
tiktoken==0.7.0
vllm==0.7.0

# Optional but recommended for improved performance and stability
triton==3.1.0
xformers==0.0.28.post3
uvloop==0.21.0
protobuf==5.29.3
openai==1.60.2
opencv-python-headless==4.11.0.86
pillow==10.4.0

# Installed FlashAttention (for float16 only)
flash-attn>=2.5.6  # Not used in float32, but should be documented

注意: 请确保您了解使用过时软件包的安全隐患。

注意

官方的 openbmb/MiniCPM-V-2 暂时无法工作,因此我们目前需要使用一个 fork (HwwwH/MiniCPM-V-2)。更多详细信息,请参见: Pull Request #4087

警告

我们的 PaliGemma 实现与 Gemma 3(参见上文)在 V0 和 V1 中存在相同的问题。

注意

要使用 Qwen2.5-Omni,您必须通过 pip install git+https://github.com/huggingface/transformers.git 从源代码安装 Hugging Face Transformers 库。

目前在 V0 中支持从视频预处理中读取音频(但 V1 不支持),因为 V1 尚不支持模态重叠。--mm-processor-kwargs '{"use_audio_in_video": true}'

池化模型

请参阅此页面获取有关如何使用池化模型的更多信息。

警告

由于某些模型架构同时支持生成和池化任务,您应该显式指定任务类型,以确保模型以池化模式而不是生成模式使用。

文本嵌入

使用 --task embed 指定。

通过传递 --task embed 参数,任何文本生成模型都可以转换为嵌入模型。

注意

为了获得最佳结果,您应该使用专门为此目的训练的池化模型。

下表列出了在 vLLM 中经过测试的模型。

架构 模型 输入 示例 HF 模型 LoRA PP
LlavaNextForConditionalGeneration 基于 LLaVA-NeXT T / I royokong/e5-v
Phi3VForCausalLM 基于 Phi-3-Vision T + I TIGER-Lab/VLM2Vec-Full 🚧 ✅︎

转录

使用 --task transcription 指定。

专门为自动语音识别训练的 Speech2Text 模型。

架构 模型 示例 HF 模型 LoRA PP

模型支持策略

在 vLLM,我们致力于促进第三方模型在我们的生态系统中的集成和支持。我们的方法旨在平衡对鲁棒性的需求和支持各种模型的实际限制。以下是我们管理第三方模型支持的方式

  1. 社区驱动支持:我们鼓励社区贡献以添加新模型。当用户请求支持新模型时,我们欢迎社区提交拉取请求(PRs)。这些贡献主要根据它们生成输出的合理性进行评估,而不是与现有实现(例如 transformers 中的实现)的严格一致性。征集贡献:我们非常欢迎来自模型供应商的 PRs!

  2. 尽力而为的一致性:虽然我们旨在保持 vLLM 中实现的模型与 transformers 等其他框架之间的一致性水平,但完全一致并不总是可行的。加速技术和低精度计算的使用等因素可能会引入差异。我们的承诺是确保实现的模型功能正常并产生合理的结果。

    提示

    比较 Hugging Face Transformers 中 model.generate 的输出与 vLLM 中 llm.generate 的输出时,请注意前者读取模型的生成配置文件(即 generation_config.json)并应用生成默认参数,而后者仅使用传递给函数的参数。比较输出时请确保所有采样参数完全一致。

  3. 问题解决和模型更新:我们鼓励用户报告在使用第三方模型时遇到的任何 bug 或问题。建议的修复应通过 PRs 提交,并清楚解释问题和建议解决方案的理由。如果某个模型的修复影响到另一个模型,我们依靠社区来指出和解决这些跨模型依赖关系。注意:对于 bugfix PRs,通知原始作者并征求他们的反馈是一种良好的礼仪。

  4. 监控和更新:对特定模型感兴趣的用户应监控这些模型的提交历史记录(例如,通过跟踪 main/vllm/model_executor/models 目录中的更改)。这种积极主动的方法有助于用户了解可能影响他们使用的模型的更新和更改。

  5. 选择性关注:我们的资源主要用于用户兴趣和影响较大的模型。使用频率较低的模型可能会受到较少关注,我们依靠社区在其维护和改进方面发挥更积极的作用。

通过这种方法,vLLM 营造了一个协作环境,核心开发团队和更广泛的社区共同为我们生态系统中支持的第三方模型的鲁棒性和多样性做出贡献。

请注意,作为推理引擎,vLLM 不会引入新模型。因此,vLLM 支持的所有模型在这方面都是第三方模型。

我们对模型进行以下级别的测试

  1. 严格一致性:在贪婪解码下,我们将模型的输出与 HuggingFace Transformers 库中模型的输出进行比较。这是最严格的测试。请参考模型测试查看通过此测试的模型。
  2. 输出合理性:我们通过衡量输出的困惑度并检查是否存在任何明显错误来检查模型的输出是否合理且连贯。这是一个不太严格的测试。
  3. 运行时功能:我们检查模型是否可以加载并无错误地运行。这是最不严格的测试。请参考 功能测试 示例查看通过此测试的模型。
  4. 社区反馈:我们依靠社区提供关于模型的反馈。如果模型损坏或未按预期工作,我们鼓励用户提交 issue 进行报告或打开 pull request 进行修复。其余模型属于此类别。