Skip to content

Support local and unfused transformer paths and LoRA - #159

Draft
hazelduan wants to merge 3 commits into
modelscope:mainfrom
hazelduan:gkd_dxq
Draft

Support local and unfused transformer paths and LoRA#159
hazelduan wants to merge 3 commits into
modelscope:mainfrom
hazelduan:gkd_dxq

Conversation

@hazelduan

@hazelduan hazelduan commented Aug 6, 2026

Copy link
Copy Markdown

Summary

  • derive Transformer Engine selection from config.transformer_impl for decoder, MTP, and Gemma 4 layer specs
  • replace MindSpeed TE flash core with MCore DotProductAttention for the explicit NPU unfused backend while retaining TE Linear/Norm modules
  • map input and pre-MLP norm weights to the actual fused TE or separate local-spec module layout
  • dispatch LoRA to MCore ColumnParallelLinear and RowParallelLinear, using local parallel adapter layers while retaining the TE implementation
  • add regression tests for spec selection, norm mapping, and local LoRA dispatch

Root cause

Layer-spec construction hard-coded use_transformer_engine=True, so even transformer_impl=local produced TEDotProductAttention.

On NPU, the MindSpeed Transformer Engine spec also constructs TEDotProductAttention -> FlashAttention for the explicit unfused backend. Disabling the ms-swift flash flag alone was insufficient: the first step still invoked aclnnFlashAttentionScoreV4. The NPU unfused path now replaces only the core attention module with MCore DotProductAttention, 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_weight and linear_fc1.layer_norm_weight) although local specs expose input_layernorm.weight and pre_mlp_layernorm.weight. LoRA dispatch likewise only recognized TE linear classes. These assumptions prevented model loading and adapter injection before training.

Validation

  • pre-commit hooks and Python byte-compilation passed for all changed files
  • A3 regression tests: 6 passed (spec selection, NPU unfused core selection, local/TE norm mappings, and local linear LoRA dispatch)
  • A3 validation used SSH user 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 runs
  • actual local model structure used MCore DotProductAttention, separate local RMSNorms, and MCore parallel linears
  • every successful run completed 100 optimizer steps, kept loss/grad metrics finite, and saved checkpoint-100
Path Backend Steps Mean loss Last-10 mean loss Final cumulative s/it End-to-end wall time
SFT + LoRA local 100 1.31381 1.04523 0.10189 45 s
SFT + LoRA flash/TE 100 1.30809 1.04592 0.07201 42 s
SFT + LoRA unfused 100 1.30841 1.04521 0.10207 54 s
GKD + LoRA, independent frozen teacher local 100 0.16752 0.15426 0.10990 45 s
GKD + LoRA, independent frozen teacher flash/TE 100 0.16662 0.15193 0.08711 43 s
GKD + LoRA, independent frozen teacher unfused 100 0.16602 0.15295 0.10008 45 s

All 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 unsupported MindSpeedGmmExperts grouped-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

@hazelduan hazelduan changed the title Respect transformer implementation in layer specs Support local transformer specs, weights, and LoRA Aug 6, 2026
@hazelduan hazelduan changed the title Support local transformer specs, weights, and LoRA Support local and unfused transformer paths and LoRA Aug 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant