Skip to content

[feat] Add SP and PP kernels for qwen_moe true on policy#31

Open
maocheng23 wants to merge 25 commits into
feat/true_on_policy_qwen_moefrom
feat/true_on_policy_qwen_moe_sppp
Open

[feat] Add SP and PP kernels for qwen_moe true on policy#31
maocheng23 wants to merge 25 commits into
feat/true_on_policy_qwen_moefrom
feat/true_on_policy_qwen_moe_sppp

Conversation

@maocheng23
Copy link
Copy Markdown

Stacked on top of #30.

Summary

  • Reword the attention-TP-without-SP error message to flag the missing true-on-policy path.
  • Add _under_sp_or_attn_tp guard in miles_megatron_plugins/true_on_policy/moe_layer_ext.py so the SGLang local-masked EP forward path is allowed even when padding is present (under SP or attention-TP), and padding compaction is skipped under those topologies.
  • Wire SP/PP-aware token routing, p2p communication, schedules, transformer block changes, and bridge schema flag.
  • Add MoE PP/SP test fixtures under tests/unit_tests.

Test plan

  • Run tests/unit_tests/transformer/moe/test_moe_layer.py against PP=2 and SP=on configurations.
  • Verify zero logprob diff for Qwen3-MoE TP=1 EP=4 PP=2 SP=on against rollout.

maocheng23 and others added 25 commits April 23, 2026 12:17
Add a clean Megatron backend that calls SGLang-compatible math under a flag:
- sglang.py: SGLangLinear, SGLangRMSNorm, SGLangFlashAttention and related modules
- matmul_tp_inv.py: TP-invariant matmul dispatch for Megatron layers
- transformer_config.py: use_sglang config flag
- arguments.py: --use-sglang CLI arg
- layers.py: conditional SGLang backend selection in TP layers
- gpt_layer_specs.py: SGLang-compatible layer spec builder
- test_sglang_extension.py: import, config, and default-path-unchanged tests

Default training path remains unchanged when use_sglang is off.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Match SGLang's TP reduction order and full-vocab logprob contract:
- mappings.py: tree_all_reduce_sum for deterministic TP reduction
- layers.py: conditional tree allreduce in RowParallelLinear
- gpt_model.py: full-vocab logprob gather/truncate/log-softmax
- transformer_config.py: true_on_policy_logits config
- test_tree_all_reduce.py: TP tree-allreduce tests
- test_true_on_policy_logits.py: full-vocab gather/truncate tests

Default NCCL allreduce path unchanged when flags are off.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
isort/black reformatting on files touched by the true-on-policy
substrate, runtime contract, and Qwen3-dense parity path.
No semantic changes.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@maocheng23 maocheng23 force-pushed the feat/true_on_policy_qwen_moe branch 4 times, most recently from 7ac2a80 to b0679e2 Compare May 23, 2026 02:47
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