[dev] moe(perf): Refactor CP layout organization for Qwen3.5-style hybrid attention model - #6387
Conversation
|
/claude strict-review |
|
Strict Review Summary — PR #6387 Findings by severity: CRITICAL: 6 · IMPORTANT: 6 · SUGGESTION: 9 (21 total) Overall risk: HIGH — do not merge in current state The refactor itself is well-structured (splitting Most impactful findings 1.
decoder = get_attr_wrapped_model(model, "decoder")
cp_partition_mode = decoder.cp_stage_entry_partition_modeThis is not gated on CP size, TP, or attention variant. Every GPT and every hybrid pretraining/SFT run on this branch raises 2. New test coverage cannot have been executed. (CRITICAL)
Taken together, (1) and (2) suggest a partially-landed change: it looks like a 3. Silent numerical corruption on the flash-decode path. (CRITICAL)
4. The route prebuild does not actually remove the syncs it was meant to remove. (IMPORTANT Performance)
5. Backward-compatibility break with no deprecation window. (IMPORTANT Compatibility)
6. GDN init and RNG stream changed inside a CP-layout PR. (IMPORTANT Compatibility) The new Also flagged
Process The PR head commit is literally titled Suggested path forward
Happy to re-review once the entry points execute. |
450d41a to
ac43e1c
Compare
|
/ok to test 63faa41 |
63faa41 to
1fd2a10
Compare
Signed-off-by: Yuzhong Wang <yuzhongw@nvidia.com>
Signed-off-by: Yuzhong Wang <yuzhongw@nvidia.com>
Signed-off-by: Yuzhong Wang <yuzhongw@nvidia.com>
Signed-off-by: Yuzhong Wang <yuzhongw@nvidia.com>
Signed-off-by: Yuzhong Wang <yuzhongw@nvidia.com>
Signed-off-by: Yuzhong Wang <yuzhongw@nvidia.com> Co-authored-by: Haoran Zhang <haoranz@nvidia.com>
Signed-off-by: Yuzhong Wang <yuzhongw@nvidia.com>
1fd2a10 to
3bdaba2
Compare
|
/ok to test 3bdaba2 |
What does this PR do?
PR for main: #6515
This PR adds fixed context-parallel (CP) layout support for long-context hybrid models that want to run most layers in
cp_partition_mode="contiguous"while still keeping regular attention/GQA in thezigzaglayout it requires.The main goals are:
E2E perf gain (A proxy model of Qwen3.5-397B):
Motivation
The previous fixed CP layout path effectively kept the model in zigzag layout because regular attention requires zigzag. That is correct for attention, but it is not optimal for Qwen3.5-style hybrid stacks where most layers are GDN layers.
For chunkwise CP, GDN can run in contiguous layout. This PR lets the model keep the broader stack in contiguous layout, then converts only when entering regular attention/GQA and converts the attention output back afterward. With a GQA:GDN = 1:3 schedule, this shifts layout shuffles away from the dense GDN path and places them on the sparser attention boundary.
For THD packed sequences, the route for a given microbatch is deterministic. This PR moves route construction into batch preparation and reuses the result for later
zigzag <-> contiguousconversions.Major Changes
1. CP layout conversion package
megatron/core/context_parallel_layout.pyinto a package:conversion.py: SBHD/THD tensor conversion andCpPartitionModeConverter.routes.py: THD route construction, encoding/decoding, lookup, and prebuild.metadata.py: helpers for packed sequence layout metadata.policy.py: stage-entry layout policy helpers.__init__.py: compatibility exports for existing imports.convert_module_input_tensors_cp_partition_mode()for module-boundary conversion:2. Attention/GDN layout boundary
cp_partition_mode="contiguous"useful for Qwen3.5-style schedules: most GDN layers avoid conversion, while GQA/regular-attention layers handle their own layout boundary.3. THD route prebuild
prebuild_thd_cp_partition_routes()to compute both THD conversion directions during batch construction.get_batchpaths to annotate the stage-entry layout and prebuild THD routes before model forward.4. Checks and unsupported cases
This PR adds two layers of validation.
First,
TransformerConfigrejects unsupported configuration combinations early:contiguousCP currently requiresexperimental_attention_variantto begated_delta_netordsv4_hybrid.dsv4_hybridwith CP requirescontiguous.gated_delta_netwithlinear_cp_mode="headwise"cannot usecontiguous.multi_latent_attentionoutsidedsv4_hybridcannot usecontiguous.Second, runtime layout is carried through
PackedSeqParams.cp_partition_mode, and attention variants validate the layout they receive:These checks are meant to fail early when tensor order would otherwise silently diverge from the module's layout assumption.
Limitations / Future Work
Issue tracking
For PRs from open-source community contributors:
Linked issue:
Contribution process
Pre-checks
Code review
Feel free to message or comment @NVIDIA/mcore-oncall to help accelerate your merge into main. The less complex your PR is, the faster it will be approved and merged!
All PRs start as draft. If you open a non-draft PR, it will be automatically converted to draft.
Step 1: Mark PR as "Ready for Review"
.github/CODEOWNERS.Final Review might get declined if these requirements are not fulfilled.
Step 2: Final Review
For PRs that change
megatron/core, once all expert reviewers have approved, theFinal Reviewlabel is applied automatically and final reviewers are assigned.For PRs outside
megatron/core, this step is skipped.Step 3: Approved
Once all required reviewers have approved, the
Approvedlabel is applied automatically.Merge
Any member of mcore-engineers will be able to merge your PR.