Skip to content

fix(reward-penalties): share one malformed-think-tag predicate - #5392

Open
four1er wants to merge 1 commit into
NVIDIA-NeMo:mainfrom
four1er:fix/malformed-think-tag-shared-predicate
Open

four1er wants to merge 1 commit into
NVIDIA-NeMo:mainfrom
four1er:fix/malformed-think-tag-shared-predicate

Conversation

@four1er

@four1er four1er commented Nov 23, 2026 •

Copy link
Copy Markdown
  • I, the PR author, have personally reviewed every line of this PR.

What and why

The echo path (apply_reward_penalties) ran its own token-ID and string checks for malformed think tags while the capture path ran has_malformed_think_tag, so the two could disagree. The echo path now calls the same predicate once per (user, assistant) turn.

The predicate's text check also had a hole: it only flagged a decoded close tag when its count exceeded 1, so a thinking-off turn where the model spells out </think> with ordinary tokens (ID check expects 0 close tags) was not penalized. When the tag IDs are known, the text check now compares the close-tag count against the count the ID check expects (0 or 1); > 1 is kept only when the IDs are unknown.

The parity test is kept and extended with the thinking-off spelled-out case (it still guards the echo turn pairing and the capture link-span slicing), plus two new regression tests for the spelled-out close tag on each path.

One known limitation, in the echo path only: generation_str is decoded with special tokens skipped, so a thinking-on turn with one real close tag plus one spelled-out close tag still reads as one close tag and is missed there. The capture path (decoded with special tokens kept) catches it.

Issues

Fixes #5008

Convergence / perf / functionality proof

N/A: reward-penalty logic only. tests/unit/experience/test_capture_reward_penalties.py: 504 passed locally; new tests fail on unpatched source and pass with the fix. No GPU end-to-end run (no GPU on this machine).

Needs upstream changes

None

…n echo and capture paths

apply_reward_penalties now calls has_malformed_think_tag per turn
instead of running its own ID and string checks, so both paths run
the same rule. The text check compares the decoded close-tag count
against the count the ID check expects (0 or 1) when the IDs are
known, keeping > 1 only when they are not: a spelled-out </think>
in a thinking-off turn is now a violation. The parity test is kept
and extended (it still guards the echo turn pairing and the capture
link-span slicing), with new regression tests for the spelled-out
close-tag case.

Fixes NVIDIA-NeMo#5008

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

copy-pr-bot Bot commented Nov 23, 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.

@four1er

four1er commented Nov 23, 2026

Copy link
Copy Markdown
Author

/ok to test 5025d47

@github-actions github-actions Bot added the CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) label Nov 23, 2026
@four1er four1er changed the title fix(reward-penalties): share one malformed-think-tag predicate between echo and capture paths fix(reward-penalties): share one malformed-think-tag predicate Nov 23, 2026
@four1er

four1er commented Nov 23, 2026

Copy link
Copy Markdown
Author

@claude /review-pr-team 5392

@svcnvidia-nemo-ci svcnvidia-nemo-ci added the waiting-on-maintainers Waiting on maintainers to respond label Nov 25, 2026

This branch has not been deployed

No deployments
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) community-request waiting-on-maintainers Waiting on maintainers to respond

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor(reward-penalties): share one malformed-think-tag predicate between the echo and capture paths

2 participants