Skip to content

vllm.model_executor.models.lfm2_siglip2

Implementation of Siglip2VisionModel intended to be only used within a vision language model.

Classes:

Siglip2Attention

Bases: Module

Multi-headed attention from 'Attention Is All You Need' paper.

Siglip2Encoder

Bases: Module

Transformer encoder consisting of config.num_hidden_layers self attention layers. Each layer is a [Siglip2EncoderLayer].

Parameters:

  • config

    (Siglip2VisionConfig) –

    PreTrainedConfig

Siglip2EncoderLayer

Bases: Module

Methods:

forward(hidden_states, cu_seqlens, max_seqlen)

Args: hidden_states: Input tensor of shape (batch, seq_len, embed_dim). cu_seqlens: Cumulative sequence lengths tensor. max_seqlen: Maximum sequence length.

Siglip2Model

Bases: Module

Methods:

  • forward –

    Forward pass through the vision model.

forward(pixel_values_packed, spatial_shapes, cu_seqlens, max_seqlen, select_layers=None)

Forward pass through the vision model.

Parameters:

  • pixel_values_packed

    (FloatTensor) –

    Packed pixel values for all images.

  • spatial_shapes

    (LongTensor) –

    Per-image spatial dimensions.

  • cu_seqlens

    (Tensor) –

    Cumulative sequence lengths of the packed images.

  • max_seqlen

    (Tensor) –

    Longest image sequence in the batch.

  • select_layers

    (list[int] | None, default: None ) –

    Layer indices to select hidden states from. Supports negative indices (e.g., [-2] for second-to-last). If None, returns the last layer output with post_layernorm. Multiple layers can be selected and will be concatenated.

Siglip2VisionEmbeddings

Bases: Module

Methods:

forward(pixel_values_packed, spatial_shapes)

Embed patchified pixel values in packed (unpadded) form.

Parameters:

  • pixel_values_packed

    (FloatTensor) –

    (1, total_tokens, patch_dim) or (total_tokens, patch_dim), packed in tile order.

  • spatial_shapes

    (LongTensor) –

    (num_tiles, 2) on CPU (height, width) per tile.

Returns:

  • Tensor –

    (1, total_tokens, embed_dim) packed embeddings.

resize_positional_embeddings_packed(positional_embeddings, spatial_shapes, lengths_list) staticmethod

Resize positional embeddings per image and return a packed tensor.

Parameters:

  • positional_embeddings

    (Tensor) –

    (height, width, embed_dim) base grid.

  • spatial_shapes

    (LongTensor) –

    (batch_size, 2) on CPU, (height, width) per image.

  • lengths_list

    (list[int]) –

    flattened token length per image (height * width).

Returns:

  • Tensor –

    (total_tokens, embed_dim) packed positional embeddings, concatenated

  • Tensor –

    in the same order as lengths_list.

Siglip2VisionTransformer

Bases: Module

Methods:

  • forward –

    spatial_shapes (torch.LongTensor of shape (batch_size, 2)):

forward(pixel_values_packed, spatial_shapes, cu_seqlens, max_seqlen, select_layers=None)

spatial_shapes (torch.LongTensor of shape (batch_size, 2)): Tensor containing the spatial dimensions (height, width) of the input images. select_layers (list[int] or None, defaults to None): Layer indices to select hidden states from. Supports negative indices (e.g., -1 for last layer, -2 for second-to-last). If None, returns the last layer output.