Skip to content

fix(data-plane): broadcast route fragments instead of the dense routes table - #4526

Merged
yuki-97 merged 5 commits into
mainfrom
zhiyul/fix/route-fragment-replica-broadcast
Oct 12, 2026
Merged

yuki-97 merged 5 commits into
mainfrom
zhiyul/fix/route-fragment-replica-broadcast

Conversation

@ZhiyuLi-Nvidia

@ZhiyuLi-Nvidia ZhiyuLi-Nvidia commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Problem

With router replay on, the replica-group leader of each DP rank builds a dense, padded routed_experts table for the whole batch and broadcasts it to its TP x CP x PP peers. In job 1053591 (86 nodes, TP4 x CP4, DP 8) that table was 47.13 GiB:

1024 rows x 73,536 padded tokens x 56 route layers x top-6 x 2 B (int16) = 47.13 GiB

NCCL has no int16, so _broadcast_batched_data_dict widens the table to int32. Peers then stage roughly 4x the table on GPU (188.5 GiB measured) and OOM. Only about 3.5% of the table is real routes: about 1.7 GB per DP rank. The rest is padding.

Fix

By default, whenever routes pass through a replica group (route passthrough on, group size > 1), the leader now broadcasts the route fragments instead of the padded table, and every rank builds the table itself. Host memory per rank is the same as main, where peers already hold the full table on CPU. Setting NRL_ROUTE_BCAST=dense restores the old dense-table path as an escape hatch.

leader:     fetch fragments ─► _pack_route_fragments ─► uint8 blob + per-row index
                                       │ two extra fields in the BatchedDataDict
all ranks:  _broadcast_batched_data_dict (existing path, no new collective)
            ─► _unpack_route_fragments ─► _assemble_routed_experts (CPU table)
  • _pack_route_fragments / _unpack_route_fragments: store each fragment once in a uint8 blob, at 8-byte-aligned offsets so peers read them back as views. Each row's index lists only the fragments its route plan uses.
  • _maybe_assemble_routed_experts is split into _route_plans (decode once) and _assemble_routed_experts. Every rank assembles, but fallback counts are recorded only on the leader, as before (once per replica group).

Results

GB300, 2 nodes, 8-rank TP4 x CP2 replica group built the same way as the Megatron worker, NCCL_MNNVL_ENABLE=0. Steady state; arms in each table ran on the same node pair.

Path Time GPU peak
RL main, 47 GiB dense table (int32 wire) 2.58 s 188.5 GiB
int16 as byte views, dense (c4871a0) 2.55–2.83 s 47.1 GiB
this PR: fragments through the existing dict broadcast 0.55–0.58 s 1.66 GiB
fragments through a custom chunked broadcast (not used) 0.065 s 0.125 GiB
  • Fragments still need about 2.8 s of CPU per rank to build the padded table. The dense path builds it too, on the leader.
  • Peers end up holding the same 47 GiB CPU table as on main, so host memory per rank is unchanged.
  • Why not the chunked broadcast: a custom bucketed, double-buffered transport ships the same fragments in 0.065 s, but adds about 250 lines. Against a ~560 s step, the 0.5 s difference is under 0.1%, so this PR reuses the existing broadcast.

Tests

On GB300 with NCCL:

  • tests/unit/data_plane/test_leader_broadcast.py:
    • existing tests
    • pack/unpack round trip (dedup across rows, an unstaged key, a row that lost its fetch, int64 alignment)
    • fragments through the real _broadcast_batched_data_dict over NCCL
  • test_worker_route_assembly.py needs nemo_gym, which isn't in the base venv. It covers the _route_plans / _assemble_routed_experts split and has not run yet.

Nightly coverage (a5c0535)

New nightly grpo-nanov3-30BA3B-2n8g-noncolocated-async-gym-single-controller-token_capture-r3-defer reaches the fragments branch: token_capture.defer_routed_experts_to_policy=true + router_replay.enabled=true, CP=2 so the replica group is > 1.

  • The recipe inherits the existing token_capture nightly and only changes router replay, defer, and vLLM generation (Megatron generation raises on token capture + router replay). max_total_sequence_length=8192 / max_new_tokens=1024 keep the agent's turns inside vLLM's context, so no rollout is poisoned by a context_length 400.
  • The .sh calls the parent token_capture driver (same gates), then adds three: route_plan_span_count > 0, routed_experts_row_coverage == 1, no routed_experts_deferred_fallback/* key.
  • Existing nightlies are untouched; the GPU-hour cap in test_recipes_and_test_suites.py goes 4789 → 4805.

Ran the real .sh on GB300 (4 nodes × 4 GPUs: 2 train TP2×CP2, 2 vLLM): all gates pass, exit 0 on this PR (W&B) and on #4530 (W&B).

Ablation on the same recipe, 6 steps per arm, [BCAST_AB] timing/peak logging not in the PR:

Arm Bytes sent / row Broadcast p50 (per rank) GPU peak added Gates W&B
NRL_ROUTE_BCAST=dense 1.76 MB 0.141 s 0.15 GiB pass 3bmrjtyj
this PR (fragments) 0.40 MB 0.132 s 0.02 GiB pass gdfnjwxq
+ #4530 (fragments, jagged routes) 0.37 MB 0.142 s 0.02 GiB pass gh9fye7x

All arms: 0 masked sequences, no NaN, token_mult_prob_error ≈ 1.02. At this small shape the time is the same; the win is bytes and GPU peak, which is what blows up at 86 nodes.

Follow-ups

  • 12-node router-replay run is done (see perf(data-plane): broadcast unpadded rows and pad on each rank #4530, W&B, exit 0). The 86-node run is still pending; NRL_ROUTE_BCAST=dense falls back to the old dense path.
  • If the flag stays after those runs, move NRL_ROUTE_BCAST into config, per the config-conventions skill.
  • Phase 2: build routes per packed microbatch on GPU, which removes the 47 GiB CPU table on every rank.

🤖 Generated with Claude Code

@copy-pr-bot

copy-pr-bot Bot commented Oct 6, 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.

@github-actions github-actions Bot added the Documentation Improvements or additions to documentation label Oct 6, 2026
@ZhiyuLi-Nvidia
ZhiyuLi-Nvidia added this pull request to stack #4531 October 6, 2026 08:12
@ZhiyuLi-Nvidia

Copy link
Copy Markdown
Contributor Author

/ok to test 92246a2

@ZhiyuLi-Nvidia ZhiyuLi-Nvidia added Run CICD CI:L1 Run doctests, unit tests, and functional tests labels Oct 7, 2026
zyzhou5
zyzhou5 previously approved these changes Oct 8, 2026

@zyzhou5 zyzhou5 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great to me! Thanks.

@ZhiyuLi-Nvidia
ZhiyuLi-Nvidia force-pushed the zhiyul/fix/route-fragment-replica-broadcast branch 3 times, most recently from d8c1c25 to 40ed1c7 Compare October 9, 2026 18:35
@ZhiyuLi-Nvidia

Copy link
Copy Markdown
Contributor Author

/ok to test 40ed1c7

@ZhiyuLi-Nvidia
ZhiyuLi-Nvidia force-pushed the zhiyul/fix/route-fragment-replica-broadcast branch from 40ed1c7 to e6f7b30 Compare October 11, 2026 01:14
@ZhiyuLi-Nvidia

Copy link
Copy Markdown
Contributor Author

/ok to test 33a2e82

@yuki-97 yuki-97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shipping only the valid route fragments instead of the padded 47 GiB dense table is a big improvement for router replay at TP4 x CP4: the replica-group broadcast drops to 1.66 GiB of GPU peak and about 0.55 s instead of roughly 2.6 s, and it reuses the existing dict broadcast, so no new collective is introduced.

The GB300 measurements in the description, including the chunked-broadcast variant that was deliberately left out (0.5 s faster, but about 250 more lines against a ~560 s step), make the trade-off easy to trust.

Scope: the replica-group _fetch path and the _route_plans / _assemble_routed_experts split in worker_mixin.py, plus the new pack/unpack tests.

Checked:

  • Pack/unpack layout — 8-byte-aligned offsets make the int16/int64 views legal on peers, and all three RouteFragment fields are carried in the per-row index.
  • Fallback accounting — record_fallbacks=is_leader keeps counts leader-only as on main, so the summation in tq_policy.py stays correct.
  • Leader/peer symmetry — the private blob/index keys are popped before attach_message_log_view, and the _route_fragments_by_row signature change has no other callers.
  • NRL_ROUTE_BCAST=dense still routes through the unchanged _maybe_assemble_routed_experts path.

Remaining comments are on e2e coverage: no nightly recipe enables deferred routes today, so the fragments branch is only exercised by manual runs.

Comment thread nemo_rl/data_plane/worker_mixin.py Resolved
@ZhiyuLi-Nvidia

Copy link
Copy Markdown
Contributor Author

/ok to test a5c0535

ZhiyuLi-Nvidia and others added 5 commits October 12, 2026 02:08
…s table

With router replay, the replica-group leader assembled a dense padded
routed_experts table (47 GiB int16 at 86 nodes) and broadcast it,
widening int16 to int32 and staging ~4x the table on non-leader GPUs,
which OOMs. Behind NRL_ROUTE_BCAST=fragments the leader now broadcasts
the route fragments and every rank assembles the table locally.

- _broadcast_bytes: NCCL host-byte broadcast through two alternating
  device buckets so copies overlap the broadcast; GPU staging is
  2 x NRL_ROUTE_BCAST_BUCKET_BYTES (default 64 MiB).
- _broadcast_route_fragments: index via broadcast_object_list, bytes
  via _broadcast_bytes; leader streams parts without concatenating,
  peers take 8-byte-aligned views without copying.
- _broadcast_leader_result: shared leader error-envelope protocol, now
  also used by _broadcast_batched_data_dict.
- Route plans are decoded once per fetch; fallback counts stay
  leader-only.
- design doc: docs/design-docs/routed-experts-replica-broadcast.md

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Zhiyu Li <[email protected]>
…cast

Replace the custom chunked byte broadcast with a packed fragment blob
carried by _broadcast_batched_data_dict. The leader packs each fragment
once into a uint8 blob plus a per-row index; every rank unpacks views
and assembles the routes table on CPU. No new collective.

Fragments are ~1.7 GB per DP rank, so the single-transfer path costs
0.55 s and 1.66 GiB of GPU staging on GB300 (vs 0.065 s / 0.125 GiB
for the chunked transport), for ~250 fewer lines.

Drop the design doc from the branch; it moves to the PR description.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Zhiyu Li <[email protected]>
NRL_ROUTE_BCAST=dense keeps the leader-built dense table as an escape
hatch until the 12- and 86-node end-to-end runs pass.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Zhiyu Li <[email protected]>
…re nightly

Adds a vLLM + router replay + defer_routed_experts_to_policy variant of the
nanov3 token_capture nightly (CP=2, so the replica-group fragments broadcast
runs). The script reuses the parent driver and gates and adds route checks.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Zhiyu Li <[email protected]>
@ZhiyuLi-Nvidia
ZhiyuLi-Nvidia force-pushed the zhiyul/fix/route-fragment-replica-broadcast branch from a5c0535 to 37d1f60 Compare October 12, 2026 09:11
@ZhiyuLi-Nvidia

Copy link
Copy Markdown
Contributor Author

/ok to test 37d1f60

@yuki-97
yuki-97 merged commit a5fba40 into main Oct 12, 2026
211 of 213 checks passed
@yuki-97
yuki-97 deleted the zhiyul/fix/route-fragment-replica-broadcast branch October 12, 2026 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI:L1 Run doctests, unit tests, and functional tests Documentation Improvements or additions to documentation Run CICD

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants