Skip to content

[Refactor] Run Nemotron-H DP attention through the standard layer communicator - #40867

Merged
ch-wan merged 4 commits into
mainfrom
cheng/refactor/nemotron-dp-attn-communicator
Sep 23, 2026
Merged

ch-wan merged 4 commits into
mainfrom
cheng/refactor/nemotron-dp-attn-communicator

Conversation

@ch-wan

@ch-wan ch-wan commented Sep 23, 2026 •

Copy link
Copy Markdown
Collaborator

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_batch and the Mamba metadata carried hybrid-SSM special cases keyed on _original_forward_mode / _original_batch_size. This change moves Nemotron-H onto the standard LayerCommunicator structure and removes the special cases it no longer needs; the hybrid-SSM target-verify branch stays.

Modifications

Nemotron-H model

  • Each layer is one half of a standard decoder layer, and the same code runs with and without DP attention:
    • A Mamba / attention layer calls prepare_attn and runs its mixer. Idle DP ranks skip the mixer.
    • An MLP / MoE layer calls prepare_mlp, runs the FFN and calls postprocess_layer.
  • Where each output gets reduced:
    • A mixer followed by an MLP layer skips its output reduction through get_forward().scoped(fuse_mlp_allreduce=True), and the MLP layer's prepare_mlp performs it, as after any attention.
    • Any other mixer reduces its output itself, over the attention TP group under DP attention.
    • An MLP layer fed by another MLP layer (the --- runs in Nemotron-H-47B) folds its already-reduced input into the residual before prepare_mlp.
  • The model no longer trims DP padding rows or reads _original_forward_mode. The attention layers and backends handle padding as they do for other models.
  • Auxiliary hidden-state capture reduces its copy exactly where a mixer hands an MLP layer an unreduced output.
  • Nemotron-H layer communicators keep force_layernorm_before_dp_gather. With DP attention and attention TP > 1, the default prepare_mlp gather 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_batch no 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_VERIFY counts 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.
  • Linear attention (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).
  • The Mamba metadata no longer reads _original_batch_size:
    • Decode counts every padded row, and padded rows address mamba slot 0, the reserved padding slot of both the static and the unified pool.
    • The eager path no longer rewrites padded rows to -1. That rewrite made a fabricated idle-rank prefill write ssm_state[-1], which is a live slot.
  • MambaMixer2 zeroes its padding rows and takes a reduce_results argument 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.

Model / config This PR Base
Nemotron-3-Nano-30B-A3B TP4 0.482 0.490
Nemotron-3-Nano-30B-A3B TP4 DP4 (attention TP 1), eager 0.482 0.484
Nemotron-3-Nano-30B-A3B TP4 DP2 (attention TP 2), 1319 questions 0.463 / 0.466 0.472 / 0.456
NVIDIA-Nemotron-Nano-9B-v2 TP2 0.898 0.900
NVIDIA-Nemotron-Nano-9B-v2 TP4 DP2 (attention TP 2) 0.900 0.894
Nemotron-3-Super-120B-A12B-NVFP4 TP4 DP4 EP4, FlashInfer A2A (nightly CI config) 0.934 0.942
Nemotron-3-Super-120B-A12B-NVFP4 TP4 DP4 + MTP 0.944 / 0.940 / 0.942 0.934 / 0.936 / 0.934
Nemotron-3-Super-120B-A12B-NVFP4 TP4 + MTP 0.942 0.934
  • Across all runs, 500-question GSM8K on these models varies by about ±0.011.
  • The Nano-9B-v2 pattern covers consecutive Mamba layers and Mamba → attention transitions.
  • CPU unit tests for Nemotron-H, MLP-sync pad/unpad, TBO, the communicator fusion gate, Mamba metadata and LongCat: 80 passed, 135 subtests passed.
  • Qwen3-Next on Blackwell, 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 with max_seqlen must be positive, got 0 on idle ranks.
  • Nemotron-3-Super-120B-A12B-BF16 TP4 DP4 + EAGLE, GSM8K 20 questions: 0.95 with the same per-rank accept lengths with and without the target-verify branch. That run never lines up a verify step with another rank's prefill, so the branch is covered by test/registered/unit/model_executor/test_mlp_sync_hybrid_target_verify.py.
  • New regression tests test/registered/unit/layers/test_linear_attention_masked_idle_rank.py and test_mlp_sync_hybrid_target_verify.py fail without the respective change and pass with it. unit/layers, unit/models, unit/model_executor, unit/batch_overlap, unit/managers and unit/spec: every existing case keeps its status against base (two unit/managers files 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.

  • NVIDIA-Nemotron-Nano-9B-v2 TP2, bench_serving random-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.
  • Nemotron-3-Super-120B-A12B-NVFP4 TP4 DP4 + MTP, GSM8K output throughput: 1863 / 1754 tok/s vs 2710 / 1782 tok/s. The difference is within base's own run-to-run spread.

Checklist


CI States

Latest PR Test (Base): 🚫 Run #35923868790
Latest PR Test (Extra): 🚫 Run #35923868457
Latest PR Test (AMD ROCm 10): ❌ Run #35923868950

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
ch-wan force-pushed the cheng/refactor/nemotron-dp-attn-communicator branch from 199cc84 to 90c040e Compare September 23, 2026 21:40
@ch-wan
ch-wan merged commit 701cf7e into main Sep 23, 2026
26 of 36 checks passed
@ch-wan
ch-wan deleted the cheng/refactor/nemotron-dp-attn-communicator branch September 23, 2026 21:40
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.
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