Repository navigation
Conversation
…erts Routed-expert ids ride as uint16 when a model has more than 255 experts. torch has no max() or arange() kernel for the unsigned carry dtypes, so the range check and the default-route construction raised NotImplementedError on the 512-expert Nemotron 3.5 Super. Reduce and build in int64, then narrow back to the carry dtype. Carried from smahdavi's nemo-rl-2026-09-29 working tree (uncommitted there). Co-Authored-By: Claude Fable 5.1 <[email protected]> (cherry picked from commit 5918e89) Signed-off-by: pthombre <[email protected]>
…streaming_train The train pump dispatched target_groups - groups_dispatched, i.e. every ready group up to the rest of the step, so a rollout backlog produced chunks of hundreds of groups. With router replay the replica-leader broadcast materialises sequences x padded_len x layers x topk int16 routes on every GPU of the replica, so unbounded chunks OOM on large MoE models. Add an optional upper bound (validated >= min) and clamp the chunk to it. Carried from smahdavi's nemo-rl-2026-09-29 working tree (uncommitted there). Co-Authored-By: Claude Fable 5.1 <[email protected]> (cherry picked from commit 953060f) Signed-off-by: pthombre <[email protected]>
|
Thank you @pthombre Do you think we can do something like dtype autoset or resuse the function based on the num_experts? RL/nemo_rl/models/generation/interfaces.py Lines 81 to 89 in 7409c28 So we can efficiently use minimal dtype for router indices. That's really helpful as if we use int32 instead of int64 then we halve the communication. I think the reason we don't use uint is that we need -1 for pad index. |
…signed ids and chunk bounds routed_experts_dtype is always a signed carry dtype from resolve_routed_experts_dtype, which torch.arange supports, so the int64 build of the default padding route was unnecessary. Only the one-time overflow guard needs the wider reduction: it must see the unwrapped backend id to notice an id that does not fit the carry dtype. Expose the streaming chunk cap as AsyncRLConfig.streaming_chunk_cap() so the train pump's clamp is testable without a Megatron worker, document async_rl.max_groups_for_streaming_train in the single-controller guide and the exemplar YAML, and add unit tests for uint8/uint16/uint32 backend ids through pad_and_align_routed_expert_indices, the overflow guard on an unwrapped uint16 id, and the config bounds. Co-Authored-By: Claude Fable 5.1 <[email protected]> Signed-off-by: pthombre <[email protected]>
|
/ok to test 92b28eb |
Signed-off-by: pthombre <[email protected]>
|
/ok to test c8dbd5a |
c8dbd5a to
507d322
Compare
|
/ok to test 507d322 |
…ming_train is unset An unset cap used to fall back to min_groups_for_streaming_train, which turned every existing streaming config's chunks into exactly-min-sized ones and broke the checkpoint tests that pin one chunk per step. None now means no cap: the chunk stays bounded by the step remainder as before, and only an explicit max_groups_for_streaming_train clamps it. Drop the streaming_chunk_cap() helper, read the field directly in the pump, and give the pump test stub the new field. Co-Authored-By: Claude Fable 5.1 <[email protected]> Signed-off-by: pthombre <[email protected]>
|
/ok to test efab9b8 |
|
Thanks @ZhiyuLi-Nvidia. The Why the guard can't reduce in the carry dtype itself: its job is to catch a mis-detected expert count, i.e. an id that doesn't fit the resolved dtype. Casting uint16 -> int16 first would wrap any id >= 32768 negative, so |
|
i hit the same issue and came to the same fix as here |
What does this PR do?
Two small changes needed to run router replay on MoE models with more than 255 experts (Nemotron 3.5 Super, 512 experts, top-22, 88 layers) in the single-controller async GRPO path. Both were validated on two 4-hour 92-node legs on oci-aga (32 train + 36 generation + 4 Gym + 20 judge nodes, 8192 sequences per step, 81,920 context): 12 steps per leg, routed-expert row coverage 1.0 on every step, no host OOM.
They are independent of #4263 (leader-broadcast layout and int16 byte-view fixes) and apply cleanly on top of it.
1.
fix(vllm): reduce routed-expert ids in int64 for models with >255 expertsBehavior on main. vLLM returns per-token routed-expert ids in its own storage type:
uint8up to 256 experts,uint16above.nemo_rl/models/generation/vllm/utils.pythen narrows them to the resolved signed carry dtype (int16for 512 experts). One call on that path assumes a fully supported dtype:_as_routed_experts_tensorruns a one-time overflow guard,int(tensor.max()), before the narrowing cast.PyTorch's unsigned 16/32-bit dtypes have no
maxreduction, so on a 512-expert model the very first captured batch raisedNotImplementedError: "max_all" not implemented for 'UInt16'and no rollout ever reached the trainer. Every model run through router replay before had at most 256 experts, which is why main never hit this.Change. Reduce in
int64(tensor.to(torch.int64).max()) before narrowing to the carry dtype. The stored and transported dtype is unchanged: it is still the oneresolve_routed_experts_dtypereturns (int16for 512 experts). The guard has to reduce in a type wider than that carry dtype, otherwise a uint16 id >= 32768 would wrap negative beforemax()and the guard would miss exactly the overflow it checks for. The only new cost is a one-time int64 copy of the checked slice.The default padding route (
torch.arange(top_k, dtype=routed_experts_dtype)) is untouched:routed_experts_dtypeis always a signed carry dtype, whicharangesupports.2.
feat(sc): cap the streaming train chunk withasync_rl.max_groups_for_streaming_trainBehavior on main. The train pump in
SingleControllerActorstreams a step as chunks: each iteration callssampler.select(min=min_groups_for_streaming_train, max=target_groups - groups_dispatched), and_finalize_selectionis greedy, returning every eligible group up tomaxwithout waiting. The upper bound is therefore the remainder of the step. The first chunk is small because the buffer is empty, but by the second chunk generation has run ahead, and the pump hands over everything that is ready, up to the full step. With a 512-prompt step and 36 generation nodes that was a chunk of ~250 groups (~4,000 rows).Without router replay this is harmless: a row is a few kilobytes. With router replay each DP-replica leader fetches its slice of the chunk and densifies it on the host before the NCCL broadcast, and the routed-expert field is
int16 [rows, padded_len, layers, top_k], 3,872 bytes per token for Super. A ~926-row slice padded to 55k tokens is a single 185 GiB host tensor (233 GiB with a longer tail row), which OOM-killed the leader's node on every attempt at the second chunk of step 0.Change. Add an optional
async_rl.max_groups_for_streaming_train(PositiveInt, defaultNone) and clamp the pump'smax_prompt_groupstomin(step_remainder, max_groups_for_streaming_train)when the cap is set. Unset (the default) leaves the chunk bounded only by the step remainder, exactly as before, so existing streaming configs see no behavior change. A validator rejects a max below the min;min_groups_for_streaming_trainis tightened toPositiveInt. The sampler, staleness window and training claims are untouched.Sizing the cap. Per-leader host bytes ≈
rows_per_leader × padded_len × layers × top_k × 2, withrows_per_leader ≈ chunk_groups × generations / dp_replicas. Measured on Super at DP4, 81,920 context:Step time is unchanged because the step is training-bound (policy training ≈ 97 % of the step); chunking only changes fetch cadence.
Usage
Testing
routed_experts_row_coverage1.0,token_mult_prob_error1.007, no OOM kills.tests/unit/models/generation/test_vllm_utils.py: uint8/uint16/uint32 backend ids throughpad_and_align_routed_expert_indices(prompt and completion routes, default padding route), and the overflow guard seeing the unwrapped uint16 id.tests/unit/single_controller/test_resiliency_config.py:max_groups_for_streaming_traindefaultNone,max < minrejected,max == minallowed, non-positive bounds rejected.Checklist
None, which keeps the previous step-remainder chunk bound; existing configs are unaffected.docs/guides/single-controller.mdfield definitions and thegrpo_math_1B_megatron_single_controller.yamlexemplar🤖 Generated with Claude Code