vllm.model_executor.models.vision
¶
Classes:
-
InterpolatedPosEmbedCache–Pre-allocated per-module cache for interpolated positional embeddings.
Functions:
-
get_fp8_padded_hidden_size–Return the padded hidden size for FP8 ViT encoder attention, or
-
get_load_balance_assignment–Generate load balancing assignment and metadata
-
get_multimodal_config–Return the current
MultiModalConfig, orNonewhen no engine -
get_vit_attn_backend–Get the attention backend for Vision Transformer.
-
interpolate_cls_abs_pos–Bicubic-interpolate 2-D patch embeddings while keeping a leading CLS token.
-
is_vit_use_data_parallel–Get the tensor parallel type for Vision Transformer.
-
resolve_visual_encoder_outputs–Given the outputs a visual encoder module that may correspond to the
-
run_dp_sharded_mrope_vision_model–Run a vision model with data parallelism (DP) sharding.
-
run_dp_sharded_vision_model–Run a vision model with data parallelism (DP) sharding. The function
InterpolatedPosEmbedCache
¶
Bases: Module
Pre-allocated per-module cache for interpolated positional embeddings.
Allocates a fixed non-persistent byte buffer at module initialization so
its memory footprint is accounted for during model loading and profiling
with zero growth during inference. Safe across weight loading/reloads
(process_weights_after_loading), encoder graph capture (refreshes slots
in place and never evicts live slots), and torch.compile (bypasses cache).
Methods:
-
refresh–Refresh cached entries in place after weights are loaded or updated.
refresh(weight, compute_fn)
¶
Refresh cached entries in place after weights are loaded or updated.
_get_vit_attn_backend(head_size, dtype, *, attn_backend_override=None)
¶
Get the available attention backend for Vision Transformer.
get_fp8_padded_hidden_size(num_heads, head_dim)
¶
Return the padded hidden size for FP8 ViT encoder attention, or
None when FP8 is not enabled.
cuDNN FP8 prefill attention requires head_dim to be a multiple of
16. For non-aligned head_dim (e.g. 72), Q/K/V are padded to the
nearest multiple of 16.
get_load_balance_assignment(sizes, num_gpus=2)
¶
get_multimodal_config()
¶
Return the current MultiModalConfig, or None when no engine
config context is active (e.g., during unit tests) or when the current
model_config does not carry a multimodal_config (e.g., minimal
stubs used in tests).
get_vit_attn_backend(head_size, dtype)
¶
Get the attention backend for Vision Transformer.
interpolate_cls_abs_pos(abs_pos, tgt_grid)
¶
Bicubic-interpolate 2-D patch embeddings while keeping a leading CLS token.
is_vit_use_data_parallel(num_heads=None)
¶
Get the tensor parallel type for Vision Transformer.
resolve_visual_encoder_outputs(encoder_outputs, post_layer_norm, *, select_layers=None, max_possible_layers=None, last_hs_proc=None, feature_select_strategy=None)
¶
Given the outputs a visual encoder module that may correspond to the output of the last layer, or a list of hidden states to be stacked, handle post normalization and resolve it into a single output tensor.
Parameters:
-
(encoder_outputs¶Tensor | list[Tensor]) –Output of encoder's last layer or all hidden states.
-
(post_layer_norm¶LayerNorm | None) –Post norm to apply to the output of the encoder.
-
(select_layers¶list[int] | None, default:None) –Optional layer indices to grab from the encoder outputs; if provided, encoder outputs must be a list.
-
(max_possible_layers¶int | None, default:None) –Total layers in the fully loaded visual encoder.
-
(last_hs_proc¶Callable[[Tensor], Tensor] | None, default:None) –Optional callable to be applied to the last layer if it is used, e.g., pooling head for Siglip. This is done prior to feature selection and layer normalization. If select_layers are provided, the output of last_hs_proc must be able to be concatenated with the other select_layers along the last dimension.
-
(feature_select_strategy¶VisionFeatureSelectStrategy | None, default:None) –Defines how to select the hidden states from each layer.
run_dp_sharded_mrope_vision_model(vision_model, pixel_values, grid_thw_list, *, rope_type)
¶
Run a vision model with data parallelism (DP) sharding. The function will shard the input image tensor on the first dimension and run the vision model. This function is used to run the vision model with mrope.
Parameters:
-
(vision_model¶Module) –Vision model.
-
(pixel_values¶Tensor) –Image/Video input tensor.
-
(grid_thw_list¶list[list[int]]) –List of grid dimensions for each image
-
(rope_type¶Literal['rope_3d', 'rope_2d']) –Type of rope used in the vision model. Different rope types have different dimension to do ViT. "rope_3d" for 3D rope (e.g., Qwen2.5-VL) "rope_2d" for 2D rope (e.g., Kimi-VL)
Returns: