Skip to content

fix(grpo): clearer error when overlong_filtering finds no truncated field#2395

Open
lonexreb wants to merge 1 commit intoNVIDIA-NeMo:mainfrom
lonexreb:fix/2163-overlong-filtering-gym
Open

fix(grpo): clearer error when overlong_filtering finds no truncated field#2395
lonexreb wants to merge 1 commit intoNVIDIA-NeMo:mainfrom
lonexreb:fix/2163-overlong-filtering-gym

Conversation

@lonexreb
Copy link
Copy Markdown

@lonexreb lonexreb commented May 4, 2026

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

  • Future backends that forget the field hit the loud error instead of
    a stack trace deep in batch handling.
  • The error names the offending config option, the missing field, and
    the file containing reference implementations — actionable in one
    read.
  • Adds zero overhead on the success path (a single `in` check before
    the existing access).

Test plan

  • `ruff check` — clean
  • `ruff format` — clean
  • `python3 -m py_compile` — clean
  • CI `L0`

Refs: #2163

…`` 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]>
@lonexreb lonexreb requested a review from a team as a code owner May 4, 2026 14:24
@copy-pr-bot
Copy link
Copy Markdown

copy-pr-bot Bot commented May 4, 2026

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.

@svcnvidia-nemo-ci svcnvidia-nemo-ci added the waiting-on-maintainers Waiting on maintainers to respond label May 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-request waiting-on-maintainers Waiting on maintainers to respond

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants