Repository navigation
feat(nemo-gym): optionally mask unusable rollouts instead of failing the batch - #4494
linj-glitch wants to merge 7 commits into
Conversation
2d5658e to
e4a2a5c
Compare
e4a2a5c to
a453f6b
Compare
|
Dependency: this PR is stacked on #4435 (first-class |
|
/ok to test a453f6b |
a453f6b to
792c9b2
Compare
|
/ok to test 792c9b2 |
…the batch _postprocess_nemo_gym_to_nemo_rl_result raises ValueError when a Gym result carries no generation data (the first prompt already exceeds max_model_len, or the agent produced no assistant turn), and an AssertionError when the token chain is not contiguous across turns (agent harnesses that rewrite or compact their history). Either exception ends the whole run_rollouts stream, so one bad rollout fails its batch; the async collector then re-runs the entire batch while the abandoned rollouts keep running in Gym. Add env.nemo_gym.mask_unusable_rollouts (default false, which keeps the current fail-loudly behavior). When enabled, such a rollout becomes a placeholder sample instead: - no generation data: a fixed 128-token prompt (start of the input text, padded with EOS) plus one EOS "generation" token with logprob 0; - non-contiguous chain: the contiguous prefix is kept. The result gets top-level mask_sample=True and an _ng_unusable_rollout marker. Rollout batching zeroes the loss weight of marked samples (loss_multiplier on the NeMo-Gym batch path, sample_mask on the RolloutManager payload path) regardless of env.should_mask_flagged_samples, so the placeholder never trains. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Lin Jia <[email protected]>
…ompt media With env.nemo_gym.mask_unusable_rollouts on, a result with no generation data becomes a text/EOS placeholder. The static-media restoration then copied the prompt's original image tensors onto it, in both rollout paths: _reattach_static_multimodal_payloads_to_result on the batched path and attach_static_multimodal_payload in the RolloutManager. The placeholder holds no media placeholder tokens, and the native Nemotron Omni forward (Megatron-Bridge ec835530e, modeling_nemotron_omni.py::NemotronOmniModel._merge_projected_media) requires one text placeholder per projected media feature, so a legacy Gym Nemotron Omni VLM run failed on "found 0 valid placeholders for 1 projected features" before the row's zero loss weight could exclude it. Identify the synthetic placeholder explicitly (reason constants and is_synthetic_unusable_rollout in experience/interfaces.py) and skip the restoration only for it. A non-contiguous rollout reduced to its contiguous prefix keeps real Gym tokens and still gets its media back. In the RolloutManager, take the group prompt from the first real sibling so the synthetic prompt never stands in for the group's prompt length, prompt ids or media while a real sibling exists. Reject mask_unusable_rollouts together with token_capture.enabled at setup: receipt rollouts bypass the converter that emits the placeholder, so the knob would be silently ignored. Tests: conversion -> static-media restoration -> flattened model inputs with a real PackedTensor, checked against the pinned Nemotron Omni alignment invariant (input invariant only, not a model forward), for the placeholder, the retained contiguous prefix, both restoration entry points, the RolloutManager path (gate on and off, mixed and all-synthetic groups) and record_to_train_batch. Also pin that a Gym-flagged no-generation result converts only under the knob and still raises by default, that an empty input yields the fixed-length placeholder prompt, the receipt-mode rejection, and top-level mask_sample rows beside an empty or absent instance_config. Co-Authored-By: Claude Fable 5.1 <[email protected]> Signed-off-by: Lin Jia <[email protected]>
… rollout With mask_unusable_rollouts on, the non-contiguous branch broke out of the converter loop before the per-item pops, so every trainable item from the first non-contiguous one onward kept prompt_token_ids, generation_token_ids, generation_log_probs and the base64 routed_experts envelope in full_result, while every other row was popped and decoded. That inconsistent shape flowed into Completion.env_extras, the per-agent metrics and the opt-in W&B full_result table. Pop the payloads from the dropped tail before breaking so a masked result has the same shape as any other row, and assert it in the non-contiguous test. Co-Authored-By: Claude Fable 5.1 <[email protected]> Signed-off-by: Lin Jia <[email protected]>
…de rejection The setup-time ValueError and the design doc told the operator that mask_unusable_rollouts is rejected together with `env.nemo_gym.token_capture.enabled`, but token capture is not an env.nemo_gym key: it is the top-level single-controller `token_capture:` block (MasterConfig.token_capture), which setup passes into build_nemo_gym_config. Name the real key so the operator can find which of the two settings to flip. Co-Authored-By: Claude Fable 5.1 <[email protected]> Signed-off-by: Lin Jia <[email protected]>
…he baseline The _mark_unusable_rollout docstring promised that the placeholder is masked from loss and baseline. Zero loss holds on every path, but only the single-controller advantage stage passes sample_mask into the baseline's valid mask; the batched GRPO and grpo_sync paths call calculate_baseline_and_std_per_prompt with an all-ones valid mask, so the placeholder's reward still enters its siblings' leave-one-out baseline (tracked in NVIDIA-NeMo#4160 / NVIDIA-NeMo#4490). Say exactly that in the docstring and the design doc, and note in _run_rollouts why a mixed group's placeholder may carry a prompt_ids_for_adv row cut at the real prompt's length (the SC baseline keys on GROUP_ID_TAG, so prompt ids are not a grouping key). Co-Authored-By: Claude Fable 5.1 <[email protected]> Signed-off-by: Lin Jia <[email protected]>
… encode fallback Three branches of the no-generation placeholder had no test: the slice to _UNUSABLE_ROLLOUT_PROMPT_TOKENS (which is what keeps the placeholder under any sequence limit; every existing test fed at most three tokens), _input_text over the Responses input shapes (plain string, list-of-parts content with an interleaved image part, system+user, non-dict and non-string items, dict, None) and the tokenizer.encode failure fallback to a filler-only prompt. Also pin the placeholder's input_message_log by length and identity instead of `== [user]`: that comparison passed only through CPython's identity shortcut, and a converter that copied the prompt turn would have turned it into "Boolean value of Tensor with more than one value is ambiguous" rather than a clean assertion failure. Co-Authored-By: Claude Fable 5.1 <[email protected]> Signed-off-by: Lin Jia <[email protected]>
|
Rebased onto current Two conflicts resolved against main's multimodal-reattachment change ( Local run: |
792c9b2 to
aeafeb9
Compare
Signed-off-by: Lin Jia <[email protected]>
|
/ok to test 1fef568 |
What does this PR do ?
Adds opt-in
env.nemo_gym.mask_unusable_rollouts(defaultfalse) so one rollout with no trainable output or a non-contiguous token chain does not fail the whole rollout batch.With the option enabled, a no-generation result becomes a text-only placeholder (128 prompt tokens plus EOS); a broken chain retains its contiguous prefix. Both receive an unusable-rollout reason and zero loss weight regardless of
env.should_mask_flagged_samples. Synthetic placeholders never reacquire the original prompt's media. A retained real prefix keeps its media, and a mixed group takes its prompt from the first real sibling.The integrated main includes #4160: these rows acquire zero dataset weight before trainer filtering, so their rewards are excluded from group statistics under either
grpo.masked_reward_policy, on legacy, TransferQueue and SingleController paths. The default strict behavior remains unchanged.Issues
None.
Usage
This option supports the token-echo path. Combining it with the top-level
token_capture.enabledreceipt mode is rejected during setup.Before your PR is "Ready for review"
Pre checks:
Additional Information
Merged main
d48b2e0f3d7fc4891b418ae603c8e8fa71482b9cadditively at1fef5689f2ed69b05973a467a45b98305aab7b17. The only source conflict contained independent additions: main's Gym log-directory helper and this PR's unusable-rollout helpers; both are retained. Documentation now reflects #4160's baseline handling. An independent audit verified preservation of both parent behaviors.Validation on the integrated tree, 2026-10-28 (native pytest with repository conftest and a local CPU Ray cluster):
Coverage includes opt-in/default-strict conversion, broken-chain cleanup, input truncation/fallback, unconditional zero loss, receipt-mode rejection, and media-free placeholders beside real multimodal siblings. The media tests check packed model-input alignment; a full Nemotron Omni forward or distributed training run was not repeated.
Full-repository pre-commit was run. Pyrefly reports 44 existing diagnostics, identical by file/message to the independently measured main baseline (
0e36f2e6a), with no new diagnostics. All remaining hooks pass; the final full-file hook rerun skips only that separately measured Pyrefly check. GitHub's current required checks and review gates remain authoritative.