Repository navigation
[Model] Add Gemma4 Unified (encoder-free) support - #44429
Conversation
|
Documentation preview: https://vllm--44429.org.readthedocs.build/en/44429/ |
|
Hi @lucianommartins, the pre-commit checks have failed. Please run: uv pip install pre-commit>=4.5.1
pre-commit install
pre-commit run --all-filesThen, commit the changes and push to your branch. For future commits, Tip Is
|
| torch.tensor(config.hidden_size**0.5), | ||
| torch.tensor( | ||
| config.hidden_size**0.5, | ||
| dtype=self.embed_tokens.weight.dtype, |
There was a problem hiding this comment.
Can you use a different dtype source here? If embed_tokens is quantized, then "weight" won't exist right. Same problem I found in #44340
| # Only quantize towers when the quant method supports their | ||
| # dimensions. BNB/torchao handle arbitrary sizes; other methods | ||
| # (Marlin, FP8, …) require dimensions divisible by 64, which | ||
| # the vision tower (intermediate_size=4304) does not satisfy. | ||
| if quant_config and quant_config.get_name() in [ | ||
| "bitsandbytes", | ||
| "torchao", | ||
| ]: | ||
| tower_quant = quant_config | ||
| else: | ||
| vision_cfg = config.vision_config | ||
| quantizable = ( | ||
| vision_cfg.hidden_size % 64 == 0 | ||
| and vision_cfg.intermediate_size % 64 == 0 | ||
| ) | ||
| tower_quant = quant_config if quantizable else None |
There was a problem hiding this comment.
We should add this padding support to the quant methods rather than specializing specific quant configs like this, this is a kernel limitation not a checkpoint limitation. If the checkpoint is quantized but we say the layers aren't quantized, then the model will be incorrectly loading weights. We should instead mark those layers in the ignore list in the checkpoint format i.e. compressed-tensors
| if mm_feature.modality == "audio": | ||
| continue |
There was a problem hiding this comment.
Will this affect the previous gemma4-with-audio behavior? Maybe worth testing E2B on audio quickly
| for pv, pp in zip(pixel_values, pixel_position_ids, strict=True): | ||
| pv = pv.unsqueeze(0) | ||
| pp = pp.unsqueeze(0) | ||
| embedded = self.vision_embedder(pv, pp) | ||
| projected = self.embed_vision(embedded.to(target_dtype)) | ||
| padding_mask = (pp.squeeze(0) == -1).all(dim=-1) | ||
| valid_features = projected.squeeze(0)[~padding_mask] | ||
| per_image_features.append(valid_features) |
There was a problem hiding this comment.
perf nit: for both image and video we are looping one image/frame at a time through the vision embedder, one forward per item. we should consider batching in the future
| ) | ||
| if config.audio_config is not None | ||
| else None | ||
| ) |
There was a problem hiding this comment.
These are constructed without quant_config where it is passed through in gemma4_mm, so it could be supported the same way I think. If intentional should note
- Add Gemma4UnifiedForConditionalGeneration as a subclass of Gemma4ForConditionalGeneration, following the (nn.Module.__init__ + full rebuild, no super().__init__) pattern - Encoder-free vision: Gemma4UnifiedVisionEmbedder projects raw pixel patches to LM space via Dense+LayerNorm with factorized 2D positional embeddings, replacing the SigLIP vision tower - Encoder-free audio: raw 16kHz waveform frames projected directly through Gemma4MultimodalEmbedder, no conformer audio tower - Subclassed Gemma4UnifiedProcessingInfo with num_soft_tokens field mapping (unified uses num_soft_tokens, tower-based uses default_output_length) - Register Gemma4UnifiedForConditionalGeneration in model registry, config map, arch config convertor, and spec decode proposer - Add suppress_tokens support from generation_config in both target (gemma4_mm.py) and drafter (gemma4_mtp.py) compute_logits to prevent stray audio/image token generation - Map gemma4_unified_assistant to Gemma4MTPModel for speculative decoding with shared KV cache - Handle attention_k_eq_v with num_global_key_value_heads in MTP drafter decoder layers for full-attention layers - Restore bidi sliding-window guard in gpu_model_runner.py and add audio modality skip for bidirectional attention ranges - Use SigLIP-style quantization check for vision/audio towers: BNB/torchao always quantize, others require dimensions divisible by 64 - Inline audio token count computation to remove dependency on transformers processor internals - Add processing tests for unified image schema, soft-token caps, prompt updates, and limit_mm_per_prompt - Update supported models docs and MTP speculative decoding docs ) Signed-off-by: Luciano Martins <lucianommartins@users.noreply.github.com>
0f206d9 to
f39dc8e
Compare
- Add Gemma4UnifiedForConditionalGeneration as a subclass of
Gemma4ForConditionalGeneration, following the
(nn.Module.__init__ + full rebuild, no super().__init__) pattern
- Encoder-free vision: Gemma4UnifiedVisionEmbedder projects raw pixel
patches to LM space via Dense+LayerNorm with factorized 2D positional
embeddings, replacing the SigLIP vision tower
- Encoder-free audio: raw 16kHz waveform frames projected directly
through Gemma4MultimodalEmbedder, no conformer audio tower
- Subclassed Gemma4UnifiedProcessingInfo with num_soft_tokens field
mapping (unified uses num_soft_tokens, tower-based uses
default_output_length)
- Register Gemma4UnifiedForConditionalGeneration in model registry,
config map, arch config convertor, and spec decode proposer
- Add suppress_tokens support from generation_config in both target
(gemma4_mm.py) and drafter (gemma4_mtp.py) compute_logits to prevent
stray audio/image token generation
- Map gemma4_unified_assistant to Gemma4MTPModel for speculative
decoding with shared KV cache
- Handle attention_k_eq_v with num_global_key_value_heads in MTP
drafter decoder layers for full-attention layers
- Restore bidi sliding-window guard in gpu_model_runner.py and add
audio modality skip for bidirectional attention ranges
- Use SigLIP-style quantization check for vision/audio towers:
BNB/torchao always quantize, others require dimensions divisible
by 64
- Inline audio token count computation to remove dependency on
transformers processor internals
- Add processing tests for unified image schema, soft-token caps,
prompt updates, and limit_mm_per_prompt
- Update supported models docs and MTP speculative decoding docs
Signed-off-by: Luciano Martins <lucianommartins@users.noreply.github.com>
|
hey @mgoin @ywang96 @zifeitong - the only failed test was the Llama TP+SP (sequence parallelism) test with Ray -- unrelated to this PR. can we go ahead and merge it? |
|
When audio requests are batched together I obtain an error. input_features_padded is a list, but |
…rride Smoke test on 4x L4 caught it: v0.22.1 has no native gemma-4-12B implementation and silently falls back to the generic Transformers multimodal backend, which crashes under tensor parallelism and would misrepresent the 12B in single-GPU comparisons. Native support merged in vllm-project/vllm#44429 (nightly only). The registry can now pin a per-model image; gemma-4-12b overrides to nightly until the next stable release. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…rride Smoke test on 4x L4 caught it: v0.22.1 has no native gemma-4-12B implementation and silently falls back to the generic Transformers multimodal backend, which crashes under tensor parallelism and would misrepresent the 12B in single-GPU comparisons. Native support merged in vllm-project/vllm#44429 (nightly only). The registry can now pin a per-model image; gemma-4-12b overrides to nightly until the next stable release.
Signed-off-by: Luciano Martins <lucianommartins@users.noreply.github.com> Co-authored-by: Luciano Martins <lucianommartins@users.noreply.github.com>
Signed-off-by: Luciano Martins <lucianommartins@users.noreply.github.com> Co-authored-by: Luciano Martins <lucianommartins@users.noreply.github.com>
Summary
Adds
Gemma4UnifiedForConditionalGenerationsupport for the encoder-free Gemma 4 12B model family. Unlike the tower-based Gemma 4 variants (E2B, E4B, 26B-A4B, 31B), the unified variant has no vision encoder and no audio encoder: raw pixel patches and audio waveform frames are projected directly into LM space.Architecture
Gemma4UnifiedForConditionalGenerationsubclassesGemma4ForConditionalGenerationusing thenn.Module.__init__+ full rebuild pattern (same approach asLightOnOCRForConditionalGeneration), keeping the parent class free of encoder-free branchingGemma4UnifiedVisionEmbedderreplaces the vision tower with aDense+LayerNormpipeline and factorized 2D positional embeddingsGemma4MultimodalEmbedderwith no conformer audio towerGemma4UnifiedProcessingInfosubclassesGemma4ProcessingInfoto handle thenum_soft_tokensvsdefault_output_lengthfield mappingChanges
vllm/model_executor/models/gemma4_unified.py(466 lines) withGemma4UnifiedVisionEmbedder,Gemma4UnifiedProcessingInfo, andGemma4UnifiedForConditionalGenerationsuppress_tokensfromgeneration_configapplied incompute_logitsattention_k_eq_v+num_global_key_value_headshandling for full-attention MTP decoder layers;suppress_tokensapplied in draftercompute_logits;gemma4_unified_assistantmapped toGemma4MTPModelGemma4UnifiedForConditionalGenerationregistered in model registry, config map, arch config convertor, and spec decode proposersupported_models.mdandmtp.mdwith unified variant and 12B assistant modelDuplicate-work check
No existing PR addresses Gemma 4 Unified / encoder-free support. This is the initial implementation of
Gemma4UnifiedForConditionalGenerationin vLLM.Test commands and results