NVIDIA-NeMo/RL #4776 ยท commits 97e23867f, c3977d53d ยท all links pinned to head 96ec8a36
Three pages on this PR, one question each. This one: the think-tag penalty.
<think> plan </think> answer.
When thinking is on, the chat template already puts <think> at the end of the prompt, so the model should write exactly one </think> and no <think>.
When thinking is off, the template puts an empty <think></think> in the prompt, and the model should write no tags at all.
The think-tag penalty sets a rollout's reward to 0 when the model breaks this, so training stops rewarding broken output.
A rollout comes back from Gym in one of two formats, shown below. All of the penalty runs in RL, on both paths. Gym only returns the task reward from its /run call; RL checks the tokens and sets that reward to 0. Dotted words have a short explanation: hover or tap them.Here is one coding-agent rollout with two turns. In each turn, some new prompt tokens arrive (the task, or a tool result), and then the model writes some tokens.
The echo path gets this as chat messages: a user message with the new prompt tokens, then an assistant message with what the model wrote.
The token-capture path gets the exact token list vLLM saw and sampled, with no messages. Instead, Gym adds a list of
spans:
one pair of lengths per turn, (new prompt tokens, model tokens). The new code walks the list with those lengths and cuts out the same turns.
For each turn: look at the new prompt to decide if thinking is on, then count the tags the model wrote.
It counts twice. First it counts the special tag tokens. Then it turns the model's tokens back into text and counts the tag strings, because a model can also spell </think> out of ordinary pieces like </ think >, which the token count cannot see.
Reward starts at 1.0 in every row:
| New prompt ends with | Model wrote | Tag tokens | Tag text | Reward |
|---|---|---|---|---|
<think> (thinking on) | plan </think> ls | 0 open, 1 close: ok | ok | 1.0 |
<think> | plan ls (never closed) | 0 close, need 1 | 0 | |
<think> | <think> plan </think> ls | 1 open, need 0 | 0 | |
<think> | plan </think> ls, but <think> spelled from plain pieces | looks ok | 1 <think> string | 0 |
<think></think> (thinking off) | ls | none: ok | ok | 1.0 |
<think></think> | </think> ls | 1 close, need 0 | 0 | |
<think></think> | </think> ls, spelled from plain pieces | looks ok | 1 close string, allowed up to 1 | 1.0 (missed) |
On capture, RL's finalizer runs this after rebuilding the token list, and the trainer only sees the final reward. Code: has_malformed_think_tag (capture, new) and the echo check use the same counts.
| Echo | Token capture (this PR) | |
|---|---|---|
| Where the tag text comes from | the text Gym sends with each reply | RL turns the tokens back into text with the tokenizer, so it now loads one, only when this penalty is on |
| Extra check on the answer text | RL also checks each reply's final answer text and flags any tag in it | Not done: capture has only tokens, no separate answer text. The docs say so. |
| Resume from a checkpoint | nothing saved | The tag settings are saved, and a resume with different tags is refused |
The gap is the last table row above: thinking off, and the model spells </think> from plain pieces. The token count expects 0 and sees 0. The text count allows up to 1 on every turn, even though a thinking-off turn should allow 0. So nothing fires. Echo has the same rule, so this PR does not make anything worse. The fix for both paths: when thinking is off, allow 0 close strings, not 1.
โช C3 ยท review comment โ reward_penalties.py:495