fix(grpo): clearer error when overlong_filtering finds no truncated field#2395
Open
lonexreb wants to merge 1 commit intoNVIDIA-NeMo:mainfrom
Open
fix(grpo): clearer error when overlong_filtering finds no truncated field#2395lonexreb wants to merge 1 commit intoNVIDIA-NeMo:mainfrom
truncated field#2395lonexreb wants to merge 1 commit intoNVIDIA-NeMo:mainfrom
Conversation
…`` field (NVIDIA-NeMo#2163) When ``grpo.overlong_filtering`` is enabled but the rollout batch doesn't carry a per-sample ``truncated`` field, the train loop hit KeyError: 'truncated' deep inside ``grpo_train`` with no hint about what went wrong. The NeMo-Gym rollout path now populates ``truncated`` on main (via ``run_async_nemo_gym_rollout`` in ``nemo_rl/experience/rollouts.py``, mirroring the multi-turn rollout path), so the original repro from issue NVIDIA-NeMo#2163 already resolves on HEAD. The defensive guard added here locks in the contract for future backends — any new rollout implementation that forgets to populate ``truncated`` will hit a loud ``RuntimeError`` naming the missing field, the offending option, and pointing at the existing examples in ``rollouts.py``. Refs: NVIDIA-NeMo#2163 Signed-off-by: lonexreb <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Defensive coding follow-up to issue #2163.
The original repro:
```
File "nemo_rl/algorithms/grpo.py", line 1280, in grpo_train
truncated = repeated_batch["truncated"]
KeyError: 'truncated'
```
was filed against `v0.5.0`. Since then `run_async_nemo_gym_rollout`
in `nemo_rl/experience/rollouts.py` populates `truncated` on the
final batch (mirroring `hit_max_tokens`, parity with the multi-turn
rollout path), so the original `KeyError` no longer reproduces on
`main`. No behaviour change for existing users.
This PR locks in the contract for future rollout backends: when
`grpo.overlong_filtering=true` but the batch lacks a `truncated`
key, raise a clear `RuntimeError` instead of letting it fail
opaquely deep inside the train loop:
```
RuntimeError: grpo.overlong_filtering=true requires the rollout
backend to populate a per-sample `truncated` field on the rollout
batch, but the current batch is missing it. Either disable
overlong_filtering or update the rollout backend to set `truncated`
(see `nemo_rl/experience/rollouts.py` for examples). Refs issue #2163.
```
Why this matters
a stack trace deep in batch handling.
the file containing reference implementations — actionable in one
read.
the existing access).
Test plan
Refs: #2163