AsyncGRPO: one stale-dropped group pins the saved resume position for the rest of the run
Reproduction
On main 06779f4d, AsyncGRPOTrainer._save_checkpoint takes the resume position from the smallest group id that is not present in _trained_groups:
# experimental/async_grpo/async_grpo_trainer.py L#1803-1805
trained = self._trained_groups
first_untrained = next(g for g in itertools.count() if g not in trained)
prompt_index = self.rollout_worker._loop_kwargs["dataset_start_index"] + first_untrained
However, when the staleness check in RolloutQueueDataset.__iter__ L#363 drops a group, that group will not reach the data collator, so its group id will never be added to self._trained_groups. The first_untrained variable stops at that group id and every rollouts that were used for trainer will be generated and trained all over again if we resume training from that rollout state.
Reproduction (no GPU and no vLLM, took about 12 seconds): https://gist.github.com/cm8908/8038d9aaff636a61574242952a940868
It runs the _generate_loop, _score_loop, RolloutQueueDataset.__iter__, _save_checkpoint and the resume branch of _inner_training_loop, with one slow group out of 150 and the default max_staleness=4. Only _generate_one and _score_group are stubbed, since those need a vLLM server.
group 2 reached trainer : True
group 2 in _trained_groups : False
samples dropped stale : 2
groups trained : 150 (highest id 152)
saved prompt_index : 2
Group 2 came out of the queue, so it had finished generating and wasn't still in flight.
The second test feeds that checkpoint back through the resume branch and runs the loop again:
resumed at row : 2
rows trained TWICE : 147 (out of 150)
rows new in run 2 : 3 -> [2, 150, 153]
_groups_before_resume : 2 (run 1 actually trained 150)
Expected behavior
A checkpoint written after 150 groups should resume near 150, not at the group 2 where the staleness check dropped.
Proposed fix
Track the group ids the queue drops, and skip past them too:
resolved = self._trained_groups | self._dropped_groups
first_untrained = next(g for g in itertools.count() if g not in resolved)
Groups that are still generating stay out of resolved, so they keep holding the cursor back as they do now. AsyncDistillationTrainer._save_checkpoint has the same code over _trained_prompts.
System info
- Platform: Linux-6.8.0-100-generic-x86_64-with-glibc2.39
- Python version: 3.14.2
- TRL version: 1.13.0 (source checkout at 06779f4d)
- PyTorch version: 2.13.0
- Transformers version: 5.17.0
- Accelerate version: 1.15.0
- Datasets version: 5.0.1
- PEFT version: 0.20.0
- vLLM version: 0.28.0
Checklist
- [x] I have checked that my issue isn't already filed (see open issues)
- [x] I have included my system information
- [x] Any code provided is minimal, complete, and reproducible
- [x] Any code provided is properly formatted in code blocks
- [x] Any traceback provided is complete (nothing is raised, the checkpoint just holds a wrong value)
I checked this against current main (ed2a2497): AsyncGRPOTrainer now already tracks self._dropped_groups and computes consumed = self._trained_groups | self._dropped_groups in _save_checkpoint and _EpochStopCallback, so worker-dropped zero-variance groups no longer pin the cursor.
However, RolloutQueueDataset.__iter__ still drops stale samples (staleness > self.max_staleness) without adding sample.group_id to self.dropped_groups, and AsyncDistillationTrainer doesn't yet have _dropped_prompts parity. Before I open a PR, wanted to check the intended design: test_save_checkpoint_skips_holes_left_by_stale_drops currently expects stale holes to keep the cursor back so those prompts get re-generated on resume, whereas #7274 argues one early stale drop shouldn't pin prompt_index and re-train hundreds of later groups.
If you'd like stale-dropped groups/prompts recorded in _dropped_groups / _dropped_prompts (while still holding the cursor at unresolved in-flight gaps), could you assign #7274 to me? I have a minimal patch (1 line in async_grpo_trainer.py + _dropped_prompts parity in async_distillation_trainer.py + CPU unit tests) tested locally.