vllm.model_executor.models.phi4mm
¶
Classes:
-
Phi4MMAudioEmbeddingInputs–Dimensions:
-
Phi4MMAudioFeatureInputs–Dimensions:
-
Phi4MMForCausalLM–Implements the Phi-4-multimodal-instruct model in vLLM.
-
Phi4MMImageEncoder–Image embedding.
-
Phi4MMImagePixelInputs–Dimensions:
-
Phi4MMProcessingInfo–
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
¶
Phi4MMForCausalLM
¶
Bases: Module, SupportsLoRA, SupportsMultiModal
Implements the Phi-4-multimodal-instruct model in vLLM.
Methods:
-
get_mm_mapping–Get the module prefix in multimodal models.
_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:
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:
-
NestedTensors(NestedTensors) –Audio embeddings
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:
-
get_audio_num_frames–Compute the output size of the
extract_featuresmethod.
_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
stack_with_pad(tensors, padding_value=0)
¶
Stack tensors, padding dimensions that differ across items.