Add Q-K normalization and scaled embeddings for Gemma-3-1b-it#45
Open
sdeeptan-aws wants to merge 1 commit intoaws-neuron:mainfrom
Open
Add Q-K normalization and scaled embeddings for Gemma-3-1b-it#45sdeeptan-aws wants to merge 1 commit intoaws-neuron:mainfrom
sdeeptan-aws wants to merge 1 commit intoaws-neuron:mainfrom
Conversation
aws-yishanm
approved these changes
Feb 19, 2026
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
Updated Gemma-3-1b-it contrib model with Q-K normalization (RMSNorm applied to Q and K after reshape to heads), scaled embeddings by
sqrt(hidden_size), and 4 RMSNorm layers per decoder block (pre/post for both attention and MLP). The model produces correct, coherent outputs but BF16 precision causes style divergence on open-ended prompts — code completion prompts like"def fibonacci(n):"are deterministic and achieve 100% token match.Model Information
Model Name: Gemma-3-1b-it
Model Architecture: Decoder-only transformer (Q-K normalization, scaled embeddings, 4 RMSNorm per layer)
Purpose: Text generation / instruction following
Checklist
Required Components
test/integration/test_model.py)src/)Optional Components
Folder Structure
Testing
Model was compiled and tested with TP=1, batch_size=1, seq_len=128, bfloat16. Three key architectural features validated:
sqrt(hidden_size)(sqrt(1152) ≈ 33.94). Missing this scaling causes the model to produce incoherent output.input_layernorm,post_attention_layernorm,pre_feedforward_layernorm,post_feedforward_layernorm— unlike standard LLaMA which has 2 norms per layer.Test Results:
Multi-Prompt Accuracy:
Lower-scoring prompts reflect BF16 style divergence — both HF and Neuron produce correct outputs but differ in explanation phrasing when logits are close.
Compatibility
Tested with:
Additional Information
sqrt(hidden_size). This is a Gemma-family convention, not standard in LLaMA-style models.post_attention_layernormandpost_feedforward_layernormare applied to the block output before adding the residual.Related Issues
N/A
vLLM Integration
By submitting this PR, I confirm that: