vllm.model_executor.models.interfaces ¶
Classes:
-
DiarizedTranscriptionSegment–A timestamped, speaker-attributed segment produced by an ASR model.
-
HasInnerState–The interface required for all models that has inner state.
-
IsAttentionFree–The interface required for all models like Mamba that lack attention,
-
IsHybrid–The interface required for all models like Jamba that have both
-
LocalArgmaxMixin–Mixin for draft model heads in speculative decoding.
-
MixtureOfExperts–Check if the model is a mixture of experts (MoE) model.
-
StreamingTranscriptionPostProcessor–Stateful streaming post-processor for transcription deltas.
-
SupportsCrossEncoding–The interface required for all models that support cross encoding.
-
SupportsEagle–The interface required for models that support
-
SupportsEagle3–The interface required for models that support
-
SupportsEagleBase–Base interface for models that support EAGLE-based speculative decoding.
-
SupportsEncoderCudaGraph–Interface for models whose vision encoder supports CUDA graph
-
SupportsLateInteraction–The interface required for all models that support late interaction.
-
SupportsLoRA–The interface required for all models that support LoRA.
-
SupportsMRoPE–The interface required for all models that support M-RoPE.
-
SupportsMambaPrefixCaching–The interface for models whose mamba layers support prefix caching.
-
SupportsMultiModal–The interface required for all multi-modal models.
-
SupportsMultiModalEmbeddings–The interface for models that can merge external multimodal embeddings.
-
SupportsMultiModalPruning–The interface required for models that support returning both input
-
SupportsPP–The interface required for all models that support pipeline parallel.
-
SupportsQuant–The interface required for all models that support quantization.
-
SupportsRealtime–The interface required for all models that support transcription.
-
SupportsReplaySSM–The interface for models whose recurrent layers support ReplaySSM
-
SupportsScoreTemplate–The interface required for all models that support score template.
-
SupportsTranscription–The interface required for all models that support transcription.
Functions:
-
get_mixture_of_experts_model–Return the MixtureOfExperts contained within an arbitrary model.
-
supports_any_eagle–Check if model supports any EAGLE variant (1, 2, or 3).
Attributes:
-
MultiModalEmbeddings(TypeAlias) –The output embeddings must be one of the following formats:
MultiModalEmbeddings = list[Tensor] | Tensor | tuple[Tensor, ...] module-attribute ¶
The output embeddings must be one of the following formats:
- A list or tuple of 2D tensors, where each tensor corresponds to each input multimodal data item (e.g, image).
- A single 3D tensor, with the batch dimension grouping the 2D tensors.
DiarizedTranscriptionSegment dataclass ¶
A timestamped, speaker-attributed segment produced by an ASR model.
Source code in vllm/model_executor/models/interfaces.py
HasInnerState ¶
Bases: Protocol
The interface required for all models that has inner state.
Attributes:
-
has_inner_state(Literal[True]) –A flag that indicates this model has inner state.
Source code in vllm/model_executor/models/interfaces.py
has_inner_state = True class-attribute ¶
A flag that indicates this model has inner state. Models that has inner state usually need access to the scheduler_config for max_num_seqs, etc. True for e.g. both Mamba and Jamba.
IsAttentionFree ¶
Bases: Protocol
The interface required for all models like Mamba that lack attention, but do have state whose size is constant wrt the number of tokens.
Attributes:
-
is_attention_free(Literal[True]) –A flag that indicates this model has no attention.
Source code in vllm/model_executor/models/interfaces.py
is_attention_free = True class-attribute ¶
A flag that indicates this model has no attention. Used for block manager and attention backend selection. True for Mamba but not Jamba.
IsHybrid ¶
Bases: Protocol
The interface required for all models like Jamba that have both attention and mamba blocks, indicates that hf_config has 'layers_block_type'
Methods:
-
get_mamba_state_copy_func–Calculate copy-function callables for each Mamba state.
-
get_mamba_state_shape_from_config–Calculate shapes for Mamba's convolutional and state caches.
Attributes:
Source code in vllm/model_executor/models/interfaces.py
is_hybrid = True class-attribute ¶
A flag that indicates this model has both mamba and attention blocks , also indicates that the model's hf_config has 'layers_block_type'
get_mamba_state_copy_func() classmethod ¶
Calculate copy-function callables for each Mamba state.
Returns:
-
MambaStateCopyFunc–A tuple of MambaStateCopyFunc callables that correspond, in order,
-
...–to the Mamba states produced by the model. Each callable accepts
-
tuple[MambaStateCopyFunc, ...]–(state, block_ids, cur_block_idx, num_accepted_tokens) and returns
-
tuple[MambaStateCopyFunc, ...]–a MambaCopySpec describing the memory-copy parameters for prefix
-
tuple[MambaStateCopyFunc, ...]–caching in align mode.
Source code in vllm/model_executor/models/interfaces.py
get_mamba_state_shape_from_config(vllm_config) classmethod ¶
Calculate shapes for Mamba's convolutional and state caches.
Parameters:
-
(vllm_config¶VllmConfig) –vLLM config
Returns:
-
MambaStateShapes–Shapes for each state cache used by the model.
Source code in vllm/model_executor/models/interfaces.py
LocalArgmaxMixin ¶
Mixin for draft model heads in speculative decoding.
Provides a D2T-aware get_top_tokens that preserves the local-argmax communication reduction even when the draft vocabulary is smaller than the target vocabulary.
When draft_id_to_target_id is present (shape (draft_vocab_size,), containing per-token offset to target vocab id), the draft argmax index k is mapped to the target vocab id via::
target_id = k + draft_id_to_target_id[k]
This is mathematically equivalent to computing the full-vocab scatter logits and taking the global argmax, but requires only O(batch * 2 * tp_size) communication instead of O(batch * vocab_size).
Requires the subclass to expose
self.logits_processor: LogitsProcessor self.lm_head: ParallelLMHead self.draft_id_to_target_id (optional): nn.Parameter
Methods:
-
get_top_tokens–Vocab-parallel argmax with optional D2T remapping.
Source code in vllm/model_executor/models/interfaces.py
get_top_tokens(hidden_states) ¶
Vocab-parallel argmax with optional D2T remapping.
Source code in vllm/model_executor/models/interfaces.py
MixtureOfExperts ¶
Bases: Protocol
Check if the model is a mixture of experts (MoE) model.
Methods:
-
set_eplb_state–Register the EPLB state in the MoE model.
Attributes:
-
expert_weights(MutableSequence[Sequence[Tensor]]) –Expert weights saved in this rank.
-
moe_layers(Sequence[MoERunner]) –List of MoE layers in this model.
-
num_expert_groups(int) –Number of expert groups in this model.
-
num_local_physical_experts(int) –Number of local physical experts in this model.
-
num_logical_experts(int) –Number of logical experts in this model.
-
num_moe_layers(int) –Number of MoE layers in this model.
-
num_physical_experts(int) –Number of physical experts in this model.
-
num_redundant_experts(int) –Number of redundant experts in this model.
-
num_routed_experts(int) –Number of routed experts in this model.
-
num_shared_experts(int) –Number of shared experts in this model.
Source code in vllm/model_executor/models/interfaces.py
1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 | |
expert_weights instance-attribute ¶
Expert weights saved in this rank.
The first dimension is the layer, and the second dimension is different parameters in the layer, e.g. up/down projection weights.
moe_layers instance-attribute ¶
List of MoE layers in this model.
num_expert_groups instance-attribute ¶
Number of expert groups in this model.
num_local_physical_experts instance-attribute ¶
Number of local physical experts in this model.
num_logical_experts instance-attribute ¶
Number of logical experts in this model.
num_moe_layers instance-attribute ¶
Number of MoE layers in this model.
num_physical_experts instance-attribute ¶
Number of physical experts in this model.
num_redundant_experts instance-attribute ¶
Number of redundant experts in this model.
num_routed_experts instance-attribute ¶
Number of routed experts in this model.
num_shared_experts instance-attribute ¶
Number of shared experts in this model.
set_eplb_state(expert_load_view, logical_to_physical_map, logical_replica_count) ¶
Register the EPLB state in the MoE model.
Since these are views of the actual EPLB state, any changes made by the EPLB algorithm are automatically reflected in the model's behavior without requiring additional method calls to set new states.
You should also collect model's expert_weights here instead of in the weight loader, since after initial weight loading, further processing like quantization may be applied to the weights.
Parameters:
-
(expert_load_view¶Tensor) –A view of the expert load metrics tensor.
-
(logical_to_physical_map¶Tensor) –Mapping from logical to physical experts.
-
(logical_replica_count¶Tensor) –Count of replicas for each logical expert.
Source code in vllm/model_executor/models/interfaces.py
StreamingTranscriptionPostProcessor ¶
Stateful streaming post-processor for transcription deltas.
Source code in vllm/model_executor/models/interfaces.py
SupportsCrossEncoding ¶
Bases: Protocol
The interface required for all models that support cross encoding.
Source code in vllm/model_executor/models/interfaces.py
SupportsEagle ¶
Bases: SupportsEagleBase, Protocol
The interface required for models that support EAGLE-1 and EAGLE-2 speculative decoding.
Attributes:
-
supports_eagle(Literal[True]) –A flag that indicates this model supports EAGLE-1 and EAGLE-2
Source code in vllm/model_executor/models/interfaces.py
supports_eagle = True class-attribute ¶
A flag that indicates this model supports EAGLE-1 and EAGLE-2 speculative decoding.
Note
There is no need to redefine this flag if this class is in the MRO of your model class.
SupportsEagle3 ¶
Bases: SupportsEagleBase, Protocol
The interface required for models that support EAGLE-3 speculative decoding.
Methods:
-
get_eagle3_default_aux_hidden_state_layers–Get the default layer indices that should output auxiliary hidden states
-
set_aux_hidden_state_layers–Set which layers should output auxiliary hidden states for EAGLE-3.
Attributes:
-
supports_eagle3(Literal[True]) –A flag that indicates this model supports EAGLE-3
Source code in vllm/model_executor/models/interfaces.py
supports_eagle3 = True class-attribute ¶
A flag that indicates this model supports EAGLE-3 speculative decoding.
Note
There is no need to redefine this flag if this class is in the MRO of your model class.
get_eagle3_default_aux_hidden_state_layers() ¶
Get the default layer indices that should output auxiliary hidden states for EAGLE-3 for this model. Models can override this method to provide different default layers based on their architecture, but it is encouraged to instead include the layer specification in the model's config if possible.
Returns:
Source code in vllm/model_executor/models/interfaces.py
set_aux_hidden_state_layers(layers) ¶
Set which layers should output auxiliary hidden states for EAGLE-3.
Parameters:
Source code in vllm/model_executor/models/interfaces.py
SupportsEagleBase ¶
Bases: Protocol
Base interface for models that support EAGLE-based speculative decoding.
Attributes:
-
has_own_embed_tokens(bool) –A flag that indicates this model has trained its own input embeddings.
-
has_own_lm_head(bool) –A flag that indicates this model has trained its own lm_head.
Source code in vllm/model_executor/models/interfaces.py
SupportsEncoderCudaGraph ¶
Bases: Protocol
Interface for models whose vision encoder supports CUDA graph capture/replay.
Models implement these methods to provide the :class:EncoderCudaGraphManager with all model-specific logic (input handling, metadata computation, forward pass) without the manager needing to know model internals.
Methods:
-
encoder_cudagraph_forward–Run the encoder forward pass with precomputed buffers.
-
encoder_eager_forward–Run the encoder forward pass without precomputed buffers.
-
get_encoder_cudagraph_budget_range–Return (min_token_budget, max_token_budget) for auto-inference.
-
get_encoder_cudagraph_item_specs–Return specs describing each item in the batch.
-
get_input_modality–Return the modality of the inputs (default: image-only).
-
get_max_frames_per_video–Return model-specific max frames per video.
-
postprocess_encoder_output–Post-process encoder output, directly call scatter_output_slices by default.
-
prepare_encoder_cudagraph_capture_inputs–Create dummy inputs and buffers for CUDA graph capture.
-
prepare_encoder_cudagraph_replay_buffers–Compute buffer values from actual batch inputs for replay.
-
select_encoder_cudagraph_items–Select a subset of items and return mm_kwargs for the sub-batch.
Source code in vllm/model_executor/models/interfaces.py
1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 | |
encoder_cudagraph_forward(inputs, path='default') ¶
Run the encoder forward pass with precomputed buffers.
Used during both CUDA graph capture and replay.
Source code in vllm/model_executor/models/interfaces.py
encoder_eager_forward(mm_kwargs, path='default') ¶
Run the encoder forward pass without precomputed buffers.
Used as eager fallback when inputs exceed all budgets.
Source code in vllm/model_executor/models/interfaces.py
get_encoder_cudagraph_budget_range(vllm_config) ¶
Return (min_token_budget, max_token_budget) for auto-inference.
- min_token_budget: estimated smallest possible encoder input (e.g. 64 for a 224x224 image)
- max_token_budget: estimated largest budget worth capturing (e.g. max_num_batched_tokens)
Used when encoder_cudagraph_token_budgets and/or encoder_cudagraph_max_vision_items_per_batch are not explicitly specified by the user.
Source code in vllm/model_executor/models/interfaces.py
get_encoder_cudagraph_item_specs(mm_kwargs) ¶
Return specs describing each item in the batch.
Replaces the former separate methods for num_items, per_item_output_tokens, and per_item_input_sizes. The manager derives all three from this single return value.
Source code in vllm/model_executor/models/interfaces.py
get_input_modality(mm_kwargs) ¶
get_max_frames_per_video() ¶
postprocess_encoder_output(outputs, indices, per_item_out_tokens, dest, clone=False, batch_mm_kwargs=None) ¶
Post-process encoder output, directly call scatter_output_slices by default.
By default, delegates directly to scatter_output_slices. Override this for models that require additional processing on the raw encoder output prior to scattering, e.g. Step3-VL, which merges features according to dynamic patch counts before scattering.
Source code in vllm/model_executor/models/interfaces.py
prepare_encoder_cudagraph_capture_inputs(token_budget, max_batch_size, max_frames_per_batch, device, dtype, path='default', axis_keys=None) ¶
Create dummy inputs and buffers for CUDA graph capture.
Parameters:
-
(axis_keys¶tuple[Hashable, ...] | None, default:None) –The resolved capture-axis keys (one per axis of
EncoderCudaGraphConfig.capture_axes) this capture is for. None or empty when no capture axes are configured; models without capture axes ignore it.
Source code in vllm/model_executor/models/interfaces.py
prepare_encoder_cudagraph_replay_buffers(mm_kwargs, max_batch_size, max_frames_per_batch, path='default') ¶
Compute buffer values from actual batch inputs for replay.
Source code in vllm/model_executor/models/interfaces.py
select_encoder_cudagraph_items(mm_kwargs, indices) ¶
Select a subset of items and return mm_kwargs for the sub-batch.
Called by the manager during greedy packing and DP sharding to extract inputs for a specific set of items (e.g. images at indices [0, 3, 5]). The implementation is model-specific because input formats differ:
- Qwen-family: slice concatenated pixel_values by cumulative patch offsets, subset grid_thw by indices.
- Batched models (CLIP): index pixel_values along dim 0.
Models that configure EncoderCudaGraphConfig.capture_axes must additionally store the resolved per-axis keys (one key per axis, in order) under ENCODER_CUDAGRAPH_AXIS_KEYS_KWARG in the returned dict; the manager pops it before the kwargs are used elsewhere.
Source code in vllm/model_executor/models/interfaces.py
SupportsLateInteraction ¶
Bases: Protocol
The interface required for all models that support late interaction.
Late interaction models (like ColBERT) encode queries and documents separately into per-token embeddings, then compute similarity via MaxSim (max over document tokens, sum over query tokens).
Source code in vllm/model_executor/models/interfaces.py
SupportsLoRA ¶
Bases: Protocol
The interface required for all models that support LoRA.
Attributes:
-
supports_lora(Literal[True]) –A flag that indicates this model supports LoRA.
Source code in vllm/model_executor/models/interfaces.py
supports_lora = True class-attribute ¶
A flag that indicates this model supports LoRA.
Note
There is no need to redefine this flag if this class is in the MRO of your model class.
SupportsMRoPE ¶
Bases: Protocol
The interface required for all models that support M-RoPE.
Methods:
-
get_mrope_input_positions–Get M-RoPE input positions and delta value for this specific model.
Attributes:
-
supports_mrope(Literal[True]) –A flag that indicates this model supports M-RoPE.
Source code in vllm/model_executor/models/interfaces.py
supports_mrope = True class-attribute ¶
A flag that indicates this model supports M-RoPE.
Note
There is no need to redefine this flag if this class is in the MRO of your model class.
get_mrope_input_positions(input_tokens, mm_features) ¶
Get M-RoPE input positions and delta value for this specific model.
This method should be implemented by each model that supports M-RoPE to provide model-specific logic for computing input positions.
Parameters:
-
(input_tokens¶list[int]) –List of input token IDs
-
(mm_features¶list[MultiModalFeatureSpec]) –Information about each multi-modal data item
Returns:
-
llm_positions(Tensor) –Tensor of shape
[num_dims, num_tokens], one row per M-RoPE position channel (e.g. T/H/W). -
mrope_position_delta(int) –Delta for position calculations.
Source code in vllm/model_executor/models/interfaces.py
SupportsMambaPrefixCaching ¶
Bases: Protocol
The interface for models whose mamba layers support prefix caching.
This is currently experimental.
Methods:
-
get_mamba_state_copy_func–Return copy functions for the model's Mamba states.
-
get_mamba_state_copy_funcs–Map legacy copy functions to each requested Mamba backend.
Source code in vllm/model_executor/models/interfaces.py
get_mamba_state_copy_func() classmethod ¶
get_mamba_state_copy_funcs(mamba_types) classmethod ¶
Map legacy copy functions to each requested Mamba backend.
Source code in vllm/model_executor/models/interfaces.py
SupportsMultiModal ¶
Bases: SupportsMultiModalEmbeddings, Protocol
The interface required for all multi-modal models.
Methods:
-
configure_mm_token_handling–Check if any multimodal tokens are out of vocabulary. If so, we will
-
embed_input_ids–Apply token embeddings to
input_ids. -
embed_multimodal–Returns multimodal embeddings generated from multimodal kwargs
-
get_language_model–Returns the underlying language model used for text generation.
-
get_mm_lora_token_counts–Return
(tower_tokens, connector_tokens)for multimodal LoRA mappings. -
get_num_mm_connector_tokens–Implement this function to enable LoRA support
-
get_num_mm_encoder_tokens–Implement this function to enable LoRA support
-
get_placeholder_str–Get the placeholder text for the
ithmodalityitem in the prompt.
Attributes:
-
requires_raw_input_tokens(bool) –A flag that indicates this model processes input id tokens
-
supports_encoder_tp_data(bool) –A flag that indicates whether this model supports
-
supports_mm_device_do_normalize(bool) –A flag that indicates whether this model supports
-
supports_multimodal(Literal[True]) –A flag that indicates this model supports multi-modal inputs.
-
supports_multimodal_raw_input_only(bool) –A flag that indicates this model supports multi-modal inputs and processes
-
supports_tower_connector_lora(bool) –A flag that indicates whether this model supports
Source code in vllm/model_executor/models/interfaces.py
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 | |
_has_oov_mm_tokens = False class-attribute instance-attribute ¶
In general, this should be set at init time by invoking configure_mm_token_handling models & passing all potentially OOV multimodal tokens.
_language_model_names = [] class-attribute instance-attribute ¶
Set internally by _mark_language_model.
_processor_factory class-attribute ¶
Set internally by MultiModalRegistry.register_processor.
_tower_model_names = [] class-attribute instance-attribute ¶
Set internally by _mark_tower_model.
requires_raw_input_tokens = False class-attribute ¶
A flag that indicates this model processes input id tokens in their raw form and not input embeddings.
supports_encoder_tp_data = False class-attribute ¶
A flag that indicates whether this model supports multimodal_config.mm_encoder_tp_mode="data".
supports_mm_device_do_normalize = False class-attribute ¶
A flag that indicates whether this model supports multimodal_config.mm_device_do_normalize.
supports_multimodal = True class-attribute ¶
A flag that indicates this model supports multi-modal inputs.
Note
There is no need to redefine this flag if this class is in the MRO of your model class.
supports_multimodal_raw_input_only = False class-attribute ¶
A flag that indicates this model supports multi-modal inputs and processes them in their raw form and not embeddings.
supports_tower_connector_lora = False class-attribute ¶
A flag that indicates whether this model supports lora_config.enable_tower_connector_lora.
_mark_composite_model(vllm_config, *, language_targets, tower_targets) ¶
Composite wrapper over _mark_language_model and _mark_tower_model by modality.
Source code in vllm/model_executor/models/interfaces.py
_mark_language_model(vllm_config, *, targets=None) ¶
Mark each child module that was assigned to this model during this context as a language model component.
Language model components are automatically skipped in --mm-encoder-only mode.
If targets is set, instead include descendants that are an instance of targets, even if they aren't direct children.
Source code in vllm/model_executor/models/interfaces.py
_mark_tower_model(vllm_config, modalities, *, targets=None) ¶
Mark each child module that was assigned to this model during this context as a tower model component.
Tower model components are automatically skipped when --limit-mm-per-prompt is set to zero for all of their modalities.
If targets is set, instead include descendants that are an instance of targets, even if they aren't direct children.
Marked components are also routed through the active offloader (when it supports tower offloading), since make_layers only ever sees the decoder layer stack.
Source code in vllm/model_executor/models/interfaces.py
configure_mm_token_handling(vocab_size, mm_token_ids) ¶
Check if any multimodal tokens are out of vocabulary. If so, we will explicitly mask all multimodal tokens out when computing text embeddings, since the multimodal embeddings will be scattered over the results.
Source code in vllm/model_executor/models/interfaces.py
embed_input_ids(input_ids, multimodal_embeddings=None, *, is_multimodal=None) ¶
Apply token embeddings to input_ids.
If multimodal_embeddings is passed, scatter them into input_ids according to the mask is_multimodal.
NOTE: If this model has multimodal tokens that are of vocabulary (i.e., self._has_oov_mm_tokens=True), the input_ids will be copied and masked to 0 during the forward pass for the text embeddings.
Source code in vllm/model_executor/models/interfaces.py
embed_multimodal(**kwargs) ¶
Returns multimodal embeddings generated from multimodal kwargs to be merged with text embeddings.
Note
The returned multimodal embeddings must be in the same order as the appearances of their corresponding multimodal data item in the input prompt.
Source code in vllm/model_executor/models/interfaces.py
get_language_model() ¶
Returns the underlying language model used for text generation.
This is typically the torch.nn.Module instance responsible for processing the merged multimodal embeddings and producing hidden states
Returns:
-
VllmModel–torch.nn.Module: The core language model component.
Source code in vllm/model_executor/models/interfaces.py
get_mm_lora_token_counts(*, modality, mm_kwargs, num_mm_embeds) ¶
Return (tower_tokens, connector_tokens) for multimodal LoRA mappings.
MM LoRA uses these counts to build adapter mappings for the tower and connector forwards. Models with multiple modalities can override this when each modality has different encoder padding or pooling behavior.
Source code in vllm/model_executor/models/interfaces.py
get_num_mm_connector_tokens(num_vision_tokens) ¶
Implement this function to enable LoRA support for the connector module of the multi-modal model. Given the number of vision tokens, output the number of multi-modal connector tokens.
Source code in vllm/model_executor/models/interfaces.py
get_num_mm_encoder_tokens(num_image_tokens) ¶
Implement this function to enable LoRA support for the tower module of the multi-modal model. Given the number of image tokens, output the number of multi-modal encoder tokens.
Source code in vllm/model_executor/models/interfaces.py
get_placeholder_str(modality, i) classmethod ¶
Get the placeholder text for the ith modality item in the prompt.
SupportsMultiModalEmbeddings ¶
Bases: Protocol
The interface for models that can merge external multimodal embeddings.
Source code in vllm/model_executor/models/interfaces.py
SupportsMultiModalPruning ¶
Bases: Protocol
The interface required for models that support returning both input embeddings and positions. Model may require custom positions for dynamic pruning of multimodal embeddings.
Methods:
-
recompute_mrope_positions–Update part of input mrope positions (starting with
Attributes:
-
supported_video_pruning_methods(tuple[VideoPruningMethod, ...]) –Video pruning methods (as reported by
Source code in vllm/model_executor/models/interfaces.py
supported_video_pruning_methods = ('evs',) class-attribute ¶
Video pruning methods (as reported by MultiModalConfig.get_video_pruning_spec) implemented by this model. Models supporting methods beyond EVS should override this.
recompute_mrope_positions(input_ids, multimodal_embeddings, mrope_positions, num_computed_tokens) ¶
Update part of input mrope positions (starting with num_computed_tokens index). Original mrope_positions are computed for unpruned sequence and becomes incorrect once pruning occurs, so once we prune media tokens we should reflect this in the mrope_positions before we feed it to LLM.
Parameters:
-
(input_ids¶list[int] | Tensor) –(N,) All input tokens of the prompt containing entire sequence. Either a host-side list or an already device-resident tensor.
-
(multimodal_embeddings¶Sequence[Tensor]) –Sequence of multimodal embeddings that fits into the prefill chunk that is being processed.
-
(mrope_positions¶LongTensor) –Existing mrope positions (3, N) for entire sequence
-
(num_computed_tokens¶int) –A number of computed tokens so far.
Returns:
-
tuple[Sequence[Tensor], Tensor, int]–Tuple of (multimodal_embeddings, mrope_positions, mrope_position_delta).
Source code in vllm/model_executor/models/interfaces.py
SupportsPP ¶
Bases: Protocol
The interface required for all models that support pipeline parallel.
Methods:
-
forward–Accept
IntermediateTensorswhen
Attributes:
-
make_empty_intermediate_tensors(_MakeEmptyIntermediateTensors) –Called when PP rank > 0 for profiling purposes.
-
supports_pp(Literal[True]) –A flag that indicates this model supports pipeline parallel.
Source code in vllm/model_executor/models/interfaces.py
make_empty_intermediate_tensors instance-attribute ¶
Called when PP rank > 0 for profiling purposes.
supports_pp = True class-attribute ¶
A flag that indicates this model supports pipeline parallel.
Note
There is no need to redefine this flag if this class is in the MRO of your model class.
forward(input_ids, positions, *, intermediate_tensors) ¶
Accept IntermediateTensors when PP rank > 0.
Return IntermediateTensors only for the last PP rank.
Source code in vllm/model_executor/models/interfaces.py
SupportsQuant ¶
The interface required for all models that support quantization.
Source code in vllm/model_executor/models/interfaces.py
_find_quant_config(*args, **kwargs) staticmethod ¶
Find quant config passed through model constructor args
Source code in vllm/model_executor/models/interfaces.py
_maybe_apply_model_mapping() ¶
Apply model mappings to config for proper config-model matching
Source code in vllm/model_executor/models/interfaces.py
SupportsRealtime ¶
Bases: Protocol
The interface required for all models that support transcription.
Attributes:
-
realtime_max_tokens(int) –Maximum tokens to generate per streaming audio segment.
Source code in vllm/model_executor/models/interfaces.py
realtime_max_tokens = 1 class-attribute ¶
Maximum tokens to generate per streaming audio segment. Override in subclasses based on the model's expected output length.
SupportsReplaySSM ¶
Bases: Protocol
The interface for models whose recurrent layers support ReplaySSM cached decode.
This is currently experimental.
Source code in vllm/model_executor/models/interfaces.py
SupportsScoreTemplate ¶
Bases: Protocol
The interface required for all models that support score template.
Methods:
-
get_score_template–Generate a full prompt by populating the score template with query and document content.
-
post_process_tokens–Perform architecture-specific manipulations on the input tokens.
Attributes:
-
supports_score_template(Literal[True]) –A flag that indicates this model supports score template.
Source code in vllm/model_executor/models/interfaces.py
supports_score_template = True class-attribute ¶
A flag that indicates this model supports score template.
Note
There is no need to redefine this flag if this class is in the MRO of your model class.
get_score_template(query, document) classmethod ¶
Generate a full prompt by populating the score template with query and document content.
post_process_tokens(prompt) classmethod ¶
SupportsTranscription ¶
Bases: Protocol
The interface required for all models that support transcription.
Methods:
-
get_generation_prompt–Get the prompt for the ASR model.
-
get_language_detection_prompt–Return a prompt that triggers language detection.
-
get_language_token_ids–Return token IDs that represent valid language tokens.
-
get_num_audio_tokens–Map from audio duration to number of audio tokens produced by the ASR
-
get_speech_to_text_config–Get the speech to text config for the ASR model.
-
get_streaming_post_processor_cls–Return a stateful post-processor class for streaming output deltas.
-
parse_diarized_transcript–Parse the model-specific diarized transcript format.
-
parse_language_detection_output–Parse the detected language from model output token IDs.
-
post_process_output–Post-process the raw model output text.
-
validate_language–Ensure the language specified in the transcription request
Attributes:
-
no_space_languages(set[str]) –Languages that don't need a space between words.
-
supports_diarized_transcription(bool) –Enables the
diarized_jsonresponse format for the model. -
supports_explicit_language_detection(bool) –Transcription models that require an explicit language detection step
-
supports_segment_timestamp(bool) –Enables the segment timestamp option for supported models by setting this to
True. -
supports_transcription_only(bool) –Transcription models can opt out of text generation by setting this to
Source code in vllm/model_executor/models/interfaces.py
1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 | |
no_space_languages = {'ja', 'zh'} class-attribute ¶
Languages that don't need a space between words. For example, Japanese (ja) and Chinese (zh) don't need a space between words.
supports_diarized_transcription = False class-attribute ¶
Enables the diarized_json response format for the model.
supports_explicit_language_detection = False class-attribute ¶
Transcription models that require an explicit language detection step (e.g. Whisper needs a separate forward pass to predict the language token) should set this to True and implement :meth:get_language_detection_prompt and :meth:parse_language_detection_output and :meth:get_language_token_ids.
supports_segment_timestamp = False class-attribute ¶
Enables the segment timestamp option for supported models by setting this to True.
supports_transcription_only = False class-attribute ¶
Transcription models can opt out of text generation by setting this to True.
get_generation_prompt(stt_params) classmethod ¶
Get the prompt for the ASR model. The model has control over the construction, as long as it returns a valid PromptType.
Source code in vllm/model_executor/models/interfaces.py
get_language_detection_prompt(audio, stt_config) classmethod ¶
Return a prompt that triggers language detection.
Only needs to be implemented when supports_explicit_language_detection is True.
Source code in vllm/model_executor/models/interfaces.py
get_language_token_ids(tokenizer) classmethod ¶
Return token IDs that represent valid language tokens.
Used to constrain language detection to only produce valid language tokens.
Only needs to be implemented when supports_explicit_language_detection is True.
Source code in vllm/model_executor/models/interfaces.py
get_num_audio_tokens(audio_duration_s, stt_config, model_config) classmethod ¶
Map from audio duration to number of audio tokens produced by the ASR model, without running a forward pass. This is used for estimating the amount of processing for this audio.
Source code in vllm/model_executor/models/interfaces.py
get_speech_to_text_config(model_config, task_type) classmethod ¶
Get the speech to text config for the ASR model.
get_streaming_post_processor_cls() classmethod ¶
Return a stateful post-processor class for streaming output deltas.
Each instance receives the next decoded text delta and whether the request output is final. It returns the cleaned delta that should be sent to the client.
Source code in vllm/model_executor/models/interfaces.py
parse_diarized_transcript(text) classmethod ¶
Parse the model-specific diarized transcript format.
Only models that set supports_diarized_transcription must override this method.
Source code in vllm/model_executor/models/interfaces.py
parse_language_detection_output(token_ids, tokenizer) classmethod ¶
Parse the detected language from model output token IDs.
Only needs to be implemented when supports_explicit_language_detection is True.
Source code in vllm/model_executor/models/interfaces.py
post_process_output(text) classmethod ¶
Post-process the raw model output text.
Some ASR models output structured formats (e.g., language tags, special tokens) that need to be stripped before returning to the user.
Parameters:
Returns:
-
str–Cleaned transcription text.
Source code in vllm/model_executor/models/interfaces.py
validate_language(language) classmethod ¶
Ensure the language specified in the transcription request is a valid ISO 639-1 language code. If the request language is valid, but not natively supported by the model, trigger a warning (but not an exception).
Source code in vllm/model_executor/models/interfaces.py
_require_is_multimodal(is_multimodal) ¶
A helper function to be used in the context of vllm.model_executor.models.interfaces.SupportsMultiModal.embed_input_ids to provide a better error message.
Source code in vllm/model_executor/models/interfaces.py
get_mixture_of_experts_model(model) ¶
Return the MixtureOfExperts contained within an arbitrary model.
- If the model itself is a MixtureOfExperts, return the model directly.
- If the model is a multi-modal model, and its
language_modelis a MixtureOfExperts, return thelanguage_model. - If neither, return None.
Parameters:
Returns:
-
MixtureOfExperts | None–The MixtureOfExperts instance contained within the model, or None.
Source code in vllm/model_executor/models/interfaces.py
supports_any_eagle(model) ¶
Check if model supports any EAGLE variant (1, 2, or 3).