Skip to content

feat(capture): support reward penalties and effort shaping - #4099

Merged
yfw merged 4 commits into
mainfrom
pranav/token_capture_reward_penalization
Oct 9, 2026
Merged

yfw merged 4 commits into
mainfrom
pranav/token_capture_reward_penalization

Conversation

@pthombre

@pthombre pthombre commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Support duplicated-reasoning, empty-final-answer, and unwanted-token reward penalties on the token-capture path, and make effort shaping match non-capture rollouts for equivalent scored trajectories.

Capture previously shaped rewards using accumulated response usage. For a low-effort rollout with call lengths 900 then 100, raw reward 1, and low_weight=low_penalty=1, low_ub=1000, capture now produces 1.9, matching the standard path's terminal-call length.

  • Both paths share text detectors, token membership, original-prompt classification, and the effort formula in one module. Reuse the existing reward and effort configuration models.
  • The manager saves the raw reward and one three-boolean RewardChecks record. Existing sibling/prompt-group recovery and finalizer requests carry this record.
  • After Gym verifies the selected chain, shape using the terminal generated span, then set the reward to zero for any enabled penalty, including when the shaped reward is negative. Unwanted IDs are checked across selected generated spans, including terminal tokens and excluding prompt/tool carries and abandoned branches.
  • Save and compare reward settings once per checkpoint. Pool valid-row reward/penalty statistics and exact effort-length frequencies, preserving metrics across recovery without double counting.

No environment reward plumbing, per-rollout fingerprints, additional token fetches, tokenizer decoding, or Gym/vLLM schema changes. Captured tokens, logprobs, and masks retain their existing behavior.

Issues

No linked issue.

Usage

Use the existing reward_penalties flags and env.nemo_gym.effort_levels settings. Defaults are unchanged; active shaping requires low_ub > 0. See the Single-Controller guide.

Before your PR is "Ready for review"

  • Followed contributor guidelines and signed off commits.
  • Added parity, recovery, configuration, metrics, and live TQ/Gym tests.
  • Ran tests and type checks through Slurm.
  • Updated documentation.

Additional Information

Validation for e3ad0eaa807e59a6c53dc5e6caa4929fc938c60e (identical code tree to the previously tested commit; Git identity corrected): 1,772 distinct tests passed, counting the latest result of each test after targeted fixes.

  • Slurm 3678328: 1,629 unit/controller tests passed and all 140 live TQ/Gym tests passed. One stale setup assertion and focused type-narrowing diagnostics were fixed. Broader pyrefly matched main's 17 existing diagnostics, with none introduced.
  • Slurm 3678404: corrected assertion and two effort-bound tests passed; the expanded setup fixture needed its Gym enable flag, fixed afterward.
  • Slurm 3678475: COMPLETED, exit 0:0, elapsed 00:05:03. All 5 setup/configuration cases and 107 finalizer regressions passed; focused pyrefly reported zero errors (one existing ignored diagnostic).
  • Ruff lint, import sorting, formatting, and whitespace checks passed.

Coverage includes all eight penalty combinations; positive/zero/negative rewards; disabled, low, and high effort; unequal call lengths; missing/misleading usage; both recovery modes; exact pooled medians; and metrics consumed once. Live TQ tests feed published rewards into the real GRPO advantage estimator and assert unchanged tokens, logprobs, and masks.

Recovery schema 5 saves the combined checks. Legacy capture checkpoint migration is outside scope. Malformed-thinking penalties and message-level advantage overrides remain unsupported with capture. Validation does not include full model generation/training or convergence measurements.

The latest follow-up adds the missing copyright header to tests/unit/experience/test_capture_reward_penalties.py, fixing the copyright CI failure. Tests were not rerun for this header-only change.

@copy-pr-bot

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

@github-actions github-actions Bot added the Documentation Improvements or additions to documentation label Sep 11, 2026
@pthombre
pthombre force-pushed the pranav/token_capture_reward_penalization branch from 45aef0a to 877707f Compare September 11, 2026 23:36
@pthombre
pthombre marked this pull request as ready for review September 11, 2026 23:37
@pthombre
pthombre requested review from a team as code owners September 11, 2026 23:37
@pthombre pthombre added the CI:L1 Run doctests, unit tests, and functional tests label Sep 11, 2026
@pthombre

Copy link
Copy Markdown
Contributor Author

/ok to test 8c66da0

@pthombre
pthombre marked this pull request as draft September 11, 2026 23:46
@pthombre

Copy link
Copy Markdown
Contributor Author

/ok to test 518b9e7

@macandro96 macandro96 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.

Merge conflicts — this PR currently shows as CONFLICTING/DIRTY against main. The conflicts are narrow (2 files: nemo_rl/algorithms/single_controller.py, tests/unit/experience/test_rollout_reassembler_actor.py), but please rebase before further review.

Reviewed by a team of specialized agents (RL expert, bug finder, test agent, design reviewer) with an adversarial pass to stress-test every finding before posting. A few notes that didn't make it into inline comments:

Credit: _abandon_entire_group now also clears attempt.mask_sample (rollout_recovery.py:459), which incidentally fixes a pre-existing latent restore bug (verified against the base commit).
Credit: reward_penalties.py has no capture-vs-inline conditionals — the detectors, membership checks, and effort formula are single implementations shared by both paths, backed by a genuine differential parity harness rather than just coverage.
No convergence/A-B run requested: all new flags default off, so this PR is a no-op unless opted into, and the reward math is closed-form and pinned by exact parity tests (including one asserting real GRPO advantage values with unchanged tokens/logprobs).
Test evidence: 786 tests run locally (785 passed, 1 skipped), zero never awaited warnings. Pre-commit: all hooks pass clean.
Generated by Claude Code

Comment thread nemo_rl/algorithms/single_controller.py Resolved
Comment thread nemo_rl/experience/rollout_manager.py Resolved
Comment thread nemo_rl/experience/rollouts.py Resolved
@pthombre
pthombre force-pushed the pranav/token_capture_reward_penalization branch from 518b9e7 to 1df0a0a Compare September 17, 2026 08:29
@pthombre
pthombre force-pushed the pranav/token_capture_reward_penalization branch from 1df0a0a to bad4645 Compare October 1, 2026 16:28
@pthombre

pthombre commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test bad4645

@copy-pr-bot

copy-pr-bot Bot commented Oct 1, 2026

Copy link
Copy Markdown

/ok to test bad4645

@pthombre, there was an error processing your request: E2

See the following link for more information: https://docs.gha-runners.nvidia.com/cpr/e/2/

@pthombre

pthombre commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 5818ddb

@copy-pr-bot

copy-pr-bot Bot commented Oct 1, 2026

Copy link
Copy Markdown

/ok to test 5818ddb

@pthombre, there was an error processing your request: E2

See the following link for more information: https://docs.gha-runners.nvidia.com/cpr/e/2/

@pthombre

pthombre commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 5818ddb

Comment thread nemo_rl/algorithms/single_controller.py Resolved
Comment thread nemo_rl/experience/reward_penalties.py Resolved
Comment thread nemo_rl/experience/rollout_recovery.py Resolved
@pthombre
pthombre force-pushed the pranav/token_capture_reward_penalization branch from abfb290 to 4efa3c6 Compare October 7, 2026 18:31
macandro96
macandro96 previously approved these changes Oct 8, 2026
pthombre and others added 4 commits October 8, 2026 15:35
Support duplicated-reasoning, empty-final-answer, and unwanted-token reward
penalties on the token-capture path, and make effort shaping match
non-capture rollouts for equivalent scored trajectories.

- Share text detectors, token membership, original-prompt classification,
  and the effort formula between both paths in reward_penalties.py.
- The manager saves the raw reward and one three-boolean RewardChecks
  record; sibling/prompt-group recovery and finalizer requests carry it.
- After Gym verifies the selected chain, the finalizer shapes using the
  terminal generated span, then zeroes the reward for any enabled penalty.
- Save and compare reward settings once per checkpoint (recovery schema 6);
  pool valid-row reward/penalty statistics and effort-length frequencies
  across recovery without double counting.

Squash of the five original PR commits for the rebase onto main.

Signed-off-by: Pranav Prashant Thombre <[email protected]>
…test

main made is_final_checkpoint a required keyword of
SingleControllerActor._save_checkpoint (#4213 lifecycle changes); the
rebased PR test still used the old two-argument form and failed with a
TypeError in the Slurm verification run.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: Pranav Prashant Thombre <[email protected]>
…chema

Address the second review round on the capture reward-penalty PR:

- Release pending finalizer metrics and reward observations for groups
  that leave the replay buffer without being trained on: pop them when a
  committed group falls below min_valid_fraction_per_group, and prune
  them against the live buffer after stale eviction.
- Renumber the rollout recovery sidecar to schema 3 and accept only the
  current schema. reward_settings, finalizer_metrics_by_group and
  finalizer_rewards_by_group are now required sidecar keys; a sidecar
  saved with capture disabled is rejected under capture with a specific
  error.
- CaptureRewardSettings.from_state accepts only version-1 records. The
  bootstrap identity builds its projection from the typed config models
  in a dedicated _normalize_capture_reward_config helper.
- Drop the redundant finalize/reward_{count,sum,sumsq,min,max} group
  statistics; aggregate_capture_reward_metrics derives every reward
  statistic from the retained per-row observations, which are now
  required.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: Pranav Prashant Thombre <[email protected]>
main migrated MasterConfig.logger from a TypedDict to the LoggerConfig
model, so the capture controller must use attribute access when deciding
whether to log full-result tables. main also made the advantage stage
require a group_id tag on every row, so the recovered-statistics pump
test stamps one per group.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: Pranav Prashant Thombre <[email protected]>
@pthombre
pthombre force-pushed the pranav/token_capture_reward_penalization branch from 4efa3c6 to 2ba5bf1 Compare October 8, 2026 22:45
@pthombre

pthombre commented Oct 8, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 2ba5bf1

@copy-pr-bot

copy-pr-bot Bot commented Oct 8, 2026

Copy link
Copy Markdown

/ok to test 2ba5bf1

@pthombre, there was an error processing your request: E2

See the following link for more information: https://docs.gha-runners.nvidia.com/cpr/e/2/

@pthombre

pthombre commented Oct 8, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 2ba5bf1

@yfw yfw added CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) and removed CI:L1 Run doctests, unit tests, and functional tests labels Oct 8, 2026
@yfw

yfw commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

/ok to test 2ba5bf1

@yfw
yfw enabled auto-merge (squash) October 8, 2026 23:14
@yfw
yfw merged commit f5bb864 into main Oct 9, 2026
210 of 212 checks passed
@yfw
yfw deleted the pranav/token_capture_reward_penalization branch October 9, 2026 06:56
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]>
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) Documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants