vllm.model_executor.models.gemma4_unified
¶
Gemma 4 Unified multimodal model (encoder-free image + audio + video).
The Unified Gemma4 variant has no SigLIP vision tower and no audio tower. Raw pixel patches are projected directly to LM space via a Dense+LayerNorm pipeline with factorized 2D positional embeddings (Gemma4UnifiedVisionEmbedder), then routed through the same Gemma4MultimodalEmbedder used by the tower-based variant. Audio inputs are raw waveform frames projected directly through the multimodal embedder.
This module subclasses Gemma4ForConditionalGeneration from gemma4_mm rather than reimplementing it from scratch. Only the multimodal pipeline differs; the language model, MTP integration, bidirectional attention helpers, embedding/forward path, and LoRA support are all inherited unchanged.
Classes:
-
Gemma4ImagePixelInputs–Pre-patchified image inputs from the Gemma4 image processor.
-
Gemma4UnifiedForConditionalGeneration–Encoder-free Gemma4 (Unified) for conditional generation.
-
Gemma4UnifiedProcessingInfo–ProcessingInfo for the Gemma4 Unified variant.
-
Gemma4UnifiedVisionEmbedder–Encoder-free vision embedder for Gemma4 Unified variants.
Gemma4ImagePixelInputs
¶
Bases: TensorSchema
Pre-patchified image inputs from the Gemma4 image processor.
Dimensions
- bn: Batch size * number of images
- np: Number of patches (max_patches = max_soft_tokens * pooling_kernel_size²)
- pp: Patch pixels (patch_size² * 3)
The Gemma4 image processor outputs pixel_values as (batch, max_patches, patch_pixels) — already patchified with zero-padding for patches beyond the real image content. pixel_position_ids provides (x, y) coordinates per patch, with (-1, -1) for padding patches.
Gemma4UnifiedForConditionalGeneration
¶
Bases: Gemma4ForConditionalGeneration
Encoder-free Gemma4 (Unified) for conditional generation.
Inherits multimodal embedding routing, PLE handling, bidirectional
attention helpers, language-model forward, LoRA, and pipeline-parallel
support from Gemma4ForConditionalGeneration. Overrides only:
__init__— builds the encoder-free vision embedder instead of SigLIP/audio towers (LightOnOCR-style:nn.Module.__init__+ full rebuild, nosuper().__init__()).hf_to_vllm_mapper— adds themodel.vision_embedder.prefix._process_image_input/_process_video_input/_process_audio_input— encoder-free projection paths.load_weights— ignore-prefix list excludes the absent towers.get_mm_mapping— no tower entries.
Methods:
-
get_mm_mapping–Module prefix mapping for the encoder-free model (no towers).
_process_audio_input(audio_input)
¶
Project raw waveform-frame features directly to LM space.
No audio tower: the per-frame raw features are passed straight through the multimodal embedder, then padding is stripped.
_vision_chunk(patches_per_item, free_bytes, total_bytes, patch_dim=6912, mm_embed_dim=3840)
staticmethod
¶
Max items (images or video frames) to embed in one batch.
get_mm_mapping()
¶
Module prefix mapping for the encoder-free model (no towers).
Gemma4UnifiedProcessingInfo
¶
Bases: Gemma4ProcessingInfo
ProcessingInfo for the Gemma4 Unified variant.
Two field-name differences from the tower-based parent
- config →
Gemma4UnifiedConfig(notGemma4Config) - vision_config.
num_soft_tokens(notdefault_output_length)
Audio token counts follow raw frames instead of tower subsampling. Audio limits, video frame budget, and parser construction are inherited.
Methods:
-
get_audio_repl–Emit one audio token per raw frame, without tower downsampling.
get_audio_repl(*, audio_len, processor)
¶
Emit one audio token per raw frame, without tower downsampling.
Gemma4UnifiedVisionEmbedder
¶
Bases: Module
Encoder-free vision embedder for Gemma4 Unified variants.
Projects raw pixel patches to LM space via dense projection and factorized 2D positional embeddings. Replaces the SigLIP vision tower used by the tower-based Gemma4 variant.
Pipeline: raw patches → LN₁ → Dense → LN₂ → +factorized_posemb → LN₃.
_factorized_posemb(positions_xy)
¶
Factorized 2D positional embedding lookup: sum of x and y tables.
pos_embedding has shape (max_pos, 2, D). Padding positions (-1) are clamped before indexing and zeroed via mask.