Skip to content

vllm.model_executor.models.mistral3

Classes:

Mistral3ForConditionalGeneration

Bases: Module, SupportsLoRA, SupportsMultiModal, SupportsPP, SupportsEagle, SupportsEagle3, PixtralEncoderCudaGraphMixin

Methods:

  • forward –

    Run forward pass for Mistral3.

  • get_mm_mapping –

    Get the module prefix in multimodal models.

forward(input_ids, positions, intermediate_tensors=None, inputs_embeds=None, **kwargs)

Run forward pass for Mistral3.

One key thing to understand is the input_ids already accounts for the positions of the to-be-inserted image embeddings.

Concretely, consider a text prompt: "USER: <image>\nWhat's the content of the image?\nASSISTANT:".

Tokenizer outputs: [1, 3148, 1001, 29901, 29871, 32000, 29871, 13, 5618, 29915, 29879, 278, 2793, 310, 278, 1967, 29973, 13, 22933, 9047, 13566, 29901].

To reserve space in KV cache, we have to insert placeholder tokens before they are inputted to the model, so the input processor prepends additional image tokens (denoted as 32000), resulting in: [1, 3148, 1001, 29901, 29871, 32000, ..., 32000, 29871, 13, 5618, 29915, 29879, 278, 2793, 310, 278, 1967, 29973, 13, 22933, 9047, 13566, 29901].

We insert 575 tokens so that including the original image token in the input, there are a total of 576 (24 * 24) image tokens, which corresponds to the number of image tokens inputted to the language model, i.e. the number of image tokens outputted by the visual encoder.

This way, the positions and attn_metadata are consistent with the input_ids.

Parameters:

  • input_ids

    (Tensor | None) –

    Flattened (concatenated) input_ids corresponding to a batch.

  • positions

    (Tensor) –

    Position indices for the input tokens.

  • intermediate_tensors

    (IntermediateTensors | None, default: None ) –

    Intermediate tensors from prior forward pass.

  • inputs_embeds

    (Tensor | None, default: None ) –

    Optional tensor of input embeddings.

  • **kwargs

    (object, default: {} ) –

    Multimodal inputs for this batch, forwarded to the multimodal embedding path.

Info

Mistral3ImagePixelInputs

get_mm_mapping()

Get the module prefix in multimodal models.

Mistral3ImageEmbeddingInputs

Bases: TensorSchema

Projected features with shape (num_images, feature_size, hidden_size).

Mistral3ImagePixelInputs

Bases: TensorSchema

Dimensions: - bn: Batch size * number of images - c: Number of channels (3) - h: Height of each image - w: Width of each image

Mistral3PatchMerger

Bases: Module

Learned merging of spatial_merge_size ** 2 patches.

Methods:

  • forward_packed –

    Same as forward, gathering blocks with _make_merge_indices

forward_packed(image_features, merge_indices)

Same as forward, gathering blocks with _make_merge_indices (None when spatial_merge_size is 1).

_get_num_hidden_layers(hf_config)

Determine the number of hidden layers to initialize up to in the visual encoder.

Parameters:

  • hf_config

    (Mistral3Config) –

    Model config with vision feature layer(s).