Fix all four scaling multipliers for Granite#48
Open
sdeeptan-aws wants to merge 1 commit intoaws-neuron:mainfrom
Open
Fix all four scaling multipliers for Granite#48sdeeptan-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 Granite-3.1-8b-instruct contrib model to correctly apply all four Granite-specific scaling multipliers. The original implementation only applied
residual_multipliercorrectly —attention_multiplierwas stored but never used,embedding_multiplierwas applied to weights (breaking tied embeddings),logits_scalingwas missing entirely, and manual QKV key renaming in state dict conversion conflicted withpreshard_hook. Fixes include overridingprep_qkv_tensorsto pre-scale Q for the kernel's built-in1/sqrt(head_dim), applyingembedding_multiplierin the forward pass viaget_model_output, addingScaledColumnParallelLinearfor logits scaling, and removing manual key renaming. Achieves 100% token match (64/64 tokens).Model Information
Model Name: Granite-3.1-8b-instruct
Model Architecture: Decoder-only transformer (GQA 32Q/8KV, 32 layers, hidden_size=4096, custom scaling multipliers)
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=2, batch_size=1, seq_len=128, bfloat16. Four Granite-specific scaling multipliers validated:
1/sqrt(head_dim)(0.0884) internally, but Granite usesattention_multiplier(0.0078125 = 1/head_dim). Overrideprep_qkv_tensorsto pre-scale Q byattention_multiplier * sqrt(head_dim)so the kernel's built-in scaling produces the correct result.embedding_multiplier(12.0) toembed_tokens.weightin state dict conversion. Withtie_word_embeddings=True, this also scaleslm_head.weight, producing incorrect logits. Fix: apply in forward pass viaget_model_outputoverride.ScaledColumnParallelLinearthat divides output bylogits_scaling(16.0). Used forlm_headinstead of standardColumnParallelLinear. Original had no logits scaling at all.preshard_hookinGroupQueryAttention_QKVandGroupQueryAttention_O, which already handle the renaming automatically.Test Results:
Compatibility
Tested with:
Additional Information
config.json. The original code stored all four but onlyresidual_multiplierwas applied correctly. Always verify each multiplier is actually used in the code path.1/sqrt(head_dim)internally. To use a different scaling, pre-scale Q with a correction factor:correction = attention_multiplier * sqrt(head_dim).q_proj→qkv_proj.q_proj) and o_proj (o_proj→o_proj.o_proj) key renaming. Manual renaming inconvert_hf_to_neuron_state_dictcauses double-nesting.Related Issues
N/A
vLLM Integration
By submitting this PR, I confirm that: