Skip to content

perf(magi): avoid TE padding for magi - #3757

Merged
akoumpa merged 1 commit into
mainfrom
huiyingl/perf/magi-qwen3-packed-cp
Aug 31, 2026
Merged

perf(magi): avoid TE padding for magi#3757
akoumpa merged 1 commit into
mainfrom
huiyingl/perf/magi-qwen3-packed-cp

Conversation

@HuiyingLi

Copy link
Copy Markdown
Contributor

What does this PR do ?

Avoid Transformer Engine-specific per-document CP padding when the attention backend owns context-parallel dispatch, including the custom Magi backend. Add a two-layer Qwen3-MoE exact-geometry recipe that exercises packed THD CP with the production attention, router, expert, and dispatcher dimensions.

TE block-diagonal THD CP requires each packed document to be aligned to 2 * cp_size. Magi builds and dispatches its own arbitrary-mask layout, so retaining that TE-only alignment wastes attention work and reduces the useful label tokens that fit in a pack.

packing_cp_size=1 changes only dataset packing alignment. Runtime distributed.cp_size remains CP8 or CP16.

Changelog

  • Select packer CP alignment from attention ownership: model-owned CP and custom Magi use the baseline CP1 alignment; TE continues using the configured CP size.
  • Add qwen3_moe_2layer_magi_packed_cp8_32k.yaml, preserving Qwen3-30B-A3B head, expert, router, vocabulary, DeepEP, TE-expert, activation-checkpointing, backward, and optimizer paths while reducing depth to two layers for a practical gate.
  • Add parameterized unit coverage for TE, model-owned CP, custom Magi, and non-custom Magi behavior.

Validation

  • ruff format --check nemo_automodel/recipes/llm/train_ft.py tests/unit_tests/recipes/test_train_ft.py
  • ruff check nemo_automodel/recipes/llm/train_ft.py tests/unit_tests/recipes/test_train_ft.py
  • python tools/lint_example_yamls.py examples/llm_finetune/qwen/qwen3_moe_2layer_magi_packed_cp8_32k.yaml
  • python -m pytest tests/unit_tests/recipes/test_train_ft.py -q — 96 passed, 7 skipped
  • Single-node CP8 forward/backward/optimizer gate before multi-node CP16
  • Fresh W&B runs, 30 optimizer steps each; steady window is steps 10–29
Qwen3-MoE case Magi physical vs TE Magi effective-label vs TE
2-layer exact geometry, CP8 / 64K +9.81% +18.29%
Actual 48-layer Qwen3-30B-A3B, CP8 / 32K +63.17% +88.27%
2-layer exact geometry, CP16 / 64K -29.35% -16.11%

W&B workspace: https://wandb.ai/Nemo-automodel/magi

Before your PR is "Ready for review"

Pre checks:

  • Read and followed the contributor guidelines.
  • Added focused unit coverage and an end-to-end benchmark recipe.
  • Added the example recipe needed to document and reproduce the path.

Additional Information

@copy-pr-bot

copy-pr-bot Bot commented Aug 30, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@HuiyingLi
HuiyingLi force-pushed the huiyingl/perf/magi-qwen3-packed-cp branch from eff2347 to 69b1ab8 Compare August 30, 2026 08:05
Signed-off-by: HuiyingLi <willwin.lee@gmail.com>
@HuiyingLi
HuiyingLi force-pushed the huiyingl/perf/magi-qwen3-packed-cp branch from 69b1ab8 to bf999ba Compare August 30, 2026 08:09
@HuiyingLi

Copy link
Copy Markdown
Contributor Author

/ok to test bf999ba

@HuiyingLi

Copy link
Copy Markdown
Contributor Author

/claude review

@claude

claude Bot commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

LGTM

@HuiyingLi
HuiyingLi marked this pull request as ready for review August 30, 2026 08:36
@HuiyingLi
HuiyingLi requested a review from a team as a code owner August 30, 2026 08:36
@HuiyingLi HuiyingLi changed the title perf(magi): avoid TE padding for packed CP perf(magi): avoid TE padding for magi Aug 31, 2026
@akoumpa
akoumpa merged commit 501d46f into main Aug 31, 2026
85 checks passed
@akoumpa
akoumpa deleted the huiyingl/perf/magi-qwen3-packed-cp branch August 31, 2026 05:04
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.

2 participants