Add ShardedRMSNorm for Q-K normalization under tensor parallelism#47
Open
sdeeptan-aws wants to merge 1 commit intoaws-neuron:mainfrom
Open
Add ShardedRMSNorm for Q-K normalization under tensor parallelism#47sdeeptan-aws wants to merge 1 commit intoaws-neuron:mainfrom
sdeeptan-aws wants to merge 1 commit intoaws-neuron:mainfrom
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
Updated OLMo-2-1124-7B contrib model with
ShardedRMSNormfor Q-K normalization under tensor parallelism, post-layer normalization architecture (RMSNorm after attention/MLP, not before), and correct Q-K norm placement before head reshape. The critical fix was computing RMSNorm variance over the full hidden dimension (4096) rather than the sharded dimension (512 with TP=8) — naive TP implementation uses an 8x smaller denominator, causing Q/K values to differ by up to 1.64. Achieves 100% token match with TP=8.Model Information
Model Name: OLMo-2-1124-7B
Model Architecture: Decoder-only transformer (~7B params, post-layer RMSNorm, Q-K normalization, RoPE theta=500000)
Purpose: Text generation
Checklist
Required Components
test/integration/test_model.py)src/)Optional Components
Folder Structure
Testing
Model was compiled and tested with TP=8, batch_size=1, seq_len=128, bfloat16. Two key architectural features validated:
ShardedRMSNormcomputes local sum of squares, all-reduces across TP ranks viareduce_from_tensor_model_parallel_region, then divides by the full dimension size. Without this, Q/K values differ by up to 1.64 and accuracy drops to 0%.Test Results:
Compatibility
Tested with:
Additional Information
sum(x²) / 512per rank instead ofsum(x²) / 4096globally — an 8x error in variance.reduce_from_tensor_model_parallel_region: This is XLA-compatible, unlike rawtorch.distributed.all_reduce. Required for correct cross-rank variance computation.[batch, seq, hidden_size]), not per-head. This is what makes TP sharding problematic.Related Issues
N/A
vLLM Integration
By submitting this PR, I confirm that: