Skip to content

fix(rollout): avoid retaining full routed-expert buffers in message slices - #4915

Merged
ZhiyuLi-Nvidia merged 3 commits into
NVIDIA-NeMo:mainfrom
u-brixton:rzayashnikov/gym-route-storage-20261026
Oct 28, 2026
Merged

ZhiyuLi-Nvidia merged 3 commits into
NVIDIA-NeMo:mainfrom
u-brixton:rzayashnikov/gym-route-storage-20261026

Conversation

@u-brixton

@u-brixton u-brixton commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Routed-expert slices stored in message logs can retain the full turn or padded generation batch, causing oversized backing storage during serialization.

Use a shared slice_routed_experts helper so each message owns only its token span in Gym postprocessing, synchronous/asynchronous generation, and the async rollout manager. Release the full decoded Gym turn before processing the next one.

Validation at 2eed022f:

  • 13 focused CPU tests passed across the codec, Gym router replay, and rollout-manager router replay modules. These cover values, dtype, storage ownership, decoded-buffer lifetime, multi-turn updates, and pickle round-tripping.
  • Direct CPU smoke checks passed for synchronous and asynchronous generation with padded two-row batches, multiple prefix messages, reversed async completion order, independent storage, and cloudpickle round-tripping.
  • Scoped Ruff lint, import sorting, formatting, and diff checks passed.

The tests used the prepared runtime without model inference or training. No full training or full-suite run was performed for this PR.

Follow-up validation at d619e951: scalar slice bounds are explicitly converted to Python integers. Pyrefly checks on the affected files, seven CPU codec tests, and scoped Ruff lint/formatting passed.

@copy-pr-bot

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

@u-brixton

Copy link
Copy Markdown
Contributor Author

/ok to test fa52126

@u-brixton
u-brixton force-pushed the rzayashnikov/gym-route-storage-20261026 branch from fa52126 to 65cd797 Compare October 27, 2026 22:01
@u-brixton u-brixton changed the title fix(nemo-gym): compact routed-expert tensor storage fix(nemo-gym): avoid retaining full routed-expert buffers in message slices Oct 27, 2026
@u-brixton
u-brixton marked this pull request as ready for review October 27, 2026 22:13

@ZhiyuLi-Nvidia ZhiyuLi-Nvidia 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.

Review: LGTM on this PR's change, plus a suggested follow-up for the same bug elsewhere.

This PR: cloning the routed-expert slices in nemo_gym.py is correct. Each message now owns exactly its token span, and the new storage-size and pickle round-trip assertions cover it.

Same bug, other places (suggestion, low severity): the same view-retains-full-buffer pattern exists where rollout message logs are built. These sites are outside this PR's diff:

File Site
nemo_rl/experience/rollouts.py _attach_routed_experts_to_message_log_prefix
nemo_rl/experience/rollouts.py generate_responses and generate_responses_async (assistant slice)
nemo_rl/experience/rollout_manager.py AsyncRolloutImpl._generate_response (assistant slice)

Proposed change: one shared helper, slice_routed_experts(routed_experts, start, end) in nemo_rl/utils/routed_experts_codec.py (torch-only, already imported by nemo_gym.py), used at all 7 sites including the 2 in nemo_gym.py. It is a single .clone() of the slice, with one docstring explaining why.

Where it is: branch fix/clone-routed-experts-slices, commit 4b8bbf9, stacked on this PR's head (65cd797). Diff: 65cd797...4b8bbf9
Please cherry-pick it into this PR or merge it after this PR; I have not touched this PR's branch.

u-brixton and others added 2 commits October 28, 2026 15:27
…rts helper

Slices of the per-sample routed_experts tensor were views sharing the full
buffer's storage, so serializing a message could carry the whole sample.
Add slice_routed_experts (clone of the slice) to routed_experts_codec and use
it at every message-slice site: nemo_gym postprocess, rollouts prefix attach,
generate_responses{,_async}, and the async rollout manager. Assert storage
ownership in the rollout manager test.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Signed-off-by: Zhiyu Li <[email protected]>
Signed-off-by: Renat Zayashnikov <[email protected]>
@u-brixton
u-brixton force-pushed the rzayashnikov/gym-route-storage-20261026 branch from 65cd797 to 2eed022 Compare October 28, 2026 14:52
@u-brixton u-brixton changed the title fix(nemo-gym): avoid retaining full routed-expert buffers in message slices fix(rollout): avoid retaining full routed-expert buffers in message slices Oct 28, 2026
ZhiyuLi-Nvidia
ZhiyuLi-Nvidia previously approved these changes Oct 28, 2026

@ZhiyuLi-Nvidia ZhiyuLi-Nvidia 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.

Thank you @u-brixton for the fix, LGTM!

@ZhiyuLi-Nvidia

Copy link
Copy Markdown
Contributor

/ok to test 2eed022

@ZhiyuLi-Nvidia
ZhiyuLi-Nvidia enabled auto-merge (squash) October 28, 2026 16:26
auto-merge was automatically disabled October 28, 2026 17:03

Head branch was pushed to by a user without write access

@ZhiyuLi-Nvidia ZhiyuLi-Nvidia added the CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) label Oct 28, 2026
@ZhiyuLi-Nvidia

Copy link
Copy Markdown
Contributor

/ok to test d619e95

@ZhiyuLi-Nvidia
ZhiyuLi-Nvidia enabled auto-merge (squash) October 28, 2026 17:27
@ZhiyuLi-Nvidia
ZhiyuLi-Nvidia merged commit 3b022ba into NVIDIA-NeMo:main Oct 28, 2026
101 checks passed
jthomson04 added a commit to jthomson04/RL that referenced this pull request Oct 28, 2026
Resolves the conflict in nemo_rl/utils/routed_experts_codec.py: this branch
added routed_experts_envelope_dtype and NVIDIA-NeMo#4915 added slice_routed_experts at
the same spot. Both are kept.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: jthomson04 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants