Repository navigation
fix(training): exclude prompt history from reward lengths and loss masks - #4487
Conversation
54f9339 to
af66055
Compare
DAPO overlong shaping measured only the first assistant turn, so multi-turn rollouts were never penalized for their total generation. Sum all assistant turns in apply_reward_shaping and in decompose_message_log's response_token_lengths. Single-turn behavior is unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Lin Jia <[email protected]>
Document the multi-turn semantics introduced by the previous commit: in docs/guides/dapo.md, state that the response length measured by overlong reward shaping is the total over all assistant turns in a sample, and that user, environment, and tool turns are excluded. Update the tests/unit/data_plane/README.md entry for the renamed test_decompose_message_log_sums_assistant_turns, which previously described the old first-turn-only behaviour. Co-Authored-By: Claude Fable 5.1 <[email protected]> Signed-off-by: Lin Jia <[email protected]>
…compose The test inventory header for tests/unit/data_plane/test_message_log_decompose.py still said 11 tests and omitted the two realistic multi-turn tests that were added upstream (test_decompose_realistic_multi_turn_jagged_count and test_decompose_reconstruct_roundtrip_realistic_multi_turn). The file now defines 13 tests; update the count and add one-line entries for both. Pre-existing drift, adjacent to the entry corrected in the previous commit. Co-Authored-By: Claude Fable 5.1 <[email protected]> Signed-off-by: Lin Jia <[email protected]>
af66055 to
c169600
Compare
|
/ok to test c169600 |
terrykong
left a comment
There was a problem hiding this comment.
Thanks for a clean, well-scoped fix and a thorough PR body.
- The new test runs both input paths and fails if either fix is reverted. We checked this by reverting each one.
- We re-checked the recipe audit on our own and it holds: no shipped config uses both reward shaping and multi-turn rollouts.
- Two side benefits: both input paths now give the same result for an empty first assistant turn (before: 1.0 vs 0.5), and HelpSteer3's empty assistant turn in the prompt is no longer measured in place of the generated response.
One ask, in the inline comments: count only assistant turns that have generation_logprobs, the rule the GRPO loss mask already uses. Apply it to both length paths in this PR, and to the PPO and distillation loss masks.
CI: no unit tests have run on this head. The only label is Documentation, so CI quality check (No tests run: Label CI:L*) fails. This PR changes rewards, so per the CI label table please add CI:L1, then re-run /ok to test <new head SHA>.
Visual explainer: https://terrykong.github.io/gh-pages-poc/terryk/pr-4487-overlong-all-turns.html
Generated by Claude Code
Count generated assistant turns before logprob backfilling and align sync PPO, async PPO, and distillation masks with the existing GRPO marker. Exercise both reward paths, TQ actor ordering, and real training-loop masks with prompt history and generated turns. Signed-off-by: Lin Jia <[email protected]>
|
/ok to test 5373980 |
Signed-off-by: Lin Jia <[email protected]>
|
/ok to test 1259510 |
…e first apply_reward_shaping's DAPO overlong-length branch broke on the first role=="assistant" message in message_log and used only its length -- correct for upstream's assumed single-turn layout, silently wrong for our multi-turn swe_agents/NeMo-Gym rollouts (it measured turn 1 only, ignoring every later turn, including the one that actually runs long). Hand-ported (not cherry-picked) from upstream e12d18b "fix(training): exclude prompt history from reward lengths and loss masks" (NVIDIA-NeMo/RL PR NVIDIA-NeMo#4487). A straight cherry-pick produced spurious modify/delete conflicts on ppo.py/sync_rollout_actor.py/decompose_message_log, none of which exist on this branch -- only the reward_functions.py fix applies to us. See the [CUSTOM-PORTED] comment in reward_functions.py for the full porting note and drop-this-patch-when condition. Co-Authored-By: Claude Sonnet 5 <[email protected]>
Overlong reward shaping now sums tokens across all generated assistant turns while excluding assistant turns in the original prompt history. The legacy message-log and data-plane paths use the same generation-logprob marker, and the sync rollout actor measures lengths before flattening fills missing logprobs. Sync PPO, async PPO, and distillation also use that marker for their loss masks. Regression tests cover 100 history tokens followed by 15 generated tokens, multi-turn totals, empty placeholders, actor ordering, and training-loop masks; DAPO documentation and fixtures describe the same behavior. The affected native unit files pass 185 tests, the final commit passes 20 focused cases, and all applicable pre-commit hooks pass; full training and CI remain unrun.