Repository navigation
[Refactor] Run Nemotron-H DP attention through the standard layer communicator - #40867
Merged
Merged
Conversation
This was referenced Sep 23, 2026
Merged
Merged
ch-wan
marked this pull request as ready for review
September 23, 2026 07:31
ch-wan
requested review from
Fridge003,
Ying1123,
hanming-lu,
hebiao064,
hnyls2002,
ispobock,
merrymercy,
yizhang2077 and
yuan-luo
as code owners
September 23, 2026 07:31
ch-wan
force-pushed
the
cheng/hot-fix/nemotron-aux-capture
branch
from
September 23, 2026 09:32
5a236ad to
b24b22e
Compare
ch-wan
force-pushed
the
cheng/refactor/nemotron-dp-attn-communicator
branch
from
September 23, 2026 09:32
4e928dd to
199cc84
Compare
ch-wan
force-pushed
the
cheng/hot-fix/nemotron-aux-capture
branch
from
September 23, 2026 21:39
b24b22e to
930a93f
Compare
Nemotron-H layers now use LayerCommunicator the same way for DP attention and plain TP. A Mamba / attention layer calls prepare_attn and runs its mixer; an MLP / MoE layer calls prepare_mlp, runs the FFN and calls postprocess_layer, the two halves of a standard decoder layer. A mixer followed by an MLP layer leaves its output unreduced for prepare_mlp, like any attention output; otherwise it reduces the output itself. An MLP layer fed by another MLP layer folds its reduced input into the residual. Idle DP ranks skip the mixer. The model no longer trims DP padding rows or reads _original_forward_mode; padding is handled by the attention layers and backends as for other models. Auxiliary hidden-state capture reduces its copy exactly where a mixer hands an MLP layer an unreduced output. Shared code loses the hybrid-SSM special cases this needed: - ForwardBatch.prepare_mlp_sync_batch no longer forces the one-request extend fabrication or leaves the fabricated rows unmasked for hybrid models. Hybrid target-verify batches still keep their verify layout, and idle ranks still join a verify step as TARGET_VERIFY: TARGET_VERIFY counts as extend, so the extend conversion would otherwise rewrite verify rows as one-token extends. - Linear attention skips a fully masked extend (an idle rank's fabricated request) instead of running the kernel on an empty batch, which the Blackwell GDN prefill kernel rejects. - Mamba metadata no longer reads _original_batch_size. Decode counts every padded row, and padded rows address mamba slot 0, the reserved padding slot. The eager path no longer rewrites padded rows to -1, which made a fabricated idle-rank request write ssm_state[-1], a live slot. - MambaMixer2 zeroes its padding rows and can reduce its output over the attention TP group. - LayerCommunicator drops force_layernorm_before_dp_gather. With attention TP > 1 this also stops consecutive MLP layers from summing replicated inputs.
A Mamba / attention layer followed by an MLP layer now publishes fuse_mlp_allreduce around its mixer instead of building the output projection with reduce_results=False: RowParallelLinear and its LoRA wrapper skip the all-reduce, and the MLP layer's prepare_mlp performs it. Mixer projections are built reducing, over the attention TP group under DP attention, so the module structure no longer depends on the next layer type.
With DP attention and attn_tp_size > 1, the default prepare_mlp gather adds the residual to attn-TP rank 0's partial and sums the partials in the DP gather, rounding the residual stream to bf16 once more per layer. Nemotron-3-Nano-30B-A3B at tp4 dp2 drops from 0.46 to 0.43 on GSM8K on that path, so the Nemotron-H layer communicators keep force_layernorm_before_dp_gather: reduce over attn TP first and run the residual add inside the fused norm, at the cost of one more attn-TP all-reduce per MLP layer. Comments at the flag and in the gather describe the trade-off.
ch-wan
force-pushed
the
cheng/refactor/nemotron-dp-attn-communicator
branch
from
September 23, 2026 21:40
199cc84 to
90c040e
Compare
hanming-lu
pushed a commit
that referenced
this pull request
Sep 24, 2026
… MLP-sync test prepare_mlp_sync_batch now publishes through set_dp_buffer_len_from_batch, so forward_batch_info no longer imports set_dp_buffer_len; the test added on main by #40867 patched the old name and errored with AttributeError.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR is part of a stack (oldest at bottom):
Motivation
Nemotron-H ran DP attention through its own path instead of the layer communicator the other DP-attention models use. Every layer had a separate DP branch. The model trimmed DP padding rows itself and read
_original_forward_mode, and consecutive Mamba / attention layers needed an extra attention-TP all-reduce.ForwardBatch.prepare_mlp_sync_batchand the Mamba metadata carried hybrid-SSM special cases keyed on_original_forward_mode/_original_batch_size. This change moves Nemotron-H onto the standardLayerCommunicatorstructure and removes the special cases it no longer needs; the hybrid-SSM target-verify branch stays.Modifications
Nemotron-H model
prepare_attnand runs its mixer. Idle DP ranks skip the mixer.prepare_mlp, runs the FFN and callspostprocess_layer.get_forward().scoped(fuse_mlp_allreduce=True), and the MLP layer'sprepare_mlpperforms it, as after any attention.---runs in Nemotron-H-47B) folds its already-reduced input into the residual beforeprepare_mlp._original_forward_mode. The attention layers and backends handle padding as they do for other models.force_layernorm_before_dp_gather. With DP attention and attention TP > 1, the defaultprepare_mlpgather adds the residual to one rank's partial in bf16 before the cross-rank sum. That adds one bf16 rounding of the residual stream per layer, and Nemotron-3-Nano-30B-A3B at TP4 DP2 drops from 0.46 to 0.43 on GSM8K. The flag keeps the reduce-first path (attention-TP all-reduce, then fused add-norm, then gather) at the cost of one attention-TP all-reduce per MLP layer.Shared code
ForwardBatch.prepare_mlp_sync_batchno longer forces the one-request extend fabrication for hybrid-SSM models or leaves their fabricated idle-rank rows unmasked; they take the common path. The hybrid-SSM target-verify branch stays ahead of that conversion:TARGET_VERIFYcounts as extend, so in a step where another rank prefills, a verify batch would otherwise be rewritten to one-token extend requests and lose its draft tokens.radix_linear_attention.py, the GDN / KDA path of Qwen3-Next, Qwen3.5, Kimi-linear and others) zeroes its output and skips the backend when the rank's real token count is 0. An idle DP rank's fabricated request is now fully masked, and Blackwell's GDN prefill kernel rejects an empty batch (max_seqlen must be positive, got 0)._original_batch_size:ssm_state[-1], which is a live slot.MambaMixer2zeroes its padding rows and takes areduce_resultsargument whose default is unchanged. When it reduces under DP attention, the reduction runs over the attention TP group.Accuracy Tests
GSM8K, 5-shot, 500 questions unless noted, on 4×B200. Base is this PR's base branch. No run logged server errors.
test/registered/ep/test_flashinfer_a2a.py::TestFlashinferA2ATrtllmRoutedFP8(Qwen3-Next-80B-A3B-Instruct-FP8, TP4 DP4 EP4, FlashInfer A2A, 4×B200): base 0.96, this PR 0.96 (threshold 0.93). Without the linear-attention change the same run scores 0.0 withmax_seqlen must be positive, got 0on idle ranks.test/registered/unit/model_executor/test_mlp_sync_hybrid_target_verify.py.test/registered/unit/layers/test_linear_attention_masked_idle_rank.pyandtest_mlp_sync_hybrid_target_verify.pyfail without the respective change and pass with it.unit/layers,unit/models,unit/model_executor,unit/batch_overlap,unit/managersandunit/spec: every existing case keeps its status against base (twounit/managersfiles that cannot be collected on a CPU-only host are skipped on both sides).Speed Tests and Profiling
Warm caches, runs alternated between this PR and base, two servers each.
bench_servingrandom-ids, 1024 in / 512 out, concurrency 128, 512 prompts: 8747 tok/s vs 8738 tok/s, median ITL 9.16–9.17 ms on both.Checklist
CI States
Latest PR Test (Base): 🚫 Run #35923868790
Latest PR Test (Extra): 🚫 Run #35923868457
Latest PR Test (AMD ROCm 10): ❌ Run #35923868950