vllm.entrypoints.scale_out.token_in_token_out.mm_features
¶
Helpers for render-time multimodal feature extraction and generate input.
Functions:
-
engine_input_from_features–Build a multimodal engine input from forwarded render features.
-
extract_mm_features–Extract multimodal features from a rendered engine prompt.
-
merge_mm_kwargs_items–Merge full multimodal data with its metadata-only counterpart.
-
mm_kwargs_from_features–Deserialize
featuresinto per-modality kwargs formm_input. -
placeholder_ranges_from_engine_input–Return per-modality placeholder ranges, or
Nonefor text-only prompts. -
validate_feature_bounds–Check placeholder ranges stay within the token-id sequence.
-
validate_metadata_only–Check metadata-only items are only used with EC transfer.
_encode_metadata_items(items, *, declared)
¶
Serialize placeholder-metadata and keep_on_cpu fields per item.
Source code in vllm/entrypoints/scale_out/token_in_token_out/mm_features.py
_encode_mm_kwargs_with_metadata(raw_mm_kwargs, *, metadata_fields_for=None)
¶
Serialize full kwargs and their metadata-only subsets per modality.
Source code in vllm/entrypoints/scale_out/token_in_token_out/mm_features.py
engine_input_from_features(token_ids, features, *, cache_salt=None, mm_cache=None, ec_transfer_params=None)
¶
Build a multimodal engine input from forwarded render features.
Single implementation shared by the generate endpoint and the chat reuse path, performing the validations the generate protocol applies to the same payload:
- Placeholder ranges remain within
token_ids(validate_feature_bounds). - Metadata-only items require
ec_transfer_params(validate_metadata_only). - Deserialized items pass the multimodal processor cache's handle
authentication when a cache is configured. SHM cache handles are
untrusted client input (cf. #59357):
address,monotonic_idandsignaturemust match what this process actually published.
Raises ValueError on the first violation so callers can map it
to an HTTP 400.
Note: the GenerateRequest parse-time validators run these same
two protocol checks when the request body is parsed, so the generate
path validates twice (parse + here). That is intentional and cheap;
do not remove one side — the chat path only has this gate.
Source code in vllm/entrypoints/scale_out/token_in_token_out/mm_features.py
extract_mm_features(engine_input, *, metadata_fields_for=None, include_mm_kwargs=True)
¶
Extract multimodal features from a rendered engine prompt.
Returns None for text-only prompts. mm_metadata keeps the
intersection of processed kwargs that prefill needs after EC transfer:
fields declared as embedding metadata, plus fields marked
keep_on_cpu (for example M-RoPE grid dims). With
include_mm_kwargs=False neither is serialized.
Source code in vllm/entrypoints/scale_out/token_in_token_out/mm_features.py
merge_mm_kwargs_items(kwargs_item, metadata_item)
¶
Merge full multimodal data with its metadata-only counterpart.
Source code in vllm/entrypoints/scale_out/token_in_token_out/mm_features.py
mm_kwargs_from_features(features)
¶
Deserialize features into per-modality kwargs for mm_input.
Source code in vllm/entrypoints/scale_out/token_in_token_out/mm_features.py
placeholder_ranges_from_engine_input(engine_input)
¶
Return per-modality placeholder ranges, or None for text-only prompts.
Source code in vllm/entrypoints/scale_out/token_in_token_out/mm_features.py
validate_feature_bounds(token_ids, features)
¶
Check placeholder ranges stay within the token-id sequence.
Shared by the GenerateRequest parse-time validator and
engine_input_from_features so the two paths cannot drift.
Source code in vllm/entrypoints/scale_out/token_in_token_out/mm_features.py
validate_metadata_only(features, ec_transfer_params)
¶
Check metadata-only items are only used with EC transfer.
A None entry in kwargs_data means the item's embeddings are
expected to arrive through the encoder-cache connector; without
ec_transfer_params the engine has no pixel values and would fail
deep in engine core instead of returning a 400. Shared by the
GenerateRequest parse-time validator and
engine_input_from_features.