You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 6dca502
Browse filesBrowse the repository at this point in the historyBrowse files
feat(nemo-gym): share looping labels and optional reward zeroing
Use Gym assessment before token rebuilding, preserve verifier grades and row metadata, and pool diagnostic counts across supported training paths. Keep raw dynamic sampling and make loop zeroing optional under the reward-shaping master switch.
TODO after NVIDIA-NeMo/Gym#6846 merges: replace temporary Gym pin a8913a1e7e75e1b9cbf82c9bf02c6c494259db52 with the landed squash commit. Dependency alignment and uv.lock belong to the prerequisite branch.
Signed-off-by: Renat Zayashnikov <rzayashnikov@nvidia.com>
Copy file name to clipboardExpand all lines: docs/guides/dapo.md
+38Lines changed: 38 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -43,12 +43,50 @@ Standard GRPO trains on all generated responses, even when they have identical r
43
43
*`dynamic_sampling_num_discarded_valid_samples`: The number of samples with a nonzero standard deviation that are discarded because the total exceeds `num_prompts_per_step * num_generations_per_prompt`. If this value is frequently high (e.g., above `0.5 * num_prompts_per_step * num_generations_per_prompt`) and `dynamic_sampling_num_gen_batches` is consistently 1, it suggests that a large fraction of the dataset is being discarded unnecessarily. To improve data efficiency, consider decreasing the `batch_multiplier`.
44
44
45
45
## Reward Shaping
46
+
46
47
DAPO introduces an overlong reward shaping mechanism to reduce reward noise and stabilize training. This approach penalizes responses that exceed a specified length threshold, helping to prevent the model from generating excessively long outputs while maintaining solution quality.
47
48
48
49
The response length is the total number of tokens over all generated assistant turns in a sample. For multi-turn rollouts (tool use, NeMo Gym agents, `max_rollout_turns > 1`), every generated assistant turn counts toward `max_response_length`. Assistant turns in the original prompt history, including empty placeholders, and user, environment, and tool turns do not count. Generated turns are identified by their `generation_logprobs` before missing logprobs are filled for training. For a single-turn rollout this is the length of the one generated assistant response.
49
50
50
51
For a detailed explanation of the overlong reward shaping mechanism, please refer to Section 3.4 of the [DAPO paper](https://arxiv.org/pdf/2503.14476). For implementation details, see the [`apply_reward_shaping`](../../nemo_rl/algorithms/reward_functions.py) function.
51
52
53
+
### Severe text looping diagnostics
54
+
55
+
NeMo Gym can assess severe repetition in assistant and reasoning text before token rebuilding removes the returned response. This diagnostic uses Gym's shared text classifier in one persistent spawned process per Gym actor, within the actor's existing CPU reservation. For loop-only reward shaping, enable assessment and the shaping stage, and leave the existing length settings unset:
56
+
57
+
```yaml
58
+
env:
59
+
should_use_nemo_gym: true
60
+
nemo_gym:
61
+
assess_looping: true
62
+
grpo:
63
+
reward_shaping:
64
+
enabled: true
65
+
zero_looping_rewards: true
66
+
stop_properly_penalty_coef: null
67
+
overlong_buffer_length: null
68
+
overlong_buffer_penalty: null
69
+
max_response_length: null
70
+
```
71
+
72
+
| Setting | Type and default | Behavior |
73
+
| --- | --- | --- |
74
+
| `env.nemo_gym.assess_looping` | Boolean, `false` | Assess returned assistant/reasoning text. Disabled runs create no diagnostic worker and do not scan text. |
75
+
| `grpo.reward_shaping.enabled` | Boolean, `false` | Master switch for the configured length penalties and loop zeroing. |
76
+
| `grpo.reward_shaping.zero_looping_rewards` | Boolean, `false` | Zero learning rewards for confirmed loops after other configured reward adjustments. Requires the master switch and assessment on every Gym shard. |
77
+
78
+
PPO uses the same settings under `ppo.reward_shaping`. For metrics only, enable assessment and leave both reward-shaping switches off. Loop zeroing with either the master switch or assessment off is rejected at startup. When inheriting a recipe, explicitly clear any existing length settings as shown above to select loop-only shaping. Configure either the truncation coefficient or all three DAPO parameters to add a length penalty.
79
+
80
+
Rows retain `is_looping` and `reasons` through normal results, recovery contexts and metadata tags. Classic GRPO training JSONL includes these fields under `metadata` and records the original grades in `verifier_rewards` alongside the training objective's `rewards`. Synchronous PPO uses the same shaping settings but does not provide this JSONL writer; asynchronous PPO does not support Gym. When restoring replay batches written before these fields existed, looping labels remain unassessed and unavailable original verifier grades are written as JSON `null`. Those completed outputs remain in the assessment-coverage denominator. `true` means a severe text witness, `false` means the supported checks completed, and `null` means unassessed, including unreadable text, work-limit exhaustion or unavailable process execution. Incomplete or length-limited responses remain assessable when their text is readable.
81
+
82
+
Training reports `looping/rate = flagged / assessed` when any output was assessed and `looping/coverage = assessed / completed`. The population includes completed outputs before dynamic sampling, including retained masked outputs, independently of verifier grade. The accompanying `looping/*_total` counts pool groups with unequal denominators. Execution padding and failed requests contribute no completed output.
83
+
84
+
SingleController omits looping ratios for restored steps whose complete pre-filter counts were not checkpointed and logs the affected step range. Reporting resumes on the next fully observed step; saved row labels still control objective zeroing throughout recovery.
85
+
86
+
When the shaping stage is enabled, the safeguard zeroes learning rewards only for known boolean `true` rows; false and unknown labels retain their existing reward adjustments. Raw verifier observations, published validation scores and sample/token masks retain their existing behavior.
87
+
88
+
Dynamic sampling keeps its existing raw/unshaped reward signal, so enabling loop zeroing does not change which groups it retains. Learning baselines and advantage normalization use the adjusted rewards of the retained rows. For example, verifier grades `[1, 0, 1, 0]` with a confirmed loop in the first row produce learning rewards `[0, 0, 1, 0]`, while the verifier grades and DS input remain `[1, 0, 1, 0]`. A raw-uniform group such as `[1, 1, 1, 1]` is still filtered out when dynamic sampling is enabled, even if one row loops.
Copy file name to clipboardExpand all lines: docs/guides/prorlv2.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -92,7 +92,7 @@ grpo:
92
92
- **Implementation**: `apply_reward_shaping()` in [`nemo_rl/algorithms/reward_functions.py`](../../nemo_rl/algorithms/reward_functions.py).
93
93
94
94
:::{important}
95
-
In the current implementation, if `stop_properly_penalty_coef` is set (not `null`), `apply_reward_shaping()` **returns early** after applying truncation scaling. That means you **cannot** apply DAPO "overlong reward shaping" in the same run unless you set `stop_properly_penalty_coef: null` and provide the DAPO overlong parameters (`overlong_buffer_length`, `overlong_buffer_penalty`, `max_response_length`).
95
+
When `stop_properly_penalty_coef` is set, truncation scaling takes precedence over the DAPO overlong formula. To use the overlong formula, set `stop_properly_penalty_coef: null` and provide `overlong_buffer_length`, `overlong_buffer_penalty`, and `max_response_length`. The optional confirmed-loop safeguard runs after either length adjustment.
0 commit comments