| 1 | # SPDX-License-Identifier: Apache-2.0 |
| 2 | # SPDX-FileCopyrightText: Copyright contributors to the vLLM project |
| 3 | """Whenever you add an architecture to this page, please also update |
| 4 | `tests/models/registry.py` with example HuggingFace models for it. |
| 5 | """ |
| 6 | |
| 7 | import importlib |
| 8 | import importlib.util |
| 9 | import json |
| 10 | import os |
| 11 | import pickle |
| 12 | import subprocess |
| 13 | import sys |
| 14 | import tempfile |
| 15 | from abc import ABC, abstractmethod |
| 16 | from collections.abc import Callable, Set |
| 17 | from dataclasses import asdict, dataclass, field |
| 18 | from functools import lru_cache |
| 19 | from pathlib import Path |
| 20 | from typing import TYPE_CHECKING, Any, TypeVar |
| 21 | |
| 22 | import torch.nn as nn |
| 23 | import transformers |
| 24 | |
| 25 | from vllm import envs |
| 26 | from vllm.config import ( |
| 27 | ModelConfig, |
| 28 | iter_architecture_defaults, |
| 29 | try_match_architecture_defaults, |
| 30 | ) |
| 31 | from vllm.logger import init_logger |
| 32 | from vllm.logging_utils import logtime |
| 33 | from vllm.tasks import ScoreType |
| 34 | from vllm.transformers_utils.dynamic_module import try_get_class_from_dynamic_module |
| 35 | from vllm.utils.hashing import safe_hash |
| 36 | |
| 37 | if TYPE_CHECKING: |
| 38 | from vllm.config.model import AttnTypeStr |
| 39 | from vllm.config.pooler import SequencePoolingType, TokenPoolingType |
| 40 | else: |
| 41 | AttnTypeStr = Any |
| 42 | SequencePoolingType = Any |
| 43 | TokenPoolingType = Any |
| 44 | |
| 45 | |
| 46 | from .interfaces import ( |
| 47 | has_inner_state, |
| 48 | has_noops, |
| 49 | is_attention_free, |
| 50 | is_hybrid, |
| 51 | requires_raw_input_tokens, |
| 52 | supports_mamba_prefix_caching, |
| 53 | supports_multimodal, |
| 54 | supports_multimodal_encoder_tp_data, |
| 55 | supports_multimodal_raw_input_only, |
| 56 | supports_pp, |
| 57 | supports_replayssm, |
| 58 | supports_transcription, |
| 59 | ) |
| 60 | from .interfaces_base import ( |
| 61 | get_attn_type, |
| 62 | get_default_seq_pooling_type, |
| 63 | get_default_tok_pooling_type, |
| 64 | get_score_type, |
| 65 | is_pooling_model, |
| 66 | is_text_generation_model, |
| 67 | ) |
| 68 | |
| 69 | logger = init_logger(__name__) |
| 70 | |
| 71 | _TEXT_GENERATION_MODELS = { |
| 72 | # [Decoder-only] |
| 73 | "AfmoeForCausalLM": ("afmoe", "AfmoeForCausalLM"), |
| 74 | "ApertusForCausalLM": ("apertus", "ApertusForCausalLM"), |
| 75 | "AXK1ForCausalLM": ("AXK1", "AXK1ForCausalLM"), |
| 76 | "BailingMoeForCausalLM": ("bailing_moe", "BailingMoeForCausalLM"), |
| 77 | "BailingMoeV2ForCausalLM": ("bailing_moe", "BailingMoeV2ForCausalLM"), |
| 78 | "BailingMoeV2_5ForCausalLM": ("bailing_moe_linear", "BailingMoeV25ForCausalLM"), |
| 79 | "BailingMoeV3ForCausalLM": ("bailing_moe_v3", "BailingMoeV3ForCausalLM"), |
| 80 | "BloomForCausalLM": ("bloom", "BloomForCausalLM"), |
| 81 | "ChatGLMModel": ("chatglm", "ChatGLMForCausalLM"), |
| 82 | "ChatGLMForConditionalGeneration": ("chatglm", "ChatGLMForCausalLM"), |
| 83 | "CohereForCausalLM": ("commandr", "CohereForCausalLM"), |
| 84 | "Cohere2ForCausalLM": ("commandr", "CohereForCausalLM"), |
| 85 | "Cohere2MoeForCausalLM": ("cohere2_moe", "Cohere2MoeForCausalLM"), |
| 86 | "DbrxForCausalLM": ("dbrx", "DbrxForCausalLM"), |
| 87 | "DeciLMForCausalLM": ("nemotron_nas", "DeciLMForCausalLM"), |
| 88 | "DeepseekForCausalLM": ("deepseek_v2", "DeepseekForCausalLM"), |
| 89 | "DeepseekV2ForCausalLM": ("deepseek_v2", "DeepseekV2ForCausalLM"), |
| 90 | "DeepseekV3ForCausalLM": ("deepseek_v2", "DeepseekV3ForCausalLM"), |
| 91 | "DeepseekV32ForCausalLM": ( |
| 92 | "vllm.models.deepseek_v32", |
| 93 | "DeepseekV32ForCausalLM", |
| 94 | ), |
| 95 | "DeepseekV4ForCausalLM": ("vllm.models.deepseek_v4", "DeepseekV4ForCausalLM"), |
| 96 | "Ernie4_5ForCausalLM": ("ernie45", "Ernie4_5ForCausalLM"), |
| 97 | "Ernie4_5_MoeForCausalLM": ("ernie45_moe", "Ernie4_5_MoeForCausalLM"), |
| 98 | "ExaoneForCausalLM": ("exaone", "ExaoneForCausalLM"), |
| 99 | "Exaone4ForCausalLM": ("exaone4", "Exaone4ForCausalLM"), |
| 100 | "ExaoneMoeForCausalLM": ("exaone_moe", "ExaoneMoeForCausalLM"), |
| 101 | "FalconForCausalLM": ("falcon", "FalconForCausalLM"), |
| 102 | "FalconMambaForCausalLM": ("mamba", "MambaForCausalLM"), |
| 103 | "FalconH1ForCausalLM": ("falcon_h1", "FalconH1ForCausalLM"), |
| 104 | "GemmaForCausalLM": ("gemma", "GemmaForCausalLM"), |
| 105 | "Gemma2ForCausalLM": ("gemma2", "Gemma2ForCausalLM"), |
| 106 | "Gemma3ForCausalLM": ("gemma3", "Gemma3ForCausalLM"), |
| 107 | "Rnj1ForCausalLM": ("rnj1", "Rnj1ForCausalLM"), |
| 108 | "Gemma3nForCausalLM": ("gemma3n", "Gemma3nForCausalLM"), |
| 109 | "Gemma4ForCausalLM": ("gemma4", "Gemma4ForCausalLM"), |
| 110 | "Qwen3NextForCausalLM": ("qwen3_next", "Qwen3NextForCausalLM"), |
| 111 | "Qwen4ExpForCausalLM": ( |
| 112 | "vllm.models.qwen4_exp", |
| 113 | "Qwen4ExpForCausalLM", |
| 114 | ), |
| 115 | "Glm4ForCausalLM": ("glm4", "Glm4ForCausalLM"), |
| 116 | "Glm4MoeForCausalLM": ("glm4_moe", "Glm4MoeForCausalLM"), |
| 117 | "Glm4MoeLiteForCausalLM": ("glm4_moe_lite", "Glm4MoeLiteForCausalLM"), |
| 118 | "GlmMoeDsaForCausalLM": ("vllm.models.deepseek_v32", "GlmMoeDsaForCausalLM"), |
| 119 | "Glm5NextForCausalLM": ("vllm.models.glm5next", "Glm5NextForCausalLM"), |
| 120 | "GptOssForCausalLM": ("gpt_oss", "GptOssForCausalLM"), |
| 121 | "GPT2LMHeadModel": ("gpt2", "GPT2LMHeadModel"), |
| 122 | "GPTJForCausalLM": ("gpt_j", "GPTJForCausalLM"), |
| 123 | "GraniteForCausalLM": ("granite", "GraniteForCausalLM"), |
| 124 | "GraniteMoeForCausalLM": ("granitemoe", "GraniteMoeForCausalLM"), |
| 125 | "GraniteMoeHybridForCausalLM": ("granitemoehybrid", "GraniteMoeHybridForCausalLM"), |
| 126 | "GraniteMoeSharedForCausalLM": ("granitemoeshared", "GraniteMoeSharedForCausalLM"), |
| 127 | "GraniteMoeSWAForCausalLM": ("granitemoeshared", "GraniteMoeSharedForCausalLM"), |
| 128 | "GraniteSWAForCausalLM": ("granite", "GraniteForCausalLM"), |
| 129 | "HrmTextForCausalLM": ("hrm_text", "HrmTextForCausalLM"), |
| 130 | "HYV3ForCausalLM": ("hy_v3", "HYV3ForCausalLM"), |
| 131 | "HYV4ForCausalLM": ("vllm.models.hy_v4", "HYV4ForCausalLM"), |
| 132 | "HCXVisionV2ForCausalLM": ("hyperclovax_vision_v2", "HCXVisionV2ForCausalLM"), |
| 133 | "HyperCLOVAXForCausalLM": ("hyperclovax", "HyperCLOVAXForCausalLM"), |
| 134 | "InternLM2ForCausalLM": ("internlm2", "InternLM2ForCausalLM"), |
| 135 | "InternLM3ForCausalLM": ("llama", "LlamaForCausalLM"), |
| 136 | "IQuestCoderForCausalLM": ("llama", "LlamaForCausalLM"), |
| 137 | "IQuestLoopCoderForCausalLM": ("iquest_loopcoder", "IQuestLoopCoderForCausalLM"), |
| 138 | "JambaForCausalLM": ("jamba", "JambaForCausalLM"), |
| 139 | "K2HorizonForCausalLM": ("k2_horizon", "K2HorizonForCausalLM"), |
| 140 | "KimiLinearForCausalLM": ( |
| 141 | "vllm.models.kimi_k3", |
| 142 | "KimiLinearForCausalLM", |
| 143 | ), |
| 144 | "Lfm2ForCausalLM": ("lfm2", "Lfm2ForCausalLM"), |
| 145 | "Lfm2MoeForCausalLM": ("lfm2_moe", "Lfm2MoeForCausalLM"), |
| 146 | "LagunaForCausalLM": ("laguna", "LagunaForCausalLM"), |
| 147 | "LlamaForCausalLM": ("llama", "LlamaForCausalLM"), |
| 148 | "Llama4ForCausalLM": ("llama4", "Llama4ForCausalLM"), |
| 149 | # For decapoda-research/llama-* |
| 150 | "LLaMAForCausalLM": ("llama", "LlamaForCausalLM"), |
| 151 | "LongcatFlashForCausalLM": ("longcat_flash", "LongcatFlashForCausalLM"), |
| 152 | "LongcatFlashNgramForCausalLM": ( |
| 153 | "longcat_flash_ngram", |
| 154 | "LongcatFlashNgramForCausalLM", |
| 155 | ), |
| 156 | "MambaForCausalLM": ("mamba", "MambaForCausalLM"), |
| 157 | "Mamba2ForCausalLM": ("mamba2", "Mamba2ForCausalLM"), |
| 158 | "MiniCPMForCausalLM": ("minicpm", "MiniCPMForCausalLM"), |
| 159 | "MiniCPM3ForCausalLM": ("minicpm3", "MiniCPM3ForCausalLM"), |
| 160 | "MiniMaxM2ForCausalLM": ("minimax_m2", "MiniMaxM2ForCausalLM"), |
| 161 | "MiniMaxM3SparseForCausalLM": ( |
| 162 | "vllm.models.minimax_m3", |
| 163 | "MiniMaxM3SparseForCausalLM", |
| 164 | ), |
| 165 | "InklingForCausalLM": ("vllm.models.inkling", "InklingForCausalLM"), |
| 166 | "InklingForConditionalGeneration": ( |
| 167 | "vllm.models.inkling", |
| 168 | "InklingForConditionalGeneration", |
| 169 | ), |
| 170 | "Ministral3ForCausalLM": ("mistral", "MistralForCausalLM"), |
| 171 | "MistralForCausalLM": ("mistral", "MistralForCausalLM"), |
| 172 | "MistralLarge3ForCausalLM": ("mistral_large_3", "MistralLarge3ForCausalLM"), |
| 173 | "MixtralForCausalLM": ("mixtral", "MixtralForCausalLM"), |
| 174 | "MiMoForCausalLM": ("mimo", "MiMoForCausalLM"), |
| 175 | "MiMoV2FlashForCausalLM": ("mimo_v2", "MiMoV2FlashForCausalLM"), |
| 176 | "MiMoV2ForCausalLM": ("mimo_v2", "MiMoV2ForCausalLM"), |
| 177 | "NemotronForCausalLM": ("nemotron", "NemotronForCausalLM"), |
| 178 | "NemotronHForCausalLM": ("nemotron_h", "NemotronHForCausalLM"), |
| 179 | "NemotronHPuzzleForCausalLM": ("nemotron_h", "NemotronHForCausalLM"), |
| 180 | "MuseGlimmerForCausalLM": ("muse_glimmer", "MuseGlimmerForCausalLM"), |
| 181 | "OlmoHybridForCausalLM": ("olmo_hybrid", "OlmoHybridForCausalLM"), |
| 182 | "OlmoeForCausalLM": ("olmoe", "OlmoeForCausalLM"), |
| 183 | "OPTForCausalLM": ("opt", "OPTForCausalLM"), |
| 184 | "OrionForCausalLM": ("orion", "OrionForCausalLM"), |
| 185 | "PanguEmbeddedForCausalLM": ("openpangu", "PanguEmbeddedForCausalLM"), |
| 186 | "PanguProMoEV2ForCausalLM": ("openpangu", "PanguProMoEV2ForCausalLM"), |
| 187 | "PanguUltraMoEForCausalLM": ("openpangu", "PanguUltraMoEForCausalLM"), |
| 188 | "Param2MoEForCausalLM": ("param2moe", "Param2MoEForCausalLM"), |
| 189 | "Phi3ForCausalLM": ("phi3", "Phi3ForCausalLM"), |
| 190 | "PhiMoEForCausalLM": ("phimoe", "PhiMoEForCausalLM"), |
| 191 | "Plamo3ForCausalLM": ("plamo3", "Plamo3ForCausalLM"), |
| 192 | "Qwen2ForCausalLM": ("qwen2", "Qwen2ForCausalLM"), |
| 193 | "Qwen2MoeForCausalLM": ("qwen2_moe", "Qwen2MoeForCausalLM"), |
| 194 | "Qwen3ForCausalLM": ("qwen3", "Qwen3ForCausalLM"), |
| 195 | "Qwen3MoeForCausalLM": ("qwen3_moe", "Qwen3MoeForCausalLM"), |
| 196 | "Qwen3_5ForCausalLM": ("qwen3_5", "Qwen3_5ForCausalLM"), |
| 197 | "Qwen3_5MoeForCausalLM": ("qwen3_5", "Qwen3_5MoeForCausalLM"), |
| 198 | "SarvamMoEForCausalLM": ("sarvam", "SarvamMoEForCausalLM"), |
| 199 | "SarvamMLAForCausalLM": ("sarvam", "SarvamMLAForCausalLM"), |
| 200 | "Step1ForCausalLM": ("step1", "Step1ForCausalLM"), |
| 201 | "Step3TextForCausalLM": ("step3_text", "Step3TextForCausalLM"), |
| 202 | "Step3p5ForCausalLM": ("step3p5", "Step3p5ForCausalLM"), |
| 203 | "StableLmForCausalLM": ("stablelm", "StablelmForCausalLM"), |
| 204 | "SolarForCausalLM": ("solar", "SolarForCausalLM"), |
| 205 | "TeleChat2ForCausalLM": ("telechat2", "TeleChat2ForCausalLM"), |
| 206 | "TeleChat3ForCausalLM": ("llama", "LlamaForCausalLM"), |
| 207 | "TeleFLMForCausalLM": ("teleflm", "TeleFLMForCausalLM"), |
| 208 | "Zamba2ForCausalLM": ("zamba2", "Zamba2ForCausalLM"), |
| 209 | } |
| 210 | |
| 211 | _EMBEDDING_MODELS = { |
| 212 | # [Text-only] |
| 213 | "BertModel": ("bert", "BertEmbeddingModel"), |
| 214 | "BertForMaskedLM": ("bert", "BertForMaskedLM"), |
| 215 | "BertSpladeSparseEmbeddingModel": ("bert", "BertSpladeSparseEmbeddingModel"), |
| 216 | "BgeM3EmbeddingModel": ("roberta", "BgeM3EmbeddingModel"), |
| 217 | "DeciLMForCausalLM": ("nemotron_nas", "DeciLMForCausalLM"), |
| 218 | "DeepseekV3BidirectionalModel": ("deepseek_v2", "DeepseekV3ForCausalLM"), |
| 219 | "Gemma2Model": ("gemma2", "Gemma2ForCausalLM"), |
| 220 | "Gemma3TextModel": ("gemma3", "Gemma3Model"), |
| 221 | "GteModel": ("bert_with_rope", "SnowflakeGteNewModel"), |
| 222 | "GteNewModel": ("bert_with_rope", "GteNewModel"), |
| 223 | "JinaEmbeddingsV5Model": ("jina", "JinaEmbeddingsV5Model"), |
| 224 | "LlamaBidirectionalModel": ("llama", "LlamaBidirectionalModel"), |
| 225 | "LlamaModel": ("llama", "LlamaForCausalLM"), |
| 226 | **{ |
| 227 | # Multiple models share the same architecture, so we include them all |
| 228 | k: (mod, arch) |
| 229 | for k, (mod, arch) in _TEXT_GENERATION_MODELS.items() |
| 230 | if arch == "LlamaForCausalLM" |
| 231 | }, |
| 232 | "MistralModel": ("llama", "LlamaForCausalLM"), |
| 233 | "ModernBertModel": ("modernbert", "ModernBertModel"), |
| 234 | "NomicBertModel": ("bert_with_rope", "NomicBertModel"), |
| 235 | "Phi3ForCausalLM": ("phi3", "Phi3ForCausalLM"), |
| 236 | "Qwen2Model": ("qwen2", "Qwen2ForCausalLM"), |
| 237 | "Qwen2ForCausalLM": ("qwen2", "Qwen2ForCausalLM"), |
| 238 | "RobertaForMaskedLM": ("roberta", "RobertaEmbeddingModel"), |
| 239 | "RobertaModel": ("roberta", "RobertaEmbeddingModel"), |
| 240 | "TeleChat2ForCausalLM": ("telechat2", "TeleChat2ForCausalLM"), |
| 241 | "VoyageQwen3BidirectionalEmbedModel": ( |
| 242 | "voyage", |
| 243 | "VoyageQwen3BidirectionalEmbedModel", |
| 244 | ), |
| 245 | "XLMRobertaModel": ("roberta", "RobertaEmbeddingModel"), |
| 246 | # [Multimodal] |
| 247 | "CLIPModel": ("clip", "CLIPEmbeddingModel"), |
| 248 | "ColPaliForRetrieval": ("colpali", "ColPaliModel"), |
| 249 | "LlamaNemotronVLModel": ("nemotron_vl", "LlamaNemotronVLForEmbedding"), |
| 250 | "LlavaNextForConditionalGeneration": ( |
| 251 | "llava_next", |
| 252 | "LlavaNextForConditionalGeneration", |
| 253 | ), |
| 254 | "Phi3VForCausalLM": ("phi3v", "Phi3VForCausalLM"), |
| 255 | "Qwen2VLForConditionalGeneration": ("qwen2_vl", "Qwen2VLForConditionalGeneration"), |
| 256 | "SiglipModel": ("siglip", "SiglipEmbeddingModel"), |
| 257 | # Technically Terratorch models work on images, both in |
| 258 | # input and output. I am adding it here because it piggy-backs on embedding |
| 259 | # models for the time being. |
| 260 | "Terratorch": ("terratorch", "Terratorch"), |
| 261 | } |
| 262 | |
| 263 | _LATE_INTERACTION_MODELS = { |
| 264 | # [Text-only] |
| 265 | "HF_ColBERT": ("colbert", "ColBERTModel"), |
| 266 | "ColBERTModernBertModel": ("colbert", "ColBERTModernBertModel"), |
| 267 | "ColBERTJinaRobertaModel": ("colbert", "ColBERTJinaRobertaModel"), |
| 268 | "ColBERTLfm2Model": ("colbert", "ColBERTLfm2Model"), |
| 269 | "JinaForRanking": ("jina", "JinaForRanking"), |
| 270 | # [Multimodal] |
| 271 | "ColModernVBertForRetrieval": ("colmodernvbert", "ColModernVBertForRetrieval"), |
| 272 | "ColPaliForRetrieval": ("colpali", "ColPaliModel"), |
| 273 | "ColQwen3": ("colqwen3", "ColQwen3Model"), |
| 274 | "OpsColQwen3Model": ("colqwen3", "ColQwen3Model"), |
| 275 | "ColQwen3_5": ("colqwen3_5", "ColQwen3_5Model"), |
| 276 | "Qwen3VLNemotronEmbedModel": ("colqwen3", "ColQwen3Model"), |
| 277 | } |
| 278 | |
| 279 | _REWARD_MODELS = { |
| 280 | "InternLM2ForRewardModel": ("internlm2", "InternLM2ForRewardModel"), |
| 281 | "Qwen2ForRewardModel": ("qwen2_rm", "Qwen2ForRewardModel"), |
| 282 | "Qwen2ForProcessRewardModel": ("qwen2_rm", "Qwen2ForProcessRewardModel"), |
| 283 | } |
| 284 | |
| 285 | _TOKEN_CLASSIFICATION_MODELS = { |
| 286 | "BertForTokenClassification": ("bert", "BertForTokenClassification"), |
| 287 | "ModernBertForTokenClassification": ( |
| 288 | "modernbert", |
| 289 | "ModernBertForTokenClassification", |
| 290 | ), |
| 291 | "OpenAIPrivacyFilterForTokenClassification": ( |
| 292 | "openai_privacy_filter", |
| 293 | "OpenAIPrivacyFilterForTokenClassification", |
| 294 | ), |
| 295 | "Qwen3ASRForcedAlignerForTokenClassification": ( |
| 296 | "qwen3_asr_forced_aligner", |
| 297 | "Qwen3ASRForcedAlignerForTokenClassification", |
| 298 | ), |
| 299 | "RobertaForTokenClassification": ("roberta", "RobertaForTokenClassification"), |
| 300 | "XLMRobertaForTokenClassification": ( |
| 301 | "roberta", |
| 302 | "RobertaForTokenClassification", |
| 303 | ), |
| 304 | } |
| 305 | |
| 306 | _SEQUENCE_CLASSIFICATION_MODELS = { |
| 307 | "BertForSequenceClassification": ("bert", "BertForSequenceClassification"), |
| 308 | "GPT2ForSequenceClassification": ("gpt2", "GPT2ForSequenceClassification"), |
| 309 | "GteNewForSequenceClassification": ( |
| 310 | "bert_with_rope", |
| 311 | "GteNewForSequenceClassification", |
| 312 | ), |
| 313 | "JambaForSequenceClassification": ("jamba", "JambaForSequenceClassification"), |
| 314 | "LlamaBidirectionalForSequenceClassification": ( |
| 315 | "llama", |
| 316 | "LlamaBidirectionalForSequenceClassification", |
| 317 | ), |
| 318 | "ModernBertForSequenceClassification": ( |
| 319 | "modernbert", |
| 320 | "ModernBertForSequenceClassification", |
| 321 | ), |
| 322 | "RobertaForSequenceClassification": ("roberta", "RobertaForSequenceClassification"), |
| 323 | "XLMRobertaForSequenceClassification": ( |
| 324 | "roberta", |
| 325 | "RobertaForSequenceClassification", |
| 326 | ), |
| 327 | # [Multimodal] |
| 328 | "JinaVLForRanking": ("jina_vl", "JinaVLForSequenceClassification"), |
| 329 | "LlamaNemotronVLForSequenceClassification": ( |
| 330 | "nemotron_vl", |
| 331 | "LlamaNemotronVLForSequenceClassification", |
| 332 | ), |
| 333 | } |
| 334 | |
| 335 | _MULTIMODAL_MODELS = { |
| 336 | # [Decoder-only] |
| 337 | "AriaForConditionalGeneration": ("aria", "AriaForConditionalGeneration"), |
| 338 | "AudioFlamingo3ForConditionalGeneration": ( |
| 339 | "audioflamingo3", |
| 340 | "AudioFlamingo3ForConditionalGeneration", |
| 341 | ), |
| 342 | "BagelForConditionalGeneration": ("bagel", "BagelForConditionalGeneration"), |
| 343 | "BailingMoeV3VLForConditionalGeneration": ( |
| 344 | "bailing_moe_v3_vl", |
| 345 | "BailingMoeV3VLForConditionalGeneration", |
| 346 | ), |
| 347 | "BeeForConditionalGeneration": ("bee", "BeeForConditionalGeneration"), |
| 348 | "Blip2ForConditionalGeneration": ("blip2", "Blip2ForConditionalGeneration"), |
| 349 | "Cohere2VisionForConditionalGeneration": ( |
| 350 | "cohere2_vision", |
| 351 | "Cohere2VisionForConditionalGeneration", |
| 352 | ), |
| 353 | "CohereCompassForConditionalGeneration": ( |
| 354 | "cohere_compass", |
| 355 | "CohereCompassForConditionalGeneration", |
| 356 | ), |
| 357 | "Cosmos3ForConditionalGeneration": ("cosmos3", "Cosmos3ForConditionalGeneration"), |
| 358 | "Cosmos3EdgeForConditionalGeneration": ( |
| 359 | "cosmos3_edge", |
| 360 | "Cosmos3EdgeForConditionalGeneration", |
| 361 | ), |
| 362 | "DeepseekVLV2ForCausalLM": ("deepseek_vl2", "DeepseekVLV2ForCausalLM"), |
| 363 | "DeepseekOCRForCausalLM": ("deepseek_ocr", "DeepseekOCRForCausalLM"), |
| 364 | "DeepseekOCR2ForCausalLM": ("deepseek_ocr2", "DeepseekOCR2ForCausalLM"), |
| 365 | "DeepseekV4ForConditionalGeneration": ( |
| 366 | "vllm.models.deepseek_v4", |
| 367 | "DeepseekV4ForConditionalGeneration", |
| 368 | ), |
| 369 | "DeepseekV41ForCausalLM": ( |
| 370 | "vllm.models.deepseek_v41", |
| 371 | "DeepseekV41ForCausalLM", |
| 372 | ), |
| 373 | "Dots3NoteForCausalLM": ( |
| 374 | "vllm.models.dots3_note", |
| 375 | "Dots3NoteForCausalLM", |
| 376 | ), |
| 377 | "UnlimitedOCRForCausalLM": ("unlimited_ocr", "UnlimitedOCRForCausalLM"), |
| 378 | "DotsOCRForCausalLM": ("dots_ocr", "DotsOCRForCausalLM"), |
| 379 | "Eagle2_5_VLForConditionalGeneration": ( |
| 380 | "eagle2_5_vl", |
| 381 | "Eagle2_5_VLForConditionalGeneration", |
| 382 | ), |
| 383 | "Ernie4_5_VLMoeForConditionalGeneration": ( |
| 384 | "ernie45_vl", |
| 385 | "Ernie4_5_VLMoeForConditionalGeneration", |
| 386 | ), |
| 387 | "Exaone4_5_ForConditionalGeneration": ( |
| 388 | "exaone4_5", |
| 389 | "Exaone4_5_ForConditionalGeneration", |
| 390 | ), # noqa: E501 |
| 391 | "FireRedASR2ForConditionalGeneration": ( |
| 392 | "fireredasr2", |
| 393 | "FireRedASR2ForConditionalGeneration", |
| 394 | ), |
| 395 | "FunASRForConditionalGeneration": ("funasr", "FunASRForConditionalGeneration"), |
| 396 | "FunAudioChatForConditionalGeneration": ( |
| 397 | "funaudiochat", |
| 398 | "FunAudioChatForConditionalGeneration", |
| 399 | ), |
| 400 | "Gemma3ForConditionalGeneration": ("gemma3_mm", "Gemma3ForConditionalGeneration"), |
| 401 | "Gemma3nForConditionalGeneration": ( |
| 402 | "gemma3n_mm", |
| 403 | "Gemma3nForConditionalGeneration", |
| 404 | ), |
| 405 | "DiffusionGemmaForBlockDiffusion": ( |
| 406 | "diffusion_gemma", |
| 407 | "DiffusionGemmaForConditionalGeneration", |
| 408 | ), |
| 409 | "Gemma4ForConditionalGeneration": ("gemma4_mm", "Gemma4ForConditionalGeneration"), |
| 410 | "Gemma4UnifiedForConditionalGeneration": ( |
| 411 | "gemma4_unified", |
| 412 | "Gemma4UnifiedForConditionalGeneration", |
| 413 | ), |
| 414 | "GlmAsrForConditionalGeneration": ("glmasr", "GlmAsrForConditionalGeneration"), |
| 415 | "GLM4VForCausalLM": ("glm4v", "GLM4VForCausalLM"), |
| 416 | "Glm4vForConditionalGeneration": ("glm4_1v", "Glm4vForConditionalGeneration"), |
| 417 | "Glm4vMoeForConditionalGeneration": ("glm4_1v", "Glm4vMoeForConditionalGeneration"), |
| 418 | "GlmOcrForConditionalGeneration": ("glm_ocr", "GlmOcrForConditionalGeneration"), |
| 419 | "Glm5NextForConditionalGeneration": ( |
| 420 | "vllm.models.glm5next", |
| 421 | "Glm5NextForConditionalGeneration", |
| 422 | ), |
| 423 | "GraniteSpeechForConditionalGeneration": ( |
| 424 | "granite_speech", |
| 425 | "GraniteSpeechForConditionalGeneration", |
| 426 | ), |
| 427 | "GraniteSpeechPlusForConditionalGeneration": ( |
| 428 | "granite_speech_plus", |
| 429 | "GraniteSpeechPlusForConditionalGeneration", |
| 430 | ), |
| 431 | "Granite4VisionForConditionalGeneration": ( |
| 432 | "granite4_vision", |
| 433 | "Granite4VisionForConditionalGeneration", |
| 434 | ), |
| 435 | "H2OVLChatModel": ("h2ovl", "H2OVLChatModel"), |
| 436 | "InternVLChatModel": ("internvl", "InternVLChatModel"), |
| 437 | "InternS1ForConditionalGeneration": ( |
| 438 | "interns1", |
| 439 | "InternS1ForConditionalGeneration", |
| 440 | ), |
| 441 | "InternVLForConditionalGeneration": ( |
| 442 | "interns1", |
| 443 | "InternS1ForConditionalGeneration", |
| 444 | ), |
| 445 | "InternS1ProForConditionalGeneration": ( |
| 446 | "interns1_pro", |
| 447 | "InternS1ProForConditionalGeneration", |
| 448 | ), |
| 449 | "InternS2MobiusForConditionalGeneration": ( |
| 450 | "interns2_mobius", |
| 451 | "InternS2MobiusForConditionalGeneration", |
| 452 | ), |
| 453 | "InternS2PreviewForConditionalGeneration": ( |
| 454 | "interns2_preview", |
| 455 | "InternS2PreviewForConditionalGeneration", |
| 456 | ), |
| 457 | "Idefics3ForConditionalGeneration": ( |
| 458 | "idefics3", |
| 459 | "Idefics3ForConditionalGeneration", |
| 460 | ), |
| 461 | "IsaacForConditionalGeneration": ("isaac", "IsaacForConditionalGeneration"), |
| 462 | "KananaVForConditionalGeneration": ("kanana_v", "KananaVForConditionalGeneration"), |
| 463 | "KeyeForConditionalGeneration": ("keye", "KeyeForConditionalGeneration"), |
| 464 | "KeyeVL1_5ForConditionalGeneration": ( |
| 465 | "keye_vl1_5", |
| 466 | "KeyeVL1_5ForConditionalGeneration", |
| 467 | ), |
| 468 | "KimiVLForConditionalGeneration": ("kimi_vl", "KimiVLForConditionalGeneration"), |
| 469 | "KimiK25ForConditionalGeneration": ("kimi_k25", "KimiK25ForConditionalGeneration"), |
| 470 | "KimiK3ForConditionalGeneration": ( |
| 471 | "vllm.models.kimi_k3", |
| 472 | "KimiK3ForConditionalGeneration", |
| 473 | ), |
| 474 | "MoonshotKimiaForCausalLM": ("kimi_audio", "KimiAudioForConditionalGeneration"), |
| 475 | "MossTranscribeDiarizeForConditionalGeneration": ( |
| 476 | "moss_transcribe_diarize", |
| 477 | "MossTranscribeDiarizeForConditionalGeneration", |
| 478 | ), |
| 479 | "LightOnOCRForConditionalGeneration": ( |
| 480 | "lightonocr", |
| 481 | "LightOnOCRForConditionalGeneration", |
| 482 | ), |
| 483 | "Lfm2VlForConditionalGeneration": ("lfm2_vl", "Lfm2VLForConditionalGeneration"), |
| 484 | "Llama4ForConditionalGeneration": ("mllama4", "Llama4ForConditionalGeneration"), |
| 485 | "Llama_Nemotron_Nano_VL": ("nemotron_vl", "LlamaNemotronVLChatModel"), |
| 486 | "LlavaForConditionalGeneration": ("llava", "LlavaForConditionalGeneration"), |
| 487 | "LlavaNextForConditionalGeneration": ( |
| 488 | "llava_next", |
| 489 | "LlavaNextForConditionalGeneration", |
| 490 | ), |
| 491 | "LlavaNextVideoForConditionalGeneration": ( |
| 492 | "llava_next_video", |
| 493 | "LlavaNextVideoForConditionalGeneration", |
| 494 | ), |
| 495 | "LlavaOnevisionForConditionalGeneration": ( |
| 496 | "llava_onevision", |
| 497 | "LlavaOnevisionForConditionalGeneration", |
| 498 | ), |
| 499 | "LlavaOnevision2ForConditionalGeneration": ( |
| 500 | "llava_onevision2", |
| 501 | "LlavaOnevision2ForConditionalGeneration", |
| 502 | ), |
| 503 | "MiDashengLMModel": ("midashenglm", "MiDashengLMModel"), |
| 504 | "MiMoV2OmniForCausalLM": ("mimo_v2_omni", "MiMoV2OmniForCausalLM"), |
| 505 | "MiniMaxM3SparseForConditionalGeneration": ( |
| 506 | "vllm.models.minimax_m3", |
| 507 | "MiniMaxM3SparseForConditionalGeneration", |
| 508 | ), |
| 509 | "MiniCPMO": ("minicpmo", "MiniCPMO"), |
| 510 | "MiniCPMV": ("minicpmv", "MiniCPMV"), |
| 511 | "MiniCPMV4_6ForConditionalGeneration": ( |
| 512 | "minicpmv4_6", |
| 513 | "MiniCPMV4_6ForConditionalGeneration", |
| 514 | ), |
| 515 | "Mistral3ForConditionalGeneration": ( |
| 516 | "mistral3", |
| 517 | "Mistral3ForConditionalGeneration", |
| 518 | ), |
| 519 | "MolmoForCausalLM": ("molmo", "MolmoForCausalLM"), |
| 520 | "Molmo2ForConditionalGeneration": ("molmo2", "Molmo2ForConditionalGeneration"), |
| 521 | "Moondream3ForCausalLM": ("moondream3", "Moondream3ForCausalLM"), |
| 522 | "MossAudioModel": ("moss_audio", "MossAudioModel"), |
| 523 | "HfMoondream": ("moondream3", "Moondream3ForCausalLM"), |
| 524 | "NemotronH_Nano_VL_V2": ("nano_nemotron_vl", "NemotronH_Nano_VL_V2"), |
| 525 | "NemotronH_Nano_Omni_Reasoning_V3": ("nano_nemotron_vl", "NemotronH_Nano_VL_V2"), |
| 526 | "NemotronH_Super_Omni_Reasoning_V3": ("nano_nemotron_vl", "NemotronH_Nano_VL_V2"), |
| 527 | "NemotronH_Omni_Reasoning_V3": ("nano_nemotron_vl", "NemotronH_Nano_VL_V2"), |
| 528 | "NVLM_D": ("nvlm_d", "NVLM_D_Model"), |
| 529 | "MuseGlimmerForConditionalGeneration": ("muse_glimmer", "MuseGlimmerForCausalLM"), |
| 530 | "OpenCUAForConditionalGeneration": ("opencua", "OpenCUAForConditionalGeneration"), |
| 531 | "OpenPanguVLForConditionalGeneration": ( |
| 532 | "openpangu_vl", |
| 533 | "OpenPanguVLForConditionalGeneration", |
| 534 | ), |
| 535 | "OpenVLAForActionPrediction": ("openvla", "OpenVLAForActionPrediction"), |
| 536 | "Ovis": ("ovis", "Ovis"), |
| 537 | "Ovis2_5": ("ovis2_5", "Ovis2_5"), |
| 538 | "Ovis2_6ForCausalLM": ("ovis2_5", "Ovis2_5"), |
| 539 | "Ovis2_6_MoeForCausalLM": ("ovis2_5", "Ovis2_5"), |
| 540 | "PaddleOCRVLForConditionalGeneration": ( |
| 541 | "paddleocr_vl", |
| 542 | "PaddleOCRVLForConditionalGeneration", |
| 543 | ), |
| 544 | "PaliGemmaForConditionalGeneration": ( |
| 545 | "paligemma", |
| 546 | "PaliGemmaForConditionalGeneration", |
| 547 | ), |
| 548 | "Phi3VForCausalLM": ("phi3v", "Phi3VForCausalLM"), |
| 549 | "Phi4ForCausalLMV": ("phi4siglip", "Phi4ForCausalLMV"), |
| 550 | "Phi4MMForCausalLM": ("phi4mm", "Phi4MMForCausalLM"), |
| 551 | "PixtralForConditionalGeneration": ("pixtral", "PixtralForConditionalGeneration"), |
| 552 | "QianfanOCRForConditionalGeneration": ( |
| 553 | "qianfan_ocr", |
| 554 | "QianfanOCRForConditionalGeneration", |
| 555 | ), |
| 556 | "Qwen2VLForConditionalGeneration": ("qwen2_vl", "Qwen2VLForConditionalGeneration"), |
| 557 | "Qwen2_5_VLForConditionalGeneration": ( |
| 558 | "qwen2_5_vl", |
| 559 | "Qwen2_5_VLForConditionalGeneration", |
| 560 | ), |
| 561 | "Qwen2AudioForConditionalGeneration": ( |
| 562 | "qwen2_audio", |
| 563 | "Qwen2AudioForConditionalGeneration", |
| 564 | ), |
| 565 | "Qwen2_5OmniModel": ( |
| 566 | "qwen2_5_omni_thinker", |
| 567 | "Qwen2_5OmniThinkerForConditionalGeneration", |
| 568 | ), |
| 569 | "Qwen2_5OmniForConditionalGeneration": ( |
| 570 | "qwen2_5_omni_thinker", |
| 571 | "Qwen2_5OmniThinkerForConditionalGeneration", |
| 572 | ), |
| 573 | "Qwen3OmniMoeForConditionalGeneration": ( |
| 574 | "qwen3_omni_moe_thinker", |
| 575 | "Qwen3OmniMoeThinkerForConditionalGeneration", |
| 576 | ), |
| 577 | "Qwen3ASRForConditionalGeneration": ( |
| 578 | "qwen3_asr", |
| 579 | "Qwen3ASRForConditionalGeneration", |
| 580 | ), |
| 581 | "Qwen3ASRRealtimeGeneration": ("qwen3_asr_realtime", "Qwen3ASRRealtimeGeneration"), |
| 582 | "Qwen3VLForConditionalGeneration": ("qwen3_vl", "Qwen3VLForConditionalGeneration"), |
| 583 | "Qwen3VLMoeForConditionalGeneration": ( |
| 584 | "qwen3_vl_moe", |
| 585 | "Qwen3VLMoeForConditionalGeneration", |
| 586 | ), |
| 587 | "Qwen3_5ForConditionalGeneration": ("qwen3_5", "Qwen3_5ForConditionalGeneration"), |
| 588 | "Qwen3_5MoeForConditionalGeneration": ( |
| 589 | "qwen3_5", |
| 590 | "Qwen3_5MoeForConditionalGeneration", |
| 591 | ), |
| 592 | "Qwen4ExpForConditionalGeneration": ( |
| 593 | "vllm.models.qwen4_exp", |
| 594 | "Qwen4ExpForConditionalGeneration", |
| 595 | ), |
| 596 | "RForConditionalGeneration": ("rvl", "RForConditionalGeneration"), |
| 597 | "SkyworkR1VChatModel": ("skyworkr1v", "SkyworkR1VChatModel"), |
| 598 | "SmolVLMForConditionalGeneration": ("smolvlm", "SmolVLMForConditionalGeneration"), |
| 599 | "StepVLForConditionalGeneration": ("step_vl", "StepVLForConditionalGeneration"), |
| 600 | "Step3VLForConditionalGeneration": ("step3_vl", "Step3VLForConditionalGeneration"), |
| 601 | "Step3p7ForConditionalGeneration": ("step3p7", "Step3p7ForConditionalGeneration"), |
| 602 | "UltravoxModel": ("ultravox", "UltravoxModel"), |
| 603 | "VoxtralForConditionalGeneration": ("voxtral", "VoxtralForConditionalGeneration"), |
| 604 | "VoxtralRealtimeGeneration": ("voxtral_realtime", "VoxtralRealtimeGeneration"), |
| 605 | # [Encoder-decoder] |
| 606 | "CohereAsrForConditionalGeneration": ( |
| 607 | "cohere_asr", |
| 608 | "CohereAsrForConditionalGeneration", |
| 609 | ), |
| 610 | "NemotronParseForConditionalGeneration": ( |
| 611 | "nemotron_parse", |
| 612 | "NemotronParseForConditionalGeneration", |
| 613 | ), |
| 614 | "WhisperForConditionalGeneration": ("whisper", "WhisperForConditionalGeneration"), |
| 615 | } |
| 616 | |
| 617 | _SPECULATIVE_DECODING_MODELS = { |
| 618 | "ExtractHiddenStatesModel": ("extract_hidden_states", "ExtractHiddenStatesModel"), |
| 619 | "MiMoMTPModel": ("mimo_mtp", "MiMoMTP"), |
| 620 | "MiMoV2MTPModel": ("mimo_v2_mtp", "MiMoV2MTP"), |
| 621 | "MiMoV2OmniMTPModel": ("mimo_v2_mtp", "MiMoV2OmniMTP"), |
| 622 | "EagleCohereForCausalLM": ("cohere_eagle", "EagleCohereForCausalLM"), |
| 623 | "EagleLlamaForCausalLM": ("llama_eagle", "EagleLlamaForCausalLM"), |
| 624 | "EagleLlama4ForCausalLM": ("llama4_eagle", "EagleLlama4ForCausalLM"), |
| 625 | "EagleMiniCPMForCausalLM": ("minicpm_eagle", "EagleMiniCPMForCausalLM"), |
| 626 | "DFlashDraftModel": ("qwen3_dflash", "DFlashQwen3ForCausalLM"), |
| 627 | "LiLiCorrDraftModel": ("lilicorr", "LiLiCorrForCausalLM"), |
| 628 | "DFlash2DraftModel": ("qwen3_dflash2", "DFlash2Qwen3ForCausalLM"), |
| 629 | # Muse Glimmer's DFlash draft head, reusing the generic qwen3_dflash |
| 630 | # implementation. EAGLEConfig rewrites a dflash draft's architecture to |
| 631 | # DFlash{arch} unless it already starts or ends with "DFlash" (see |
| 632 | # transformers_utils/configs/eagle.py), so the name the registry is asked |
| 633 | # for is DFlashMuseGlimmerAssistantModel -- same convention as |
| 634 | # DFlashLagunaForCausalLM. The bare name is kept as a defensive alias. |
| 635 | "MuseGlimmerAssistantModel": ("qwen3_dflash", "DFlashQwen3ForCausalLM"), |
| 636 | "DFlashMuseGlimmerAssistantModel": ("qwen3_dflash", "DFlashQwen3ForCausalLM"), |
| 637 | "DSparkDraftModel": ("vllm.models.deepseek_v4", "DSparkDeepseekV4ForCausalLM"), |
| 638 | "DSparkV41DraftModel": ( |
| 639 | "vllm.models.deepseek_v41", |
| 640 | "DSparkDeepseekV4ForCausalLM", |
| 641 | ), |
| 642 | "Qwen3DSparkModel": ("qwen3_dspark", "Qwen3DSparkForCausalLM"), |
| 643 | "Qwen3OmniDSparkModel": ("qwen3_dspark", "Qwen3DSparkForCausalLM"), |
| 644 | "K3DSparkModel": ( |
| 645 | "vllm.models.kimi_k3.nvidia.dspark_mla", |
| 646 | "K3DSparkForCausalLM", |
| 647 | ), |
| 648 | "DFlashLagunaForCausalLM": ("laguna_dflash", "DFlashLagunaForCausalLM"), |
| 649 | "Gemma4DSparkModel": ("gemma4_dspark", "Gemma4DSparkForCausalLM"), |
| 650 | "PEagleDraftModel": ("llama_eagle3", "Eagle3LlamaForCausalLM"), |
| 651 | "PeagleLlamaForCausalLM": ("llama_eagle3", "Eagle3LlamaForCausalLM"), |
| 652 | "Eagle3LlamaForCausalLM": ("llama_eagle3", "Eagle3LlamaForCausalLM"), |
| 653 | "Eagle3MiniMaxM2ForCausalLM": ("llama_eagle3", "Eagle3LlamaForCausalLM"), |
| 654 | "LlamaForCausalLMEagle3": ("llama_eagle3", "Eagle3LlamaForCausalLM"), |
| 655 | "Eagle3Qwen2_5vlForCausalLM": ("llama_eagle3", "Eagle3LlamaForCausalLM"), |
| 656 | "Eagle3Qwen3vlForCausalLM": ("llama_eagle3", "Eagle3LlamaForCausalLM"), |
| 657 | "Eagle3Qwen3ForCausalLM": ("qwen3_eagle3", "Eagle3Qwen3ForCausalLM"), |
| 658 | "PeagleQwen3ForCausalLM": ("qwen3_eagle3", "Eagle3Qwen3ForCausalLM"), |
| 659 | "EagleMistralForCausalLM": ("mistral_eagle", "EagleMistralForCausalLM"), |
| 660 | "EagleMistralLarge3ForCausalLM": ( |
| 661 | "mistral_large_3_eagle", |
| 662 | "EagleMistralLarge3ForCausalLM", |
| 663 | ), |
| 664 | "Eagle3DeepseekV2ForCausalLM": ("deepseek_eagle3", "Eagle3DeepseekV2ForCausalLM"), |
| 665 | "Eagle3DeepseekV3ForCausalLM": ("deepseek_eagle3", "Eagle3DeepseekV2ForCausalLM"), |
| 666 | "EagleDeepSeekMTPModel": ("deepseek_eagle", "EagleDeepseekV3ForCausalLM"), |
| 667 | "DeepSeekMTPModel": ("deepseek_mtp", "DeepSeekMTP"), |
| 668 | "DeepseekV32MTPModel": ("vllm.models.deepseek_v32", "DeepseekV32MTP"), |
| 669 | "Dots3NoteMTPModel": ("vllm.models.dots3_note", "Dots3NoteMTP"), |
| 670 | "DeepSeekV4MTPModel": ("vllm.models.deepseek_v4", "DeepSeekV4MTP"), |
| 671 | "BailingMoeV3MTPModel": ("bailing_moe_v3_mtp", "BailingMoeV3MTPModel"), |
| 672 | "MiniMaxM3MTP": ("vllm.models.minimax_m3", "MiniMaxM3MTP"), |
| 673 | "BailingMoeV25MTPModel": ("bailing_moe_mtp", "BailingMoeV25MTPModel"), |
| 674 | "InklingMTPModel": ("vllm.models.inkling", "InklingMTP"), |
| 675 | "Gemma4MTPModel": ("gemma4_mtp", "Gemma4MTP"), |
| 676 | "ErnieMTPModel": ("ernie_mtp", "ErnieMTP"), |
| 677 | "ExaoneMoeMTP": ("exaone_moe_mtp", "ExaoneMoeMTP"), |
| 678 | "Exaone4_5_MTP": ("exaone4_5_mtp", "Exaone4_5_MTP"), |
| 679 | "NemotronHMTPModel": ("nemotron_h_mtp", "NemotronHMTP"), |
| 680 | "LongCatFlashMTPModel": ("longcat_flash_mtp", "LongCatFlashMTP"), |
| 681 | "Glm4MoeMTPModel": ("glm4_moe_mtp", "Glm4MoeMTP"), |
| 682 | "Glm4MoeLiteMTPModel": ("glm4_moe_lite_mtp", "Glm4MoeLiteMTP"), |
| 683 | "GlmOcrMTPModel": ("glm_ocr_mtp", "GlmOcrMTP"), |
| 684 | "Glm5NextMTPModel": ("vllm.models.glm5next", "Glm5NextMTP"), |
| 685 | "MedusaModel": ("medusa", "Medusa"), |
| 686 | "OpenPanguMTPModel": ("openpangu_mtp", "OpenPanguMTP"), |
| 687 | "Qwen3NextMTP": ("qwen3_next_mtp", "Qwen3NextMTP"), |
| 688 | "Qwen4ExpMTP": ("vllm.models.qwen4_exp", "Qwen4ExpMTP"), |
| 689 | "Step3p5MTP": ("step3p5_mtp", "Step3p5MTP"), |
| 690 | "Qwen3_5MTP": ("qwen3_5_mtp", "Qwen3_5MTP"), |
| 691 | "Qwen3_5MoeMTP": ("qwen3_5_mtp", "Qwen3_5MoeMTP"), |
| 692 | "InternS2MobiusMTP": ("interns2_mobius", "InternS2MobiusMTP"), |
| 693 | "HYV3MTPModel": ("hy_v3_mtp", "HYV3MTP"), |
| 694 | "HYV4MTPModel": ("vllm.models.hy_v4", "HYV4MTP"), |
| 695 | "KimiK3MTPModel": ("vllm.models.kimi_k3", "KimiK3MTP"), |
| 696 | # Temporarily disabled. |
| 697 | # # TODO(woosuk): Re-enable this once the MLP Speculator is supported in V1. |
| 698 | # "MLPSpeculatorPreTrainedModel": ("mlp_speculator", "MLPSpeculator"), |
| 699 | } |
| 700 | |
| 701 | _TRANSFORMERS_SUPPORTED_MODELS = { |
| 702 | # Text generation models |
| 703 | "ArceeForCausalLM": ("transformers", "TransformersForCausalLM"), |
| 704 | "CwmForCausalLM": ("transformers", "TransformersForCausalLM"), |
| 705 | "FlexOlmoForCausalLM": ("transformers", "TransformersMoEForCausalLM"), |
| 706 | "GlmForCausalLM": ("transformers", "TransformersForCausalLM"), |
| 707 | "GPTBigCodeForCausalLM": ("transformers", "TransformersForCausalLM"), |
| 708 | "GPTNeoXForCausalLM": ("transformers", "TransformersForCausalLM"), |
| 709 | "HunYuanDenseV1ForCausalLM": ("transformers", "TransformersForCausalLM"), |
| 710 | "HunYuanMoEV1ForCausalLM": ("transformers", "TransformersMoEForCausalLM"), |
| 711 | "Jais2ForCausalLM": ("transformers", "TransformersForCausalLM"), |
| 712 | "MellumForCausalLM": ("transformers", "TransformersMoEForCausalLM"), |
| 713 | "NanbeigeForCausalLM": ("transformers", "TransformersForCausalLM"), |
| 714 | "OlmoForCausalLM": ("transformers", "TransformersForCausalLM"), |
| 715 | "Olmo2ForCausalLM": ("transformers", "TransformersForCausalLM"), |
| 716 | "Olmo3ForCausalLM": ("transformers", "TransformersForCausalLM"), |
| 717 | "PhiForCausalLM": ("transformers", "TransformersForCausalLM"), |
| 718 | "SeedOssForCausalLM": ("transformers", "TransformersForCausalLM"), |
| 719 | "SmolLM3ForCausalLM": ("transformers", "TransformersForCausalLM"), |
| 720 | "Starcoder2ForCausalLM": ("transformers", "TransformersForCausalLM"), |
| 721 | "VaultGemmaForCausalLM": ("transformers", "TransformersForCausalLM"), |
| 722 | # Multimodal models |
| 723 | "Emu3ForConditionalGeneration": ( |
| 724 | "transformers", |
| 725 | "TransformersMultiModalForCausalLM", |
| 726 | ), |
| 727 | "HunYuanVLForConditionalGeneration": ( |
| 728 | "transformers", |
| 729 | "TransformersMultiModalForCausalLM", |
| 730 | ), |
| 731 | "VibeVoiceAsrForConditionalGeneration": ( |
| 732 | "transformers", |
| 733 | "TransformersMultiModalForCausalLM", |
| 734 | ), |
| 735 | } |
| 736 | |
| 737 | _TRANSFORMERS_BACKEND_MODELS = { |
| 738 | # Text generation models |
| 739 | "TransformersForCausalLM": ("transformers", "TransformersForCausalLM"), |
| 740 | "TransformersMoEForCausalLM": ("transformers", "TransformersMoEForCausalLM"), |
| 741 | # Multimodal models |
| 742 | "TransformersMultiModalForCausalLM": ( |
| 743 | "transformers", |
| 744 | "TransformersMultiModalForCausalLM", |
| 745 | ), |
| 746 | "TransformersMultiModalMoEForCausalLM": ( |
| 747 | "transformers", |
| 748 | "TransformersMultiModalMoEForCausalLM", |
| 749 | ), |
| 750 | # Embedding models |
| 751 | "TransformersEmbeddingModel": ("transformers", "TransformersEmbeddingModel"), |
| 752 | "TransformersMoEEmbeddingModel": ("transformers", "TransformersMoEEmbeddingModel"), |
| 753 | "TransformersMultiModalEmbeddingModel": ( |
| 754 | "transformers", |
| 755 | "TransformersMultiModalEmbeddingModel", |
| 756 | ), |
| 757 | # Sequence classification models |
| 758 | "TransformersForSequenceClassification": ( |
| 759 | "transformers", |
| 760 | "TransformersForSequenceClassification", |
| 761 | ), |
| 762 | "TransformersMoEForSequenceClassification": ( |
| 763 | "transformers", |
| 764 | "TransformersMoEForSequenceClassification", |
| 765 | ), |
| 766 | "TransformersMultiModalForSequenceClassification": ( |
| 767 | "transformers", |
| 768 | "TransformersMultiModalForSequenceClassification", |
| 769 | ), |
| 770 | } |
| 771 | |
| 772 | _VLLM_MODELS = { |
| 773 | **_TEXT_GENERATION_MODELS, |
| 774 | **_EMBEDDING_MODELS, |
| 775 | **_LATE_INTERACTION_MODELS, |
| 776 | **_REWARD_MODELS, |
| 777 | **_TOKEN_CLASSIFICATION_MODELS, |
| 778 | **_SEQUENCE_CLASSIFICATION_MODELS, |
| 779 | **_MULTIMODAL_MODELS, |
| 780 | **_SPECULATIVE_DECODING_MODELS, |
| 781 | **_TRANSFORMERS_SUPPORTED_MODELS, |
| 782 | **_TRANSFORMERS_BACKEND_MODELS, |
| 783 | } |
| 784 | |
| 785 | # This variable is used as the args for subprocess.run(). We |
| 786 | # can modify this variable to alter the args if needed. e.g. |
| 787 | # when we use par format to pack things together, sys.executable |
| 788 | # might not be the target we want to run. |
| 789 | _SUBPROCESS_COMMAND = [sys.executable, "-m", "vllm.model_executor.models.registry"] |
| 790 | |
| 791 | _PREVIOUSLY_SUPPORTED_MODELS = { |
| 792 | "MotifForCausalLM": "0.10.2", |
| 793 | "Phi3SmallForCausalLM": "0.9.2", |
| 794 | "Phi4FlashForCausalLM": "0.10.2", |
| 795 | "Phi4MultimodalForCausalLM": "0.12.0", |
| 796 | "JAISLMHeadModel": "0.22.0", |
| 797 | "ErnieModel": "0.23.0", |
| 798 | "ErnieForSequenceClassification": "0.23.0", |
| 799 | "ErnieForTokenClassification": "0.23.0", |
| 800 | "InternLM2VEForCausalLM": "0.23.0", |
| 801 | "QWenLMHeadModel": "0.23.0", |
| 802 | "QwenVLForConditionalGeneration": "0.23.0", |
| 803 | "InternLMForCausalLM": "0.23.0", |
| 804 | # encoder-decoder models except whisper |
| 805 | # have been removed for V0 deprecation. |
| 806 | "DonutForConditionalGeneration": "0.10.2", |
| 807 | "MllamaForConditionalGeneration": "0.10.2", |
| 808 | "XverseForCausalLM": "0.23.0", |
| 809 | "Dots1ForCausalLM": "0.23.0", |
| 810 | "BambaForCausalLM": "0.23.0", |
| 811 | "MiniMaxForCausalLM": "0.23.0", |
| 812 | "MiniMaxText01ForCausalLM": "0.23.0", |
| 813 | "MiniMaxM1ForCausalLM": "0.23.0", |
| 814 | "MiniMaxVL01ForConditionalGeneration": "0.23.0", |
| 815 | "BaiChuanForCausalLM": "0.23.0", |
| 816 | "BaichuanForCausalLM": "0.23.0", |
| 817 | "AquilaModel": "0.24.0", |
| 818 | "AquilaForCausalLM": "0.24.0", |
| 819 | "Grok1ModelForCausalLM": "0.24.0", |
| 820 | "Grok1ForCausalLM": "0.24.0", |
| 821 | "TarsierForConditionalGeneration": "0.24.0", |
| 822 | "Tarsier2ForConditionalGeneration": "0.23.0", # last version with Transformers v4 |
| 823 | "MantisForConditionalGeneration": "0.24.0", |
| 824 | "MusicFlamingoForConditionalGeneration": "0.24.0", |
| 825 | "AyaVisionForConditionalGeneration": "0.24.0", |
| 826 | "TeleChatForCausalLM": "0.25.0", |
| 827 | "PersimmonForCausalLM": "0.25.0", |
| 828 | "FuyuForCausalLM": "0.25.0", |
| 829 | "Plamo2ForCausalLM": "0.26.0", |
| 830 | "OuroForCausalLM": "0.26.0", |
| 831 | "ArcticForCausalLM": "0.28.0", |
| 832 | "ChameleonForConditionalGeneration": "0.28.0", |
| 833 | "Cheers": "0.28.0", |
| 834 | "CheersForConditionalGeneration": "0.28.0", |
| 835 | "Fairseq2LlamaForCausalLM": "0.28.0", |
| 836 | "FireRedLIDForConditionalGeneration": "0.28.0", |
| 837 | "GritLM": "0.28.0", |
| 838 | "HCXVisionForCausalLM": "0.28.0", |
| 839 | "MPTForCausalLM": "0.28.0", |
| 840 | "MptForCausalLM": "0.28.0", |
| 841 | "RWForCausalLM": "0.28.0", |
| 842 | "StableLMEpochForCausalLM": "0.28.0", |
| 843 | # Superseded by the generic "Terratorch" architecture |
| 844 | "PrithviGeoSpatialMAE": "0.28.0", |
| 845 | } |
| 846 | |
| 847 | _OOT_SUPPORTED_MODELS = { |
| 848 | "BartModel": "https://github.com/vllm-project/bart-plugin", |
| 849 | "BartForConditionalGeneration": "https://github.com/vllm-project/bart-plugin", |
| 850 | "Florence2ForConditionalGeneration": "https://github.com/vllm-project/bart-plugin", |
| 851 | "MBartForConditionalGeneration": "https://github.com/vllm-project/bart-plugin", |
| 852 | } |
| 853 | |
| 854 | |
| 855 | @dataclass(frozen=True) |
| 856 | class _ModelInfo: |
| 857 | architecture: str |
| 858 | is_text_generation_model: bool |
| 859 | is_pooling_model: bool |
| 860 | attn_type: AttnTypeStr |
| 861 | default_seq_pooling_type: SequencePoolingType |
| 862 | default_tok_pooling_type: TokenPoolingType |
| 863 | score_type: ScoreType |
| 864 | supports_multimodal: bool |
| 865 | supports_multimodal_raw_input_only: bool |
| 866 | requires_raw_input_tokens: bool |
| 867 | supports_multimodal_encoder_tp_data: bool |
| 868 | supports_pp: bool |
| 869 | has_inner_state: bool |
| 870 | is_attention_free: bool |
| 871 | is_hybrid: bool |
| 872 | has_noops: bool |
| 873 | supports_mamba_prefix_caching: bool |
| 874 | supports_replayssm: bool |
| 875 | supports_transcription: bool |
| 876 | supports_transcription_only: bool |
| 877 | supported_video_pruning_methods: tuple[str, ...] |
| 878 | supports_mm_device_do_normalize: bool |
| 879 | |
| 880 | @staticmethod |
| 881 | def from_model_cls(model: type[nn.Module]) -> "_ModelInfo": |
| 882 | return _ModelInfo( |
| 883 | architecture=model.__name__, |
| 884 | is_text_generation_model=is_text_generation_model(model), |
| 885 | is_pooling_model=is_pooling_model(model), |
| 886 | default_seq_pooling_type=get_default_seq_pooling_type(model), |
| 887 | default_tok_pooling_type=get_default_tok_pooling_type(model), |
| 888 | attn_type=get_attn_type(model), |
| 889 | score_type=get_score_type(model), |
| 890 | supports_multimodal=supports_multimodal(model), |
| 891 | supports_multimodal_raw_input_only=supports_multimodal_raw_input_only( |
| 892 | model |
| 893 | ), |
| 894 | requires_raw_input_tokens=requires_raw_input_tokens(model), |
| 895 | supports_multimodal_encoder_tp_data=supports_multimodal_encoder_tp_data( |
| 896 | model |
| 897 | ), |
| 898 | supports_pp=supports_pp(model), |
| 899 | has_inner_state=has_inner_state(model), |
| 900 | is_attention_free=is_attention_free(model), |
| 901 | is_hybrid=is_hybrid(model), |
| 902 | supports_mamba_prefix_caching=supports_mamba_prefix_caching(model), |
| 903 | supports_replayssm=supports_replayssm(model), |
| 904 | supports_transcription=supports_transcription(model), |
| 905 | supports_transcription_only=( |
| 906 | supports_transcription(model) and model.supports_transcription_only |
| 907 | ), |
| 908 | has_noops=has_noops(model), |
| 909 | supported_video_pruning_methods=getattr( |
| 910 | model, "supported_video_pruning_methods", () |
| 911 | ), |
| 912 | supports_mm_device_do_normalize=getattr( |
| 913 | model, "supports_mm_device_do_normalize", False |
| 914 | ), |
| 915 | ) |
| 916 | |
| 917 | |
| 918 | class _BaseRegisteredModel(ABC): |
| 919 | @abstractmethod |
| 920 | def inspect_model_cls(self) -> _ModelInfo: |
| 921 | raise NotImplementedError |
| 922 | |
| 923 | @abstractmethod |
| 924 | def load_model_cls(self) -> type[nn.Module]: |
| 925 | raise NotImplementedError |
| 926 | |
| 927 | |
| 928 | @dataclass(frozen=True) |
| 929 | class _RegisteredModel(_BaseRegisteredModel): |
| 930 | """Represents a model that has already been imported in the main process.""" |
| 931 | |
| 932 | interfaces: _ModelInfo |
| 933 | model_cls: type[nn.Module] |
| 934 | |
| 935 | @staticmethod |
| 936 | def from_model_cls(model_cls: type[nn.Module]): |
| 937 | return _RegisteredModel( |
| 938 | interfaces=_ModelInfo.from_model_cls(model_cls), |
| 939 | model_cls=model_cls, |
| 940 | ) |
| 941 | |
| 942 | def inspect_model_cls(self) -> _ModelInfo: |
| 943 | return self.interfaces |
| 944 | |
| 945 | def load_model_cls(self) -> type[nn.Module]: |
| 946 | return self.model_cls |
| 947 | |
| 948 | |
| 949 | @dataclass(frozen=True) |
| 950 | class _LazyRegisteredModel(_BaseRegisteredModel): |
| 951 | """Represents a model that has not been imported in the main process.""" |
| 952 | |
| 953 | module_name: str |
| 954 | class_name: str |
| 955 | |
| 956 | @staticmethod |
| 957 | def _get_cache_dir() -> Path: |
| 958 | return Path(envs.VLLM_CACHE_ROOT) / "modelinfos" |
| 959 | |
| 960 | def _get_cache_filename(self) -> str: |
| 961 | cls_name = f"{self.module_name}-{self.class_name}".replace(".", "-") |
| 962 | return f"{cls_name}.json" |
| 963 | |
| 964 | @staticmethod |
| 965 | def _get_modelinfo_module_hash(model_path: Path) -> str: |
| 966 | if model_path.name == "__init__.py": |
| 967 | # Package entry points often re-export classes implemented in |
| 968 | # submodules, so include the package contents in the cache key. |
| 969 | module_paths = sorted(model_path.parent.rglob("*.py")) |
| 970 | root_path = model_path.parent |
| 971 | else: |
| 972 | module_paths = [model_path] |
| 973 | root_path = model_path.parent |
| 974 | |
| 975 | hasher = safe_hash(b"", usedforsecurity=False) |
| 976 | for path in module_paths: |
| 977 | hasher.update(path.relative_to(root_path).as_posix().encode("utf-8")) |
| 978 | hasher.update(b"\0") |
| 979 | hasher.update(path.read_bytes()) |
| 980 | hasher.update(b"\0") |
| 981 | return hasher.hexdigest() |
| 982 | |
| 983 | def _load_modelinfo_from_cache(self, module_hash: str) -> _ModelInfo | None: |
| 984 | try: |
| 985 | try: |
| 986 | modelinfo_path = self._get_cache_dir() / self._get_cache_filename() |
| 987 | with open(modelinfo_path, encoding="utf-8") as file: |
| 988 | mi_dict = json.load(file) |
| 989 | except FileNotFoundError: |
| 990 | logger.debug( |
| 991 | "Cached model info file for class %s.%s not found", |
| 992 | self.module_name, |
| 993 | self.class_name, |
| 994 | ) |
| 995 | return None |
| 996 | |
| 997 | if mi_dict["hash"] != module_hash: |
| 998 | logger.debug( |
| 999 | "Cached model info file for class %s.%s is stale", |
| 1000 | self.module_name, |
| 1001 | self.class_name, |
| 1002 | ) |
| 1003 | return None |
| 1004 | |
| 1005 | # file not changed, use cached _ModelInfo properties |
| 1006 | return _ModelInfo(**mi_dict["modelinfo"]) |
| 1007 | except Exception: |
| 1008 | logger.debug( |
| 1009 | "Cached model info for class %s.%s error. ", |
| 1010 | self.module_name, |
| 1011 | self.class_name, |
| 1012 | ) |
| 1013 | return None |
| 1014 | |
| 1015 | def _save_modelinfo_to_cache(self, mi: _ModelInfo, module_hash: str) -> None: |
| 1016 | """Save dictionary json file to cache.""" |
| 1017 | from vllm.model_executor.model_loader.weight_utils import atomic_writer |
| 1018 | |
| 1019 | try: |
| 1020 | modelinfo_dict = { |
| 1021 | "hash": module_hash, |
| 1022 | "modelinfo": asdict(mi), |
| 1023 | } |
| 1024 | cache_dir = self._get_cache_dir() |
| 1025 | cache_dir.mkdir(parents=True, exist_ok=True) |
| 1026 | modelinfo_path = cache_dir / self._get_cache_filename() |
| 1027 | with atomic_writer(modelinfo_path, encoding="utf-8") as f: |
| 1028 | json.dump(modelinfo_dict, f, indent=2) |
| 1029 | except Exception: |
| 1030 | logger.exception("Error saving model info cache.") |
| 1031 | |
| 1032 | @logtime(logger=logger, msg="Registry inspect model class") |
| 1033 | def inspect_model_cls(self) -> _ModelInfo: |
| 1034 | # Modules registered with a non-default location (e.g. the |
| 1035 | # hardware-isolated ``vllm.models.<name>`` layout) live outside |
| 1036 | # ``vllm/model_executor/models``. Resolve the module spec directly |
| 1037 | # so the file-hash cache stays warm for them. |
| 1038 | model_path: Path | None = None |
| 1039 | if self.module_name.startswith("vllm.model_executor.models."): |
| 1040 | model_path = Path(__file__).parent / f"{self.module_name.split('.')[-1]}.py" |
| 1041 | if model_path is None or not model_path.exists(): |
| 1042 | try: |
| 1043 | spec = importlib.util.find_spec(self.module_name) |
| 1044 | except (ImportError, ValueError): |
| 1045 | spec = None |
| 1046 | model_path = Path(spec.origin) if spec is not None and spec.origin else None |
| 1047 | module_hash = None |
| 1048 | |
| 1049 | if model_path is not None and model_path.exists(): |
| 1050 | module_hash = self._get_modelinfo_module_hash(model_path) |
| 1051 | |
| 1052 | mi = self._load_modelinfo_from_cache(module_hash) |
| 1053 | if mi is not None: |
| 1054 | logger.debug( |
| 1055 | "Loaded model info for class %s.%s from cache", |
| 1056 | self.module_name, |
| 1057 | self.class_name, |
| 1058 | ) |
| 1059 | return mi |
| 1060 | else: |
| 1061 | logger.debug( |
| 1062 | "Cache model info for class %s.%s miss. Loading model instead.", |
| 1063 | self.module_name, |
| 1064 | self.class_name, |
| 1065 | ) |
| 1066 | |
| 1067 | # Performed in another process to avoid initializing CUDA |
| 1068 | mi = _run_in_subprocess( |
| 1069 | lambda: _ModelInfo.from_model_cls(self.load_model_cls()) |
| 1070 | ) |
| 1071 | logger.debug( |
| 1072 | "Loaded model info for class %s.%s", self.module_name, self.class_name |
| 1073 | ) |
| 1074 | |
| 1075 | # save cache file |
| 1076 | if module_hash is not None: |
| 1077 | self._save_modelinfo_to_cache(mi, module_hash) |
| 1078 | |
| 1079 | return mi |
| 1080 | |
| 1081 | def load_model_cls(self) -> type[nn.Module]: |
| 1082 | mod = importlib.import_module(self.module_name) |
| 1083 | return getattr(mod, self.class_name) |
| 1084 | |
| 1085 | |
| 1086 | @lru_cache(maxsize=128) |
| 1087 | def _try_load_model_cls( |
| 1088 | model_arch: str, |
| 1089 | model: _BaseRegisteredModel, |
| 1090 | ) -> type[nn.Module] | None: |
| 1091 | from vllm.platforms import current_platform |
| 1092 | |
| 1093 | current_platform.verify_model_arch(model_arch) |
| 1094 | try: |
| 1095 | return model.load_model_cls() |
| 1096 | except Exception: |
| 1097 | logger.exception("Error in loading model architecture '%s'", model_arch) |
| 1098 | return None |
| 1099 | |
| 1100 | |
| 1101 | @lru_cache(maxsize=128) |
| 1102 | def _try_inspect_model_cls( |
| 1103 | model_arch: str, |
| 1104 | model: _BaseRegisteredModel, |
| 1105 | ) -> _ModelInfo | None: |
| 1106 | try: |
| 1107 | return model.inspect_model_cls() |
| 1108 | except Exception: |
| 1109 | logger.exception("Error in inspecting model architecture '%s'", model_arch) |
| 1110 | return None |
| 1111 | |
| 1112 | |
| 1113 | @dataclass |
| 1114 | class _ModelRegistry: |
| 1115 | # Keyed by model_arch |
| 1116 | models: dict[str, _BaseRegisteredModel] = field(default_factory=dict) |
| 1117 | |
| 1118 | def get_supported_archs(self) -> Set[str]: |
| 1119 | return self.models.keys() |
| 1120 | |
| 1121 | def register_model( |
| 1122 | self, |
| 1123 | model_arch: str, |
| 1124 | model_cls: type[nn.Module] | str, |
| 1125 | ) -> None: |
| 1126 | """Register an external model to be used in vLLM. |
| 1127 | |
| 1128 | `model_cls` can be either: |
| 1129 | |
| 1130 | - A [`torch.nn.Module`][] class directly referencing the model. |
| 1131 | - A string in the format `<module>:<class>` which can be used to |
| 1132 | lazily import the model. This is useful to avoid initializing CUDA |
| 1133 | when importing the model and thus the related error |
| 1134 | `RuntimeError: Cannot re-initialize CUDA in forked subprocess`. |
| 1135 | """ |
| 1136 | if not isinstance(model_arch, str): |
| 1137 | msg = f"`model_arch` should be a string, not a {type(model_arch)}" |
| 1138 | raise TypeError(msg) |
| 1139 | |
| 1140 | if model_arch in self.models: |
| 1141 | logger.debug( |
| 1142 | "Model architecture %s is already registered, and will be " |
| 1143 | "overwritten by the new model class %s.", |
| 1144 | model_arch, |
| 1145 | model_cls, |
| 1146 | ) |
| 1147 | |
| 1148 | if isinstance(model_cls, str): |
| 1149 | split_str = model_cls.split(":") |
| 1150 | if len(split_str) != 2: |
| 1151 | msg = "Expected a string in the format `<module>:<class>`" |
| 1152 | raise ValueError(msg) |
| 1153 | |
| 1154 | model = _LazyRegisteredModel(*split_str) |
| 1155 | elif isinstance(model_cls, type) and issubclass(model_cls, nn.Module): |
| 1156 | model = _RegisteredModel.from_model_cls(model_cls) |
| 1157 | else: |
| 1158 | msg = ( |
| 1159 | "`model_cls` should be a string or PyTorch model class, " |
| 1160 | f"not a {type(model_cls)}" |
| 1161 | ) |
| 1162 | raise TypeError(msg) |
| 1163 | |
| 1164 | self.models[model_arch] = model |
| 1165 | |
| 1166 | def _raise_for_unsupported(self, architectures: list[str]): |
| 1167 | all_supported_archs = self.get_supported_archs() |
| 1168 | |
| 1169 | if any(arch in all_supported_archs for arch in architectures): |
| 1170 | raise ValueError( |
| 1171 | f"Model architectures {architectures} failed " |
| 1172 | "to be inspected. Please check the logs for more details." |
| 1173 | ) |
| 1174 | |
| 1175 | for arch in architectures: |
| 1176 | if arch in _PREVIOUSLY_SUPPORTED_MODELS: |
| 1177 | previous_version = _PREVIOUSLY_SUPPORTED_MODELS[arch] |
| 1178 | |
| 1179 | raise ValueError( |
| 1180 | f"Model architecture {arch} was supported in vLLM until " |
| 1181 | f"v{previous_version}, and is not supported anymore. " |
| 1182 | "Please use an older version of vLLM if you want to " |
| 1183 | "use this model architecture." |
| 1184 | ) |
| 1185 | if arch in _OOT_SUPPORTED_MODELS: |
| 1186 | plugin_url = _OOT_SUPPORTED_MODELS[arch] |
| 1187 | |
| 1188 | raise ValueError( |
| 1189 | f"Model architecture {arch} is not supported in-tree anymore. " |
| 1190 | f"Please install the plugin at {plugin_url} if you want to " |
| 1191 | "use this model architecture." |
| 1192 | ) |
| 1193 | |
| 1194 | raise ValueError( |
| 1195 | f"Model architectures {architectures} are not supported for now. " |
| 1196 | f"Supported architectures: {all_supported_archs}" |
| 1197 | ) |
| 1198 | |
| 1199 | def _try_load_model_cls(self, model_arch: str) -> type[nn.Module] | None: |
| 1200 | if model_arch not in self.models: |
| 1201 | return None |
| 1202 | |
| 1203 | return _try_load_model_cls(model_arch, self.models[model_arch]) |
| 1204 | |
| 1205 | def _try_inspect_model_cls(self, model_arch: str) -> _ModelInfo | None: |
| 1206 | if model_arch not in self.models: |
| 1207 | return None |
| 1208 | |
| 1209 | return _try_inspect_model_cls(model_arch, self.models[model_arch]) |
| 1210 | |
| 1211 | def _try_resolve_transformers( |
| 1212 | self, |
| 1213 | architecture: str, |
| 1214 | model_config: ModelConfig, |
| 1215 | ) -> str | None: |
| 1216 | if architecture in _TRANSFORMERS_BACKEND_MODELS: |
| 1217 | return architecture |
| 1218 | |
| 1219 | auto_map: dict[str, str] = ( |
| 1220 | getattr(model_config.hf_config, "auto_map", None) or dict() |
| 1221 | ) |
| 1222 | |
| 1223 | # Make sure that config class is always initialized before model class, |
| 1224 | # otherwise the model class won't be able to access the config class, |
| 1225 | # the expected auto_map should have correct order like: |
| 1226 | # "auto_map": { |
| 1227 | # "AutoConfig": "<your-repo-name>--<config-name>", |
| 1228 | # "AutoModel": "<your-repo-name>--<config-name>", |
| 1229 | # "AutoModelFor<Task>": "<your-repo-name>--<config-name>", |
| 1230 | # }, |
| 1231 | for prefix in ("AutoConfig", "AutoModel"): |
| 1232 | for name, module in auto_map.items(): |
| 1233 | if name.startswith(prefix): |
| 1234 | try_get_class_from_dynamic_module( |
| 1235 | module, |
| 1236 | model_config.model, |
| 1237 | revision=model_config.revision, |
| 1238 | code_revision=model_config.code_revision, |
| 1239 | trust_remote_code=model_config.trust_remote_code, |
| 1240 | warn_on_fail=False, |
| 1241 | ) |
| 1242 | |
| 1243 | model_module = getattr(transformers, architecture, None) |
| 1244 | |
| 1245 | if model_module is None: |
| 1246 | for name, module in auto_map.items(): |
| 1247 | if name.startswith("AutoModel"): |
| 1248 | model_module = try_get_class_from_dynamic_module( |
| 1249 | module, |
| 1250 | model_config.model, |
| 1251 | revision=model_config.revision, |
| 1252 | code_revision=model_config.code_revision, |
| 1253 | trust_remote_code=model_config.trust_remote_code, |
| 1254 | warn_on_fail=True, |
| 1255 | ) |
| 1256 | if model_module is not None: |
| 1257 | break |
| 1258 | else: |
| 1259 | if model_config.model_impl != "transformers": |
| 1260 | return None |
| 1261 | |
| 1262 | raise ValueError( |
| 1263 | f"Cannot find model module. {architecture!r} is not a " |
| 1264 | "registered model in the Transformers library (only " |
| 1265 | "relevant if the model is meant to be in Transformers) " |
| 1266 | "and 'AutoModel' is not present in the model config's " |
| 1267 | "'auto_map' (relevant if the model is custom)." |
| 1268 | ) |
| 1269 | |
| 1270 | assert issubclass(model_module, transformers.PreTrainedModel) |
| 1271 | transformers_model_cls: type[transformers.PreTrainedModel] = model_module |
| 1272 | if not ( |
| 1273 | transformers_model_cls.is_backend_compatible() |
| 1274 | or transformers_model_cls._can_set_attn_implementation() |
| 1275 | ): |
| 1276 | if model_config.model_impl != "transformers": |
| 1277 | return None |
| 1278 | |
| 1279 | raise ValueError( |
| 1280 | f"The Transformers implementation of {architecture!r} " |
| 1281 | "is not compatible with vLLM." |
| 1282 | ) |
| 1283 | |
| 1284 | return model_config._get_transformers_backend_cls() |
| 1285 | |
| 1286 | def _normalize_arch( |
| 1287 | self, |
| 1288 | architecture: str, |
| 1289 | model_config: ModelConfig, |
| 1290 | ) -> str: |
| 1291 | if architecture in self.models: |
| 1292 | return architecture |
| 1293 | |
| 1294 | # This may be called in order to resolve runner_type and convert_type |
| 1295 | # in the first place, in which case we consider the default match |
| 1296 | match = try_match_architecture_defaults( |
| 1297 | architecture, |
| 1298 | runner_type=getattr(model_config, "runner_type", None), |
| 1299 | convert_type=getattr(model_config, "convert_type", None), |
| 1300 | ) |
| 1301 | if match: |
| 1302 | suffix, _ = match |
| 1303 | |
| 1304 | # Get the name of the base model to convert |
| 1305 | for repl_suffix, _ in iter_architecture_defaults(): |
| 1306 | base_arch = architecture.replace(suffix, repl_suffix) |
| 1307 | if base_arch in self.models: |
| 1308 | return base_arch |
| 1309 | |
| 1310 | return architecture |
| 1311 | |
| 1312 | def inspect_model_cls( |
| 1313 | self, |
| 1314 | architectures: str | list[str], |
| 1315 | model_config: ModelConfig, |
| 1316 | ) -> tuple[_ModelInfo, str]: |
| 1317 | if isinstance(architectures, str): |
| 1318 | architectures = [architectures] |
| 1319 | if not architectures: |
| 1320 | raise ValueError("No model architectures are specified") |
| 1321 | |
| 1322 | # Require transformers impl |
| 1323 | if model_config.model_impl == "transformers": |
| 1324 | arch = self._try_resolve_transformers(architectures[0], model_config) |
| 1325 | if arch is not None: |
| 1326 | model_info = self._try_inspect_model_cls(arch) |
| 1327 | if model_info is not None: |
| 1328 | return (model_info, arch) |
| 1329 | elif model_config.model_impl == "terratorch": |
| 1330 | model_info = self._try_inspect_model_cls("Terratorch") |
| 1331 | assert model_info is not None |
| 1332 | return (model_info, "Terratorch") |
| 1333 | |
| 1334 | # Fallback to transformers impl (after resolving convert_type) |
| 1335 | if ( |
| 1336 | all(arch not in self.models for arch in architectures) |
| 1337 | and model_config.model_impl == "auto" |
| 1338 | and getattr(model_config, "convert_type", "none") == "none" |
| 1339 | ): |
| 1340 | arch = self._try_resolve_transformers(architectures[0], model_config) |
| 1341 | if arch is not None: |
| 1342 | model_info = self._try_inspect_model_cls(arch) |
| 1343 | if model_info is not None: |
| 1344 | return (model_info, arch) |
| 1345 | |
| 1346 | for arch in architectures: |
| 1347 | normalized_arch = self._normalize_arch(arch, model_config) |
| 1348 | model_info = self._try_inspect_model_cls(normalized_arch) |
| 1349 | if model_info is not None: |
| 1350 | return (model_info, arch) |
| 1351 | |
| 1352 | # Fallback to transformers impl (before resolving runner_type) |
| 1353 | if ( |
| 1354 | all(arch not in self.models for arch in architectures) |
| 1355 | and model_config.model_impl == "auto" |
| 1356 | ): |
| 1357 | arch = self._try_resolve_transformers(architectures[0], model_config) |
| 1358 | if arch is not None: |
| 1359 | model_info = self._try_inspect_model_cls(arch) |
| 1360 | if model_info is not None: |
| 1361 | return (model_info, arch) |
| 1362 | |
| 1363 | return self._raise_for_unsupported(architectures) |
| 1364 | |
| 1365 | def resolve_model_cls( |
| 1366 | self, |
| 1367 | architectures: str | list[str], |
| 1368 | model_config: ModelConfig, |
| 1369 | ) -> tuple[type[nn.Module], str]: |
| 1370 | if isinstance(architectures, str): |
| 1371 | architectures = [architectures] |
| 1372 | if not architectures: |
| 1373 | raise ValueError("No model architectures are specified") |
| 1374 | |
| 1375 | # Require transformers impl |
| 1376 | if model_config.model_impl == "transformers": |
| 1377 | arch = self._try_resolve_transformers(architectures[0], model_config) |
| 1378 | if arch is not None: |
| 1379 | model_cls = self._try_load_model_cls(arch) |
| 1380 | if model_cls is not None: |
| 1381 | return (model_cls, arch) |
| 1382 | elif model_config.model_impl == "terratorch": |
| 1383 | arch = "Terratorch" |
| 1384 | model_cls = self._try_load_model_cls(arch) |
| 1385 | if model_cls is not None: |
| 1386 | return (model_cls, arch) |
| 1387 | |
| 1388 | # Fallback to transformers impl (after resolving convert_type) |
| 1389 | if ( |
| 1390 | all(arch not in self.models for arch in architectures) |
| 1391 | and model_config.model_impl == "auto" |
| 1392 | and getattr(model_config, "convert_type", "none") == "none" |
| 1393 | ): |
| 1394 | arch = self._try_resolve_transformers(architectures[0], model_config) |
| 1395 | if arch is not None: |
| 1396 | model_cls = self._try_load_model_cls(arch) |
| 1397 | if model_cls is not None: |
| 1398 | return (model_cls, arch) |
| 1399 | |
| 1400 | for arch in architectures: |
| 1401 | normalized_arch = self._normalize_arch(arch, model_config) |
| 1402 | model_cls = self._try_load_model_cls(normalized_arch) |
| 1403 | if model_cls is not None: |
| 1404 | return (model_cls, arch) |
| 1405 | |
| 1406 | # Fallback to transformers impl (before resolving runner_type) |
| 1407 | if ( |
| 1408 | all(arch not in self.models for arch in architectures) |
| 1409 | and model_config.model_impl == "auto" |
| 1410 | ): |
| 1411 | arch = self._try_resolve_transformers(architectures[0], model_config) |
| 1412 | if arch is not None: |
| 1413 | model_cls = self._try_load_model_cls(arch) |
| 1414 | if model_cls is not None: |
| 1415 | return (model_cls, arch) |
| 1416 | |
| 1417 | return self._raise_for_unsupported(architectures) |
| 1418 | |
| 1419 | def is_text_generation_model( |
| 1420 | self, |
| 1421 | architectures: str | list[str], |
| 1422 | model_config: ModelConfig, |
| 1423 | ) -> bool: |
| 1424 | model_info, _ = self.inspect_model_cls(architectures, model_config) |
| 1425 | return model_info.is_text_generation_model |
| 1426 | |
| 1427 | def is_pooling_model( |
| 1428 | self, |
| 1429 | architectures: str | list[str], |
| 1430 | model_config: ModelConfig, |
| 1431 | ) -> bool: |
| 1432 | model_info, _ = self.inspect_model_cls(architectures, model_config) |
| 1433 | return model_info.is_pooling_model |
| 1434 | |
| 1435 | def is_multimodal_model( |
| 1436 | self, |
| 1437 | architectures: str | list[str], |
| 1438 | model_config: ModelConfig, |
| 1439 | ) -> bool: |
| 1440 | model_info, _ = self.inspect_model_cls(architectures, model_config) |
| 1441 | return model_info.supports_multimodal |
| 1442 | |
| 1443 | def is_multimodal_raw_input_only_model( |
| 1444 | self, |
| 1445 | architectures: str | list[str], |
| 1446 | model_config: ModelConfig, |
| 1447 | ) -> bool: |
| 1448 | model_info, _ = self.inspect_model_cls(architectures, model_config) |
| 1449 | return model_info.supports_multimodal_raw_input_only |
| 1450 | |
| 1451 | def is_pp_supported_model( |
| 1452 | self, |
| 1453 | architectures: str | list[str], |
| 1454 | model_config: ModelConfig, |
| 1455 | ) -> bool: |
| 1456 | model_info, _ = self.inspect_model_cls(architectures, model_config) |
| 1457 | return model_info.supports_pp |
| 1458 | |
| 1459 | def model_has_inner_state( |
| 1460 | self, |
| 1461 | architectures: str | list[str], |
| 1462 | model_config: ModelConfig, |
| 1463 | ) -> bool: |
| 1464 | model_info, _ = self.inspect_model_cls(architectures, model_config) |
| 1465 | return model_info.has_inner_state |
| 1466 | |
| 1467 | def is_attention_free_model( |
| 1468 | self, |
| 1469 | architectures: str | list[str], |
| 1470 | model_config: ModelConfig, |
| 1471 | ) -> bool: |
| 1472 | model_info, _ = self.inspect_model_cls(architectures, model_config) |
| 1473 | return model_info.is_attention_free |
| 1474 | |
| 1475 | def is_hybrid_model( |
| 1476 | self, |
| 1477 | architectures: str | list[str], |
| 1478 | model_config: ModelConfig, |
| 1479 | ) -> bool: |
| 1480 | model_info, _ = self.inspect_model_cls(architectures, model_config) |
| 1481 | return model_info.is_hybrid |
| 1482 | |
| 1483 | def is_noops_model( |
| 1484 | self, |
| 1485 | architectures: str | list[str], |
| 1486 | model_config: ModelConfig, |
| 1487 | ) -> bool: |
| 1488 | model_info, _ = self.inspect_model_cls(architectures, model_config) |
| 1489 | return model_info.has_noops |
| 1490 | |
| 1491 | def is_transcription_model( |
| 1492 | self, |
| 1493 | architectures: str | list[str], |
| 1494 | model_config: ModelConfig, |
| 1495 | ) -> bool: |
| 1496 | model_info, _ = self.inspect_model_cls(architectures, model_config) |
| 1497 | return model_info.supports_transcription |
| 1498 | |
| 1499 | def is_transcription_only_model( |
| 1500 | self, |
| 1501 | architectures: str | list[str], |
| 1502 | model_config: ModelConfig, |
| 1503 | ) -> bool: |
| 1504 | model_info, _ = self.inspect_model_cls(architectures, model_config) |
| 1505 | return model_info.supports_transcription_only |
| 1506 | |
| 1507 | |
| 1508 | def _resolve_module_name(mod_relname: str) -> str: |
| 1509 | # Allow registry entries to point at fully-qualified module paths (e.g. |
| 1510 | # ``vllm.models.deepseek_v4``) for models that live outside the legacy |
| 1511 | # ``vllm.model_executor.models`` flat layout. |
| 1512 | if mod_relname.startswith("vllm."): |
| 1513 | return mod_relname |
| 1514 | return f"vllm.model_executor.models.{mod_relname}" |
| 1515 | |
| 1516 | |
| 1517 | ModelRegistry = _ModelRegistry( |
| 1518 | { |
| 1519 | model_arch: _LazyRegisteredModel( |
| 1520 | module_name=_resolve_module_name(mod_relname), |
| 1521 | class_name=cls_name, |
| 1522 | ) |
| 1523 | for model_arch, (mod_relname, cls_name) in _VLLM_MODELS.items() |
| 1524 | } |
| 1525 | ) |
| 1526 | |
| 1527 | _T = TypeVar("_T") |
| 1528 | |
| 1529 | |
| 1530 | def _run_in_subprocess(fn: Callable[[], _T]) -> _T: |
| 1531 | # NOTE: We use a temporary directory instead of a temporary file to avoid |
| 1532 | # issues like https://stackoverflow.com/questions/23212435/permission-denied-to-write-to-my-temporary-file |
| 1533 | with tempfile.TemporaryDirectory() as tempdir: |
| 1534 | output_filepath = os.path.join(tempdir, "registry_output.tmp") |
| 1535 | |
| 1536 | # `cloudpickle` allows pickling lambda functions directly |
| 1537 | import cloudpickle |
| 1538 | |
| 1539 | input_bytes = cloudpickle.dumps((fn, output_filepath)) |
| 1540 | |
| 1541 | # cannot use `sys.executable __file__` here because the script |
| 1542 | # contains relative imports |
| 1543 | returned = subprocess.run( |
| 1544 | _SUBPROCESS_COMMAND, input=input_bytes, capture_output=True |
| 1545 | ) |
| 1546 | |
| 1547 | # check if the subprocess is successful |
| 1548 | try: |
| 1549 | returned.check_returncode() |
| 1550 | except Exception as e: |
| 1551 | # wrap raised exception to provide more information |
| 1552 | raise RuntimeError( |
| 1553 | f"Error raised in subprocess:\n{returned.stderr.decode()}" |
| 1554 | ) from e |
| 1555 | |
| 1556 | with open(output_filepath, "rb") as f: |
| 1557 | return pickle.load(f) |
| 1558 | |
| 1559 | |
| 1560 | def _run() -> None: |
| 1561 | # Setup plugins |
| 1562 | from vllm.plugins import load_general_plugins |
| 1563 | |
| 1564 | load_general_plugins() |
| 1565 | |
| 1566 | fn, output_file = pickle.loads(sys.stdin.buffer.read()) |
| 1567 | |
| 1568 | result = fn() |
| 1569 | |
| 1570 | with open(output_file, "wb") as f: |
| 1571 | f.write(pickle.dumps(result)) |
| 1572 | |
| 1573 | |
| 1574 | if __name__ == "__main__": |
| 1575 | _run() |