Repository navigation
[Model] Support EmbeddingGemma2 multimodal pooling architecture - #60254
Merged
Merged
Conversation
- Register Gemma4Embedding in model registry, arch convertor, and config map for runner=pooling execution.
- Implement Gemma4EmbeddingModel inheriting Gemma4ForConditionalGeneration and VllmModelForPooling with linear embedding_projection head and DispatchPooler.
- Implement Gemma4EmbeddingProcessingInfo bypassing chat template formatting to preserve standard special tokens (<bos>, <eos>) matching SentenceTransformers.
- Support bidirectional attention in Gemma4Attention via EncoderOnlyAttention when use_bidirectional_attention == 'all'.
- Invoke configure_mm_token_handling in Gemma4ForConditionalGeneration to safely mask out-of-vocabulary multimodal tokens (video_token_id >= vocab_size) prior to text embedding lookup.
- Cap block size in triton_prefill_attention for head_dim >= 512 to prevent shared memory overflow.
- Add zero vocab_size_per_layer_input guard for PLE buffer allocation in Gemma4Model.
Signed-off-by: Luciano Martins <lucianommartins@users.noreply.github.com>
lucianommartins
requested review from
AndreasKaratzas,
DarkLight1337,
LucasWilkinson,
MatthewBonanni,
NickLucche,
shen-shanshan,
tjtanaa and
ywang96
as code owners
October 6, 2026 15:37
|
✅ @lucianommartins, CI is now available for this PR.
|
ywang96
approved these changes
Oct 6, 2026
Merged
6 tasks done
Member
|
pre-commit is failing on main because of this PR, could you fix it ASAP? |
6 tasks done
6 tasks done
5 of 6 tasks
6 tasks
6 tasks done
5 of 6 tasks
6 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
[Model] Support EmbeddingGemma 2 (Omni-Modal Embeddings)
Overview
This PR adds support for EmbeddingGemma 2 (
google/embeddinggemma-2), Google's bidirectional omni-modal embedding model. EmbeddingGemma 2 maps text, image, audio, video, and interleaved multimodal inputs into a unified 768-dimensional L2-normalized vector space for cross-modal and multi-modal semantic search, retrieval, and classification.Claims
ENCODER_ONLY) with an inclusive sliding window of 513 tokens (config.sliding_window + 1) and 512-dim rotary embeddings (RoPE) across all layers, matching Hugging Face / SentenceTransformers semantics.--limit-mm-per-prompt(e.g.,image=0,audio=0,video=0). Omitting vision (167.8M params) and audio (305.6M params) loads a lightweight 271.0M param text-only model (~517 MiB VRAM), saving up to 64% VRAM with zero post-load deletion.EmbeddingGemma2VideoBackendtovllm/multimodal/video.py, providing 1 fps uniform sampling up to 32 frames with duplicate-frame expansion for short clips (< 1s), exactly matchingEmbeddingGemma2VideoProcessor.vllm/model_executor/models/embedding_gemma2.pywithout mutating existing generative Gemma 4 model classes (gemma4.py,gemma4_mm.py).Validation
Unit and Parity Tests
All 20 unit and numerical parity tests pass on NVIDIA A100-SXM4-80GB:
CLI Serving Examples
Python API Example
Numerical Parity Test Results
1. Text Embeddings
2. Image Embeddings
3. Audio Embeddings
4. Video Embeddings
5. HuggingFace / SentenceTransformer vs vLLM Parity (16/16 Passed)
Details
Architecture & Key Components
Standalone Model Architecture (
vllm/model_executor/models/embedding_gemma2.py):EmbeddingGemma2Model: Inherits fromnn.Module,SupportsMultiModal, andVllmModelForPooling. Integrates vision and audio modality encoders via_mark_tower_model, language model backbone (EmbeddingGemma2TextModel), and aDispatchPooler.for_embeddingpooling head withMEANpooling and L2 normalization.EmbeddingGemma2Attention: Implements bidirectional attention across all layers usingENCODER_ONLYattention. For sliding-window layers, sets sliding window size toconfig.sliding_window + 1(513) to reconcile Hugging Face's|q - k| <= Wcondition with vLLM's|q - k| < Wencoder attention kernel. Applies full 512-dim RoPE on global attention layers.EmbeddingGemma2TextPLE&EmbeddingGemma2PLEBlock: Per-layer embedding projections matching the checkpoint weight schema.Multimodal Processing & Tokenization:
EmbeddingGemma2ProcessingInfo: Retains standard<bos>and<eos>special tokens without applying chat templates, matching SentenceTransformers.EmbeddingGemma2MultiModalProcessor: Dynamically budgets soft tokens (max_soft_tokens=140per video frame) and suppresses unconditional timestamp prefixing (exclude_timestamps=True). Safely masks multimodal placeholder tokens exceedingvocab_sizebefore embedding lookups.Video Backend (
vllm/multimodal/video.py):EmbeddingGemma2VideoBackendinVIDEO_LOADER_REGISTRY(embedding_gemma2).EmbeddingGemma2VideoProcessor.sample_frames, with support for uniform overflow capping at 32 frames and duplicate frame expansion for short clips (< 1s).Configuration & Attention Capping (
vllm/model_executor/models/config.py,vllm/v1/attention/ops/triton_prefill_attention.py):EmbeddingGemma2ModelConfig: Automatically caps defaultmax_model_lento 8192 (down from the 262k theoretical context) and syncs scheduler token limits while respecting explicit user limits.Upfront Dynamic Modality Loading:
SupportsMultiModallifecycle: when a modality is disabled vialimit_mm_per_prompt(e.g.,image=0,video=0oraudio=0), the corresponding encoder tower is created ontorch.device("meta")and skipped during weight loading. Only active weights are loaded into VRAM.Pull Request Checklist
I used vLLM's
/pr-checklistskill. (Mandatory for agents, optional for humans).AI assistance was used during the creation of this PR.
Design Fit: Minimizes impact on core components, reuses existing functionality, and justifies added complexity.
Testing and Validation: Validates the change and ensures any added tests are meaningful and reliable, with CI coverage or documented CI resource constraints and validation performed outside CI.
Code Quality and Style: Keeps code and comments clear and concise, and updates relevant documentation and examples.
Pull Request Contents: Includes a brief summary and relevant links, supports claims with evidence, explains root causes and implementation trade-offs, and follows the contributing guide.