Skip to content

vllm.model_executor.models.phi4mm

Classes:

Functions:

  • stack_with_pad –

    Stack tensors, padding dimensions that differ across items.

Phi4MMAudioEmbeddingInputs

Bases: TensorSchema

Dimensions: - b: Batch size - n: Number of audios - f: Audio feature size - h: Hidden size (must match language model backbone)

Phi4MMAudioFeatureInputs

Bases: TensorSchema

Dimensions: - bn: Batch size * number of audios - t: Time frames (M)

Phi4MMForCausalLM

Bases: Module, SupportsLoRA, SupportsMultiModal

Implements the Phi-4-multimodal-instruct model in vLLM.

Methods:

_parse_and_validate_audio_input(**kwargs)

Parse and validate the audio input to the model. This handles both audio features and audio embeddings, but only the former is used for now.

Parameters:

  • kwargs

    (object, default: {} ) –

    Keyword arguments.

Returns:

  • Phi4MMAudioInputs | None –

    Optional[Phi4MMAudioInputs]: Parsed and validated audio inputs.

_process_audio_input(audio_input, audio_projection_mode)

Create the audio embeddings from the audio input, where the audio input is pairs of audio features and audio embed lengths. The audio input is created by input_mapper_for_phi4mm_audio.

Parameters:

  • audio_input

    (Phi4MMAudioInputs) –

    Audio input.

  • audio_projection_mode

    (str) –

    Projection mode to use, selecting which audio projector weights are applied.

Returns:

get_mm_mapping()

Get the module prefix in multimodal models.

Phi4MMImageEncoder

Bases: Module

Image embedding.

Methods:

  • forward –

    Process image and return vision embeddings.

forward(pixel_values, image_sizes, image_attention_mask)

Process image and return vision embeddings.

pixel_values: (num_images, num_crops, c, h, w) image_sizes: [[h1, w1], [h2, w2]] image_attention_mask: num_images x num_crops x 32 x 32 output: (num_images, num_img_tokens, hidden_size)

Phi4MMImagePixelInputs

Bases: TensorSchema

Dimensions: - bn: Batch size * number of images - p: Number of patches (1 + num_patches) - c: Number of channels (3) - h: Height of each image patch - w: Width of each image patch - nc: Number of crops - H_mask: Height of attention mask - W_mask: Width of attention mask

Phi4MMProcessingInfo

Bases: BaseProcessingInfo

Methods:

_compute_audio_embed_size(audio_frames)

Compute the audio embedding size based on the audio frames and compression rate.

_compute_num_image_tokens(orig_width, orig_height, dynamic_hd_size, vit_image_size, vit_patch_size, token_compression_factor=2)

Compute the number of tokens an image is expected to take up considering the image encoder architecture and exclude output features containing only padding pixels

for siglip, vit_image_size=448, vit_patch_size=14, so output will be 32x32 feature map NOTE right now, Phi4MM uses hard-coded token_compression_factor=2

get_audio_num_frames(audio_len, sr)

Compute the output size of the extract_features method.

Parameters:

  • audio_len

    (int) –

    Length of the input waveform in samples.

  • sr

    (float) –

    Sampling rate of the waveform, either 16000 or 8000.

Returns:

  • tuple ( (int, int) ) –

    Output size as (T, D), where: T: Number of time frames. D: Number of Mel filterbank bins (80).

stack_with_pad(tensors, padding_value=0)

Stack tensors, padding dimensions that differ across items.