Skip to content

refactor(moe): restore local MoE composition and consolidate auxiliary losses - #1677

Merged
github-actions[bot] merged 1 commit into
mindspore-ai:masterfrom
Er1ckPang:refactor/moe_1124
Nov 28, 2026
Merged

github-actions[bot] merged 1 commit into
mindspore-ai:masterfrom
Er1ckPang:refactor/moe_1124

Conversation

@Er1ckPang

@Er1ckPang Er1ckPang commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Paired: GitHub #1677 ↔ GitCode !2045

What type of PR is this?

/kind refactor

What does this PR do / why do we need it:

  • Restore the local MoE layer by composing GateModule, GroupedExpertsModule, and an optional SharedExpertModule directly from their configurations.
  • Consolidate router load-balancing losses and gradient scaling in hyper_parallel.components.losses.aux_loss. Move the four public scaling helpers from functional to losses and update callers and documentation. Keep the Qwen3-MoE token-choice objective alongside the sequence-level objective.
  • Bring in the related MoE changes from refactor: migrate model integration to module families #1652. Place score-corrected grouped top-k routing in router.py and expose SwiGLU precision and clamp settings for packed expert sources while preserving the default grouped GEMM path.
  • Let ChunkedCausalLMLoss bind a compatible native model head and optionally shift raw labels together with their loss mask when context parallelism is disabled.
  • Track the DeepSeek V4.1 recipes and TP router metadata separately in refactor: migrate DeepSeek V4.1 training recipes to module families #1683.

Which issue(s) this PR fixes:

Related to RFC #1593 and continues the MoE and EP module-family work in #1644.

What scenarios were tested, and what were the verification results(Function, performance, reliability, etc.):

  • GitHub gate #2348 passed on the same code tree before the commit message update. The run passed 51 x86 smoke cases, 49 Ascend smoke cases, and 9,289 unit tests. Full and incremental line coverage were 80% and 48%.
  • The Windows CPU regression passed 194 unit tests and 438 subtests across auxiliary loss, routing, expert parallelism, and VeRL. The local run used import stubs for optional native extensions. The remote gate exercised Ascend hardware.
  • Verified FP32 and BF16 token-choice loss values and gradients before and after migration with no mask, partial masks, and fully masked inputs. Also verified the new import paths, native chunked-loss binding, label and mask alignment, and the context-parallelism guard.

Self-checklist:(Please check carefully,and mark an x in the [] brackets. We will review your completion status.)

  • Design: Has the solution corresponding to the PR been reviewed by the Maintainer, and have all review comments been replied to and revised
  • Test: Has the code in the PR been fully covered by UT/ST test cases, and have the newly added test cases been uploaded to the repository along with this PR or already uploaded.
  • Verification: Does the PR description contains a detailed description of the verification results regarding the achievement of the expected goals for the Feature, Refactor, and Bugfix to this PR.
  • Interface: Does it involve changes to external interfaces? The corresponding changes have been approved by the interface review organization, and the annotation information for the API has been correctly refreshed.
  • Document: Does it involve modifications to the official website documentation? If so, please submit the materials to the Doc repository in a timely manner.

@Er1ckPang Er1ckPang changed the title refactor(moe): restore family composition and reorganize module helpers refactor(moe): restore the module-family MoE composition Nov 25, 2026
@Er1ckPang Er1ckPang changed the title refactor(moe): restore the module-family MoE composition refactor(moe): restore composition and consolidate auxiliary loss Nov 25, 2026
@Er1ckPang
Er1ckPang force-pushed the refactor/moe_1124 branch 4 times, most recently from 4d12dff to 487419a Compare November 26, 2026 08:42
@Er1ckPang Er1ckPang changed the title refactor(moe): restore composition and consolidate auxiliary loss refactor(moe): 恢复本地 MoE 组合并统一辅助损失入口 Nov 26, 2026
@Er1ckPang
Er1ckPang force-pushed the refactor/moe_1124 branch 2 times, most recently from a51953e to c6a8942 Compare November 26, 2026 13:18
@Er1ckPang

Copy link
Copy Markdown
Contributor Author

/check-pr

@Er1ckPang

Copy link
Copy Markdown
Contributor Author

/retest

@mindspore-ai-bot

Copy link
Copy Markdown

🔵 The pipeline #2302 is running. Please wait a moment... (Link)

@mindspore-ai-bot

Copy link
Copy Markdown
Platform Type Module Excution Time Time Limit
- distributed_data 347.388s 450.0s
- activation_memory 310.696s 375.0s
- auto_models 82.461s 150.0s
- shard 140.739s 300.0s
- pipeline_parallel 477.932s 675.0s
- swap_optimizer 245.729s 300.0s
- optimizer 205.801s 300.0s
- accuracy 65.322s 120.0s
- fully_shard 275.101s 600.0s
- expert_parallel 214.51462s 200.0s
- clip_grad 65.557s 120.0s
- tensor_parallel 189.887s 300.0s
- init_weights 56.511s 118.75s
- distributed_checkpoint 65.279s 120.0s
- context_parallel 64.323s 240.0s
- dtensor 64.858s 120.0s
- process_group 50.618s 90.0s
- llama3_examples 50.319s 120.0s
- ops 2.57112s 150.0s

@mindspore-ai-bot

Copy link
Copy Markdown
Project Name Build_Stage Build Result Details
Hyper-parallel_Github_Gate - ❌ FAILURE 2302
Smoke_CPU_X86_CentOS_Level0 FAILURE 2302

@Er1ckPang

Copy link
Copy Markdown
Contributor Author

/retest

@mindspore-ai-bot

Copy link
Copy Markdown

🔵 The pipeline #2305 is running. Please wait a moment... (Link)

@mindspore-ai-bot

Copy link
Copy Markdown
Project Name Build_Stage Build Result Details(Full/Incremental) Detail
Coverage Line Coverage ❌ FAILURE 21%/22% Link

@mindspore-ai-bot

Copy link
Copy Markdown
Platform Type Module Excution Time Time Limit
- distributed_data 413.11s 450.0s
- activation_memory 401.597s 400.0s
- shard 223.673s 300.0s
- pipeline_parallel 679.155s 675.0s
- clip_grad 115.746s 120.0s
- optimizer 357.339s 300.0s
- fully_shard 411.675s 600.0s
- accuracy 120.531s 120.0s
- auto_models 126.425s 150.0s
- swap_optimizer 376.521s 375.0s
- tensor_parallel 300.554s 300.0s
- expert_parallel 288.03788s 200.0s
- llama3_examples 105.159s 120.0s
- context_parallel 100.169s 240.0s
- distributed_checkpoint 110.719s 120.0s
- process_group 110.407s 90.0s
- init_weights 89.685s 118.75s
- dtensor 95.06s 120.0s
- multicore 3.77312s 120.0s
- ops 3.42625s 150.0s

@mindspore-ai-bot

Copy link
Copy Markdown
Project Name Build_Stage Build Result Details
Hyper-parallel_Github_Gate - ❌ FAILURE 2329
Smoke_Ascend910b_Torch FAILURE 2329
Smoke_CPU_X86_CentOS_Level0 FAILURE 2329

@Er1ckPang

Copy link
Copy Markdown
Contributor Author

/check-pr

@Er1ckPang

Copy link
Copy Markdown
Contributor Author

/retest

@mindspore-ai-bot

Copy link
Copy Markdown

🔵 The pipeline #2348 is running. Please wait a moment... (Link)

@mindspore-ai-bot

Copy link
Copy Markdown
Project Name Build_Stage Build Result Details(Full/Incremental) Detail
Coverage Line Coverage ✅ SUCCESS 80%/48% Link

@mindspore-ai-bot

Copy link
Copy Markdown
Platform Type Module Excution Time Time Limit
- distributed_data 341.311s 450.0s
- activation_memory 332.286s 400.0s
- auto_models 84.673s 150.0s
- shard 138.252s 300.0s
- pipeline_parallel 480.038s 675.0s
- optimizer 209.204s 300.0s
- swap_optimizer 252.849s 375.0s
- expert_parallel 216.414s 200.0s
- fully_shard 256.584s 600.0s
- accuracy 63.364s 120.0s
- distributed_checkpoint 69.086s 120.0s
- clip_grad 65.828s 120.0s
- tensor_parallel 183.973s 300.0s
- init_weights 61.685s 118.75s
- context_parallel 63.785s 240.0s
- dtensor 56.665s 120.0s
- process_group 55.078s 90.0s
- llama3_examples 54.634s 120.0s
- ops 2.49525s 150.0s
- multicore 2.858s 120.0s

@mindspore-ai-bot

Copy link
Copy Markdown
Project Name Build_Stage Build Result Details
Hyper-parallel_Github_Gate - ✅ SUCCESS 2348

…y losses

Move auxiliary loss calculation and gradient scaling to
components/losses/aux_loss.py so routing, attention, and the trainer can
share the implementation. Remove the old exports from functional.

Bring in the loss and MoE module-family changes from mindspore-ai#1652 needed for
this refactor. Reuse the existing SwiGLU and grouped GEMM paths.

(partial cherry-pick from commit 2e62f7b)
@Er1ckPang Er1ckPang changed the title refactor(moe): 恢复本地 MoE 组合并统一辅助损失入口 refactor(moe): restore local MoE composition and consolidate auxiliary losses Nov 28, 2026
@Er1ckPang

Copy link
Copy Markdown
Contributor Author

/check-pr

@Er1ckPang

Copy link
Copy Markdown
Contributor Author

/retest

@mindspore-ai-bot

Copy link
Copy Markdown

🔵 The pipeline #2357 is running. Please wait a moment... (Link)

@mindspore-ai-bot

Copy link
Copy Markdown
Project Name Build_Stage Build Result Details(Full/Incremental) Detail
Coverage Line Coverage ✅ SUCCESS 80%/48% Link

@mindspore-ai-bot

Copy link
Copy Markdown
Platform Type Module Excution Time Time Limit
- distributed_data 345.028s 450.0s
- activation_memory 321.235s 400.0s
- auto_models 84.421s 150.0s
- shard 138.563s 300.0s
- pipeline_parallel 486.269s 675.0s
- optimizer 219.255s 300.0s
- expert_parallel 215.363s 200.0s
- distributed_checkpoint 65.976s 120.0s
- swap_optimizer 249.128s 375.0s
- fully_shard 255.926s 600.0s
- clip_grad 63.782s 120.0s
- context_parallel 64.084s 240.0s
- accuracy 64.635s 120.0s
- tensor_parallel 188.095s 300.0s
- init_weights 62.549s 118.75s
- dtensor 56.207s 120.0s
- process_group 51.451s 90.0s
- llama3_examples 50.717s 120.0s
- ops 2.57912s 150.0s
- multicore 3.48163s 120.0s

@mindspore-ai-bot

Copy link
Copy Markdown
Project Name Build_Stage Build Result Details
Hyper-parallel_Github_Gate - ✅ SUCCESS 2357

@github-actions
github-actions Bot merged commit 81e4fa8 into mindspore-ai:master Nov 28, 2026
7 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants