vllm.model_executor.models.transformers.multimodal
¶
Transformers modeling backend mixin for multi-modal models.
Classes:
-
MultiModalMixin– -
MultiModalProcessingInfo– -
MultiModalProcessor–Locates placeholders from the
text_replacement_offsetsthe HF processor
MultiModalMixin
¶
Bases: SupportsMultiModal, SupportsMRoPE, Base
Methods:
-
get_language_model–Transformers modeling backend multimodal classes do not contain a separate
-
get_mm_mapping–Get the module prefix in multimodal models
_decorate_for_torch_compile()
¶
Decorate the model's decoder and encoder classes to indicate to vLLM
that they support torch compile if can_enable_torch_compile and
should_torch_compile_mm_encoder are True respectively.
_find_encoder_classes(model)
¶
Modalities whose encoder cannot be told apart from the model itself are
omitted, as are those get_encoder rejects or has no encoder for.
_init_deepstack(vllm_config)
¶
DeepStack models add extra vision features to the image tokens after each of the first few decoder layers. Transformers selects those tokens with a boolean mask, which CUDA graphs can't capture, so we add the features from a fixed-address buffer instead.
_init_per_layer_inputs(vllm_config)
¶
Per-layer embedding models give each decoder layer an extra embedding of
every token. Transformers looks them up from input_ids, which the model
doesn't receive alongside inputs_embeds, so we look them up in
embed_input_ids and pass them from a fixed-address buffer instead.
_select_item_kwargs(kwargs, index, num_items)
¶
Narrow the entries of kwargs that hold one row per item down to the item
at index. Length is all there is to match on, so an unrelated entry of the
same length is narrowed too.
_set_deepstack_input_embeds(multimodal_embeddings, is_multimodal)
¶
Write the DeepStack features to their buffer, returning the embeddings without them.
_split_deepstack_embeds(multimodal_embeddings)
¶
Split the DeepStack features off multimodal_embeddings.
get_language_model()
¶
Transformers modeling backend multimodal classes do not contain a separate
vLLM language model class. Therefore, in order to return a language model vLLM
class, we use a wrapper to give self the same interface as a text model.
get_mm_mapping()
¶
Get the module prefix in multimodal models
MultiModalProcessingInfo
¶
Bases: BaseProcessingInfo
Methods:
-
get_video_size_with_most_features–Per-frame size that yields the most video tokens.
_audio_samples_per_token
cached
property
¶
Samples behind each audio token, measured on a 60 s audio.
_is_audio_capped
cached
property
¶
Whether long audios stop adding tokens, as n_samples can be a window
that the processor splits them into (e.g. MOSS-Transcribe-Diarize).
_is_long_form_audio_model
cached
property
¶
Whether a whole recording goes through in a single pass.
_prompt_prefix_ids
cached
property
¶
Tokens the HF processor puts before a prompt on top of what its tokenizer adds, such as the BOS that the Emu3 and Molmo2 processors prepend.
_template_placeholders
cached
property
¶
For each modality, the text the chat template writes for one item and the
part of it the HF processor replaces. Both can be more than
<modality>_token: HunYuanVL requires its image start/end markers, and
Qwen3-VL replaces the whole <|vision_start|><|video_pad|><|vision_end|>.
_get_max_audio_length()
¶
Samples the audio processor truncates audios to, or None if it doesn't.
_get_max_long_form_audio_length(seq_len)
¶
Samples of the longest audio that fits in seq_len, set with
--limit-mm-per-prompt, or the longest the API decodes.
_get_placeholder_id(modality)
¶
The placeholder token id, if the placeholder is a single token.
_get_size_candidates(sub_processor, divisors)
¶
Candidate sizes read off a sub-processor's size.
The keys are one of VALID_SIZE_DICT_KEYS, so the bound is either exact
or an area budget, which divisors splits over its items. shortest_edge
bounds only the small side, so it yields no candidate.
longest_edge is read as the area budget Qwen and GLM use it for. A
processor using it as an edge length (SmolVLM) yields a tiny candidate,
which is only chosen if it ties on tokens, so it is still correct.
_get_size_with_most_tokens(candidates, count)
¶
Smallest size found that yields the most tokens.
size bounds the resized output, not the token count, so the candidates
are compared by token count against an arbitrary large fallback, which
tiling processors need. The fallback goes last so a candidate wins a tie.
Resize rounding can give a large input fewer tokens (Qwen2.5-VL), so the
candidates matter for the count, not only for memory.
The winner is then halved while the count holds, so processors with no usable bound aren't profiled on huge dummy inputs.
_trim_to_wrapper(item, matched)
¶
matched with the added token, if any, directly on either side of it
in item, dropping other template text such as roles or item numbers.
get_video_size_with_most_features(num_frames)
¶
Per-frame size that yields the most video tokens.
The video processor's size budget may cover one frame, every frame or
every temporal patch, so all three splits are tried.
MultiModalProcessor
¶
Bases: BaseMultiModalProcessor[MultiModalProcessingInfo]
Locates placeholders from the text_replacement_offsets the HF processor
reports, expressing each one as a PromptUpdate.
Stating the expansion as an update is what lets it be rebuilt from an unexpanded prompt, so this processor takes the base class's processing path and with it the multi-modal processor cache.
_derive_audio_from_video_placeholders(placeholders)
¶
The placeholders for audios folded into videos, which share their span.
_get_hf_mm_inputs(mm_items, hf_kwargs)
¶
Pass the video metadata along to the HF processor.
_get_modality_field_names(modality)
¶
Names of the fields the sub-processor for modality produces.
_get_num_image_patches(hf_inputs, mm_data, num_images)
¶
How many rows of the image fields belong to each image.
Taken from whichever per-image count the processor reports, and checked against the data it has to slice.
_get_num_patches_per_image(mm_data)
¶
Ask the HF processor how many rows of image data each image produces.
_get_prompt_updates(mm_items, hf_processor_mm_kwargs, out_mm_kwargs)
¶
Replace each modality's placeholder token with the token ids that item's replacement text encodes to, marking which of them hold embeddings.
_get_slice_dim(data, total_rows)
¶
Which dimension of a field holds the rows belonging to each item.
Some processors (e.g., Idefics3) return image fields with a leading batch dimension, putting the rows one dimension further in.
_partition_keys_by_modality(keys, modalities)
¶
Attribute each HF processor output key to the modality that produced it.
_unpad_audios(hf_inputs, mm_data, mm_kwargs)
¶
Replace the audio fields with each audio processed on its own.
Processors pad every audio up to the longest in the call, which would leave an item's data dependent on what it was processed with. Unlike images, nothing in the output states how long each one really is, and processors pad a lone audio too, so the only way to know what an audio produces by itself is to process it by itself.
_unpad_images(hf_inputs)
¶
Trim each image back to its own size when the processor padded them all to the largest in the batch.
An image's data has to depend on nothing but that image, or the multi-modal processor cache would store it under that image's hash and later reuse it beside a different neighbour. Padding is re-applied when the encoder runs.
_TemplatePlaceholder
¶
_count_embed_tokens(seqs, placeholder_id=None)
¶
Number of embedding tokens in each item's replacement.
_get_embed_token_id(replacement_ids, placeholder_id=None)
¶
The token an expansion repeats is the one holding the embeddings.