Support local and unfused transformer paths and LoRA - #159
Draft
hazelduan wants to merge 3 commits into
Draft
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.
Summary
config.transformer_implfor decoder, MTP, and Gemma 4 layer specsDotProductAttentionfor the explicit NPUunfusedbackend while retaining TE Linear/Norm modulesColumnParallelLinearandRowParallelLinear, using local parallel adapter layers while retaining the TE implementationRoot cause
Layer-spec construction hard-coded
use_transformer_engine=True, so eventransformer_impl=localproducedTEDotProductAttention.On NPU, the MindSpeed Transformer Engine spec also constructs
TEDotProductAttention -> FlashAttentionfor the explicitunfusedbackend. Disabling the ms-swift flash flag alone was insufficient: the first step still invokedaclnnFlashAttentionScoreV4. The NPU unfused path now replaces only the core attention module with MCoreDotProductAttention, preserving TE Linear/Norm behavior and leaving the GPU spec unchanged.Once true local specs were selected, weight conversion still assumed TE-fused norm parameters (
linear_qkv.layer_norm_weightandlinear_fc1.layer_norm_weight) although local specs exposeinput_layernorm.weightandpre_mlp_layernorm.weight. LoRA dispatch likewise only recognized TE linear classes. These assumptions prevented model loading and adapter injection before training.Validation
dxq, MindSpeed, Megatron Core 0.16.0, BF16, Qwen3-0.6B, a fixed 500-row dataset,padding_free=false, and identical seed/configuration for local and flash runsDotProductAttention, separate local RMSNorms, and MCore parallel linearscheckpoint-100All six valid runs completed 100 optimizer steps. SFT unfused/flash per-step loss correlation was 0.99992 with mean absolute delta 0.00546. GKD unfused/flash total-loss correlation was 0.99912 with mean absolute delta 0.00197; JSD-loss correlation was 0.99419. The GKD runs executed separate student and frozen-teacher forwards on every step and logged total loss, JSD loss, SFT loss, and grad norm.
The A3 image required test-only import shims for unused optional
acl/FLA paths; these are not repository changes. A separate Qwen3-30B-A3B teacher attempt reached local MoE construction but exposed an existing unsupportedMindSpeedGmmExpertsgrouped-weight loading layout. The controlled dense student/teacher comparison above keeps the test focused on the spec, weight, and LoRA changes in this PR.Paired PR: modelscope/ms-swift#9864