NVIDIA-NeMo/RL #5155
ยท the nightly check that caught it is in #5074
ยท permalinks pin head 9990d4b (removed code: base fc009e6)
vllm/generation_tokens and the other vllm/* step metrics came out near 0 in on-policy runs (training waits for the full batch, and nothing generates during training). Every other single-controller setup undercounted them.grpo.py, ppo.py, grpo_sync.py) are unchanged.Background. vLLM keeps running totals (counters) such as "tokens generated since the engine started".
To get one step's number, NeMo-RL reads the counters twice and logs the difference:
snapshot_step_metrics() takes the start reading, get_step_metrics() the end reading.
The single controller
runs generation and training as two separate loops. Dotted words: hover or tap.
The old code took the start reading inside the train pump, when it handed the step's first group to training
(old _train_pump).
So anything generated before that moment was missed.
How much that was depends on two settings, not on the sampler:
| Setup | Old window caught | Old window missed |
|---|---|---|
| On-policy: full-batch wait, plus lookahead 0 or a colocated engine | about nothing โ logs ~0 | the whole step's generation |
| Full-batch wait, lookahead โฅ 1 | the next batch's generation during training | what was generated while training waited for its batch |
| Streaming (smaller first chunk) | the later chunks | the first chunk, and anything before it |
"Full-batch wait" means min_groups_for_streaming_train equals the batch size, so select() returns nothing until every group is ready
(_finalize_selection).
The fix moves the start reading to before the loops start, and keeps each end reading as the next start, so the windows touch end to end in every setup.
Where the fix lands: RL only.
single_controller.py moves the start reading and asks to keep the end reading;
vllm_generation.py implements keep_snapshot;
interfaces.py adds the keyword to the default, so SGLang, Megatron and Dynamo accept it and still return {}.
@@ single_controller.py L872-L882 (head) ยท _run_pumps if await self._rollout_restorer.restore(): self._rollout_recovery_enabled = True + # Capture the baseline before either pump can dispatch generation. + try: + await asyncio.to_thread(self._gen.snapshot_step_metrics) + except RayActorError as error: + log.warning("Skipping generation snapshot metrics: %s", error) rollout_task = asyncio.create_task(self._rollout_pump()) @@ single_controller.py L2805-L2811 (base) ยท _train_pump โ per-step start reading removed - if groups_dispatched == 0: - try: - await asyncio.to_thread(self._gen.snapshot_step_metrics) @@ single_controller.py L3353-L3358 (head) ยท _train_pump, step end - await asyncio.to_thread(self._gen.get_step_metrics) + await asyncio.to_thread( + self._gen.get_step_metrics, keep_snapshot=True + ) @@ vllm_generation.py L884-L893 (head) ยท get_step_metrics counters_end = self._get_raw_spec_counters() + # no start reading yet: this read becomes the start, report nothing + if counters_start is None: + self._step_metrics_snapshot = counters_end + return {} step_metrics = compute_spec_decode_metrics(counters_start, counters_end) ... + # this window's end is the next window's start + if keep_snapshot: + self._step_metrics_snapshot = counters_end
In order: the controller reads the counters once before either loop can start generating (the restore step above it only reloads saved state).
Each step end reads again, logs the difference, and keeps that reading as the next start.
If a read fails, the start reading is cleared
(L876-L879);
the next read only sets a new start and returns {}
(L885-L887).
So one step shows no vllm/* numbers, instead of a number that spans the gap.