Open
Conversation
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.
Description
Add NeuronX Distributed Inference implementation of the Gemma-4 model family. Supports all 4 variants (E2B, E4B, 31B, 26B-A4B) in a single unified
modeling_gemma4.py,handling variable head_dim (256/512), Per-Layer Embeddings (PLE), hybrid sliding/full attention, Q-K-V normalization, attention_k_eq_v, MoE routing (128 experts, top-8),
and logit softcapping. Includes audio (Conformer) and vision (ViT) encoder implementations for multimodal inference.
Model Information
Model Name: Gemma-4 (E2B / E4B / 31B / 26B-A4B)
Model Architecture: Decoder-only transformer (Dense + MoE variants)
Purpose: Text generation (instruction-tuned), multimodal audio/vision understanding
Checklist
Required Components
Accuracy Test (
test/integration/test_model.py)GEMMA4_VARIANTenv var (e2b,e4b,31b,26b)README.md with the following sections:
Source Code (
src/)modeling_gemma4.py— Main model implementation following NxDI patternsgemma4_audio_encoder.py— Conformer-based audio encodergemma4_vision_encoder.py— ViT-based vision encoderOptional Components
Folder Structure
/contrib/models/gemma-4/
README.md
/src
init.py
modeling_gemma4.py
gemma4_audio_encoder.py
gemma4_vision_encoder.py
/test
/unit
/integration
test_model.py
verify_audio.py
verify_image.py
verify_video.py
Testing
How did you test this change?
All 4 variants compiled and tested on trn2.3xlarge (4 Neuron cores, LNC=2) with bfloat16 precision. Each variant validated with text generation prompts for output
coherence and correctness. Multimodal (audio/vision) paths verified separately against HuggingFace CPU (float32) reference outputs.
Test Results:
Compatibility
Tested with:
Additional Information
attn_kernel_enabled=Falseis required — NKI attention kernel does not support head_dim > 128 (Gemma-4 uses 256/512).AutoModeldoes not support Gemma-4 in transformers < 5.5).Related Issues
N/A
vLLM Integration
By submitting this PR, I confirm that: