Skip to content

vllm.model_executor.models.idefics2_vision_model

PyTorch Idefics2 model.

Classes:

Idefics2Encoder

Bases: Module

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

Parameters:

  • config

    (Idefics2Config) –

    Idefics2Config

Methods:

forward(inputs_embeds, attention_mask=None, varlen=None)

inputs_embeds (torch.Tensor): Optionally, instead of passing input_ids you can choose to directly pass an embedded representation. This is useful if you want more control over how to convert input_ids indices into associated vectorsthan the model's internal embedding lookup matrix.

Idefics2EncoderLayer

Bases: Module

Methods:

forward(hidden_states, attention_mask=None, varlen=None)

hidden_states (torch.FloatTensor): Input to the layer of shape (batch, seq_len, embed_dim).

Idefics2VarlenMetadata dataclass

Methods:

  • pack –

    Packs the valid tokens of a padded (B, L, D) batch into (1, N, D).

  • unpack –

    Unpacks a packed (1, N, D) tensor into a padded (B, L, D) tensor.

pack(hidden_states)

Packs the valid tokens of a padded (B, L, D) batch into (1, N, D).

unpack(packed)

Unpacks a packed (1, N, D) tensor into a padded (B, L, D) tensor.

Idefics2VisionAttention

Bases: Module

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

Idefics2VisionEmbeddings

Bases: Module

This is a modified version of siglip.modelign_siglip.SiglipVisionEmbeddings to enable images of variable resolution.

The modifications are adapted from Patch n' Pack: NaViT, a Vision Transformer for any Aspect Ratio and Resolution which allows treating images in their native aspect ratio and without the need to resize them to the same fixed size. In particular, we start from the original pre-trained SigLIP model(which uses images of fixed-size square images) and adapt it by training on images of variable resolutions.

Idefics2VisionTransformer

Bases: Module

Methods:

Attributes:

prefer_varlen_attention property

Whether to prefer varlen attention over masked SDPA.

FlashAttention backends are faster than masked SDPA when using varlen attention while Triton varlen attention is slower.

get_varlen_metadata(patch_mask)

Returns None if no token is padded.