Commit 06785af
fix(generators): compute batched rollout metrics from truncated responses (#1821)
## What
In `SkyRLGymGenerator.generate_batched`, each engine response is
truncated to `max_tokens` into `truncated_responses`, and `loss_masks`
are built from those truncated lengths. The `GeneratorOutput` returns
`truncated_responses` as `response_ids`. But the rollout metrics were
computed from the **untruncated** `responses`:
```python
rollout_metrics = get_rollout_metrics(responses, rewards, env_metrics, env_classes, loss_masks)
```
So `generate/{min,max,avg,std}_num_tokens` described sequences longer
than the `response_ids` actually returned and trained, and disagreed
with the assistant-token metrics derived from the truncated `loss_masks`
passed into the same call. `generate/max_num_tokens` could exceed
`max_generate_length`, violating the invariant added in #764.
## Fix
Pass `truncated_responses` instead of `responses` — a one-token change
that matches the async multi-turn path (`generate`), which feeds
`get_rollout_metrics` the same `responses` it returns.
## Test
`tests/train/generators/test_skyrl_gym_generator.py::test_generate_batched_metrics_use_truncated_responses`
sets `max_generate_length=2` below the 4-token mock output and asserts
`generate/max_num_tokens == 2`, matching the truncated `response_ids`
and `loss_masks`. Fails on `main` (`4 == 2`), passes after the fix. All
24 tests in the file pass; black + ruff clean.
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>1 parent fc829f8 commit 06785af
2 files changed
Lines changed: 35 additions & 1 deletion
File tree
- skyrl/train/generators
- tests/train/generators
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
776 | 776 | | |
777 | 777 | | |
778 | 778 | | |
779 | | - | |
| 779 | + | |
780 | 780 | | |
781 | 781 | | |
782 | 782 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
358 | 358 | | |
359 | 359 | | |
360 | 360 | | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
361 | 395 | | |
362 | 396 | | |
363 | 397 | | |
| |||
0 commit comments