How a validation rollout skips token capture, next to a training rollout

NVIDIA-NeMo/RL#5098 Β· RL half of NVIDIA-NeMo/Gym#5711 Β· links pinned to RL cceb2eb and Gym 9e2e5d0

Before
With token capture on, Gym captured every model call of a capturing agent, validation included. RL's vLLM worker would store token ids it never trains on, and RL's Gym actor masked any rollout with no capture.
This PR
Validation rows carry a flag. Gym captures nothing for them, and RL's Gym actor returns their reward without looking for a capture.
Status
Added by this PR. No run can use it yet, and no setting turns it on. Validation rows now get the mark, but every validation run builds its Gym actor with token capture off, so Gym ignores it. The skip branch in RL's Gym actor only runs with capture on, and only the single controller turns capture on. The single controller has no validation loop yet, and it clears the mark from every row. The code is ready for when that validation loop is added.
Background. Token capture stores each model call's tokens in TransferQueue while Gym runs the rollout. When the rollout ends, RL's Gym actor reads the rollout's manifest and turns it into a receipt. Validation only needs the reward, so capturing it is wasted work. Dotted words have a short explanation: hover or tap them.

The flag is one row key, _ng_skip_token_capture, copied from Gym's SKIP_TOKEN_CAPTURE_KEY_NAME, with a test that fails if the two differ. RL sets it in _prepare_nemo_gym_rows when a validate function passes skip_token_capture=True, and removes it otherwise. Gym reads it from the top of the row in skips_token_capture. RL's Gym actor checks it in finish_capture. The figure follows one row of each kind, using the PR's own test values (reward 0.5, rollout id "val-1").

The two paths, step by step

Training rollout (unchanged) Validation rollout (this PR) same in both where the two differ process boundary β‘  RL driver (validate / train loop) _prepare_nemo_gym_rows(skip=False) {"_ng_rollout_index": 0, …} mark removed, even if the dataset row had one _prepare_nemo_gym_rows(skip=True) {…, "_ng_skip_token_capture": true} grpo / distillation / grpo_sync validate row sent to Gym (HTTP)row sent to Gym (HTTP) β‘‘ Gym agent server (its own process) _run_captures = capture_on and not skip = True β†’ every model call stored tokens + logprobs go to TransferQueue skips_token_capture(body) β†’ True _run_captures = False β†’ nothing stored the agent still runs and the reward is still scored {reward: 0.5, response: …}{reward: 0.5, response: …} β‘’ RL's Gym actor (Ray actor), finish_capture _postprocess_receipt_mode(row, result) _drained_manifest(id) waits ≀300 s for calls GET …/rollouts/{id}/manifest builds the receipt from the manifest if row.get(SKIP_KEY) is True: return _skipped_capture_result(…) no manifest call, no wait before: no capture β†’ masked as a lost rollout β‘£ result handed back to RL {message_log: [], input_message_log: [], full_result: {reward: 0.5, …}, receipt: {…stored calls…}} {message_log: [], input_message_log: [], full_result: {reward: 0.5, …}, rollout_id: "val-1", receipt: None} Same keys in both. Only receiptdiffers: a skipped rollout has nothing stored, so it has no receipt.

The two rows split at step β‘  and join again at step β‘£: both results have the same keys, with empty message logs, because under capture the tokens live in TransferQueue, not in the reply. Only receipt differs. Training rows can never keep the mark. _prepare_nemo_gym_rows removes it, and so does the single controller's _build_inputs. That matters because Gym's dataset prep keeps a dataset row's mark. With capture off, Gym ignores the mark and RL never calls finish_capture.

The change, as pseudocode

RL driver, after

# driver process: validate() β†’ run_nemo_gym_rollout_sync β†’ run_async_nemo_gym_rollout
def prepare_rows(rows, …, *, skip_token_capture=False):
    for row in rows:
        stamp sampling, group id, rollout index           # unchanged
        if skip_token_capture: row[SKIP_KEY] = True          # validation
        else:                  row.pop(SKIP_KEY, None)      # training: never skip

Real code: _prepare_nemo_gym_rows, rollout_to_tq (grpo_sync)

RL's Gym actor, after

# Gym actor event loop: one task per finished rollout, run side by side
async def finish_capture(task):
    row, result = await task
    if result is an error: return row, result
    if row.get(SKIP_KEY) is True:                      # Gym stored nothing for this row
        return row, {logs: [], full_result: result, receipt: None}
    return row, await receipt_mode(row, result)   # reads the manifest, builds a receipt

Real code: finish_capture, _skipped_capture_result

Who can reach this today

Nothing reaches it yet, and no setting changes that. Step β‘  runs today: every GRPO, distillation and grpo_sync validation call marks its rows. But those runs build their Gym actor without capture (grpo.py, distillation.py), so Gym ignores the mark and steps ⑑–⑒ take the old path. Only the single controller passes token_capture to the Gym actor. It has no validation loop yet, and it removes the mark from every row. So the new skip branch in step β‘’ can't run until the single controller gets a validation loop.

So what. The PR adds the RL half of a two-repo change, and it is ready for when validation runs with capture on. One thing that change will need: the old training loops' batch builder reads input_message_log[0], so it can't use any result from step β‘£, captured or skipped. Whoever turns on validation with capture must read the reward from full_result instead. The review asks for a shorter docstring on _skipped_capture_result that points to the single controller's tracking issue, #5044. This PR and #5044 now link each other: the PR description names #5044, and a comment on #5044 tells whoever builds that validation loop to set the mark and read full_result.

🟑 review comment C3 β€” nemo_gym.py:2098