Skip to content

fix(gym): per-agent_ref truncation/token metrics (#3970, #4030) - #4379

Merged
yfw merged 2 commits into
mainfrom
pjin/agent-ref-metrics-20260930
Oct 8, 2026
Merged

yfw merged 2 commits into
mainfrom
pjin/agent-ref-metrics-20260930

Conversation

@pjin-nvidia

Copy link
Copy Markdown
Contributor

Port of 72fc46b (per-agent-ref truncation rate) and 95d3cc3 (per-agent_ref {total,gen}_tokens_per_sample) onto this branch.

Adds {agent}/truncation_rate, {agent}/total_tokens_per_sample/* and {agent}/gen_tokens_per_sample/* in both the batched NeMo-Gym postprocess path (rollouts.py) and AsyncNemoGymRolloutImpl._compute_rollout_metrics. Live token metrics are emitted after full-result metrics so similarly named env metadata cannot overwrite them. In receipt mode the per-agent token metrics use the manifest-derived counts; a test covers this.

Port of 72fc46b (per-agent-ref truncation rate) and 95d3cc3
(per-agent_ref {total,gen}_tokens_per_sample) onto this branch.

Adds {agent}/truncation_rate, {agent}/total_tokens_per_sample/* and
{agent}/gen_tokens_per_sample/* in both the batched NeMo-Gym postprocess
path (rollouts.py) and AsyncNemoGymRolloutImpl._compute_rollout_metrics.
Live token metrics are emitted after full-result metrics so similarly
named env metadata cannot overwrite them. In receipt mode the per-agent
token metrics use the manifest-derived counts; a test covers this.

Signed-off-by: Peter Jin <[email protected]>
@copy-pr-bot

copy-pr-bot Bot commented Sep 30, 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.

@pjin-nvidia pjin-nvidia changed the title fix(gym): port per-agent_ref truncation/token metrics (#3970, #4030) fix(gym): per-agent_ref truncation/token metrics (#3970, #4030) Sep 30, 2026
@yfw yfw added the CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) label Oct 5, 2026
@yfw

yfw commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

/ok to test b28cc80

@yfw
yfw enabled auto-merge (squash) October 5, 2026 23:48
@nemo-automation-bot
nemo-automation-bot Bot requested a review from a team October 5, 2026 23:49
@yfw
yfw disabled auto-merge October 5, 2026 23:50
@yfw

yfw commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

/ok to test 6833b58

@yfw
yfw enabled auto-merge (squash) October 8, 2026 02:40
@yfw
yfw merged commit 26e0b07 into main Oct 8, 2026
94 checks passed
@yfw
yfw deleted the pjin/agent-ref-metrics-20260930 branch October 8, 2026 04:16
linj-glitch added a commit to linj-glitch/RL that referenced this pull request Oct 13, 2026
Reconciles the straggler cutoff with what main gained on the NeMo-Gym
rollout path since the branch was cut: reward penalties and effort shaping
(NVIDIA-NeMo#4099), per-prompt-group length penalties (NVIDIA-NeMo#4553) and per-agent token
metrics (NVIDIA-NeMo#4379).

- A cut placeholder is not a model output. _postprocess_single_nemo_gym_group
  now runs effort shaping and the reward-penalty checks over the scored rows
  only, and reports the penalty rates over that population, so an empty
  placeholder response is not counted as an "empty final answer". Cut rows
  also stay out of main's new per-agent token/truncation metrics, alongside
  the existing exclusion from the per-agent full_result means. Length
  penalties need no change: they only adjust rows with a positive reward.
- Token-capture (receipt) mode is unsupported: a cancelled rollout has no
  receipt for the finalizer to rebuild. The actor now logs once and runs the
  batch uncut, the same fallback as a Gym without aclose(); the warning text
  names the reason.

Tests: receipt-mode fallback; penalty rate and rewards with a cut row under
penalize_empty_final_answer; per-agent gen-token mean excludes the cut row.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: Lin Jia <[email protected]>
pjin-nvidia added a commit that referenced this pull request Oct 14, 2026
Signed-off-by: Peter Jin <[email protected]>
Co-authored-by: Yi-Fu Wu <[email protected]>
(cherry picked from commit 26e0b07)
Signed-off-by: Peter Jin <[email protected]>
pjin-nvidia added a commit that referenced this pull request Oct 14, 2026
With token capture the controller logged no rollout metrics:
total_reward, turns_per_sample, {total,gen}_tokens_per_sample,
max_gen_tokens_per_turn, truncation_rate, natural_termination_rate,
the per-agent metrics and timing/rollout/* were all missing (a 40-node
MOPD run logged 134 non-Ray scalars per step, against 3688 for the
same configuration without capture). The capture dispatch dropped the
PromptGroupRecord that run_rollout returns, and the finalizer
published its KVBatchMeta without extra_info[ROLLOUT_METRICS], the
only place the train pump reads rollout metrics from. The dropped
receipt-mode values were also wrong: a root call's delta_len includes
its prompt, so sum(delta_len) measured the whole row rather than the
generated tokens, and receipts were never marked truncated.

The finalizer now measures each group's canonical rows and publishes
the metrics with them, under the token path's names and per-sample
definitions: rewards over every rollout; turns (model calls on the
trained chain), total and generated tokens, the longest call's
generation and truncation (row length == max_seq_len, the rule
behind the published truncated column) over the rows that verified;
and the per-agent token and truncation metrics of #4379 under the
resolved agent name. The dispatcher's own metrics (agent results,
rollout timing) ride the ReassemblyRequest, filtered to numbers and
number lists for the metadata-only RPC, and are published beneath
the measured ones. The receipt branch of _compute_rollout_metrics no
longer emits its manifest proxies.

The teacher enricher and the sampler already carry extra_info through
to aggregate_rollout_metrics; a finalizer lifecycle test now pins the
enricher side. A resumed group whose siblings were all sealed before
the restart regenerates nothing and carries no dispatcher metrics;
the finalizer still measures its rows.

Signed-off-by: Peter Jin <[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