Fix state dict mapping and add partial RoPE for Phi-1.5#43
Open
sdeeptan-aws wants to merge 1 commit intoaws-neuron:mainfrom
Open
Fix state dict mapping and add partial RoPE for Phi-1.5#43sdeeptan-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 Phi-1.5 contrib model with custom state dict conversion mapping HuggingFace weight names to NeuronX's
NeuronAttentionBasenaming convention, partial rotary embeddings (partial_rotary_factor=0.5), and parallel residual architecture. The model has several unique architectural features compared to modern LLMs: HF Phi uses flat weight names (q_proj) but NeuronX expects wrapped names (qkv_proj.q_proj), only 50% of head dimensions receive RoPE, and attention + MLP compute in parallel from the same LayerNorm output. Validation achieves 100% token match on best prompts.Model Information
Model Name: Phi-1.5
Model Architecture: Decoder-only transformer (1.3B params, partial RoPE, parallel residual, GELU, LayerNorm)
Purpose: Text generation / code generation
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. Three key architectural features validated:
self_attn.q_proj), NeuronX expects wrapped names (self_attn.qkv_proj.q_proj). Also renamesdense→o_proj.o_projandfinal_layernorm→norm. Without this, weights were silently dropped ("Removing redundant keys" warning) causing 26% accuracy.partial_rotary_factor=0.5— only first 32 of 64 head dimensions receive RoPE. Q/K split into rotary and pass-through parts, RoPE applied to first half, then concatenated back.input_layernormper layer (nopost_attention_layernorm).Test Results:
Multi-Prompt Accuracy:
Lower-scoring prompts reflect expected BF16 precision divergence on longer generation sequences, not implementation errors.
Compatibility
Tested with:
Additional Information
NeuronAttentionBasewraps projections inGroupQueryAttention_QKV, creating names likeqkv_proj.q_proj.weight. HF Phi usesq_proj.weightdirectly. The "Removing redundant keys" warning during loading indicates weight name mismatch, not extra weights.nn.LayerNorm, not RMSNorm.Related Issues
N/A
vLLM Integration
By submitting this PR, I confirm that: