Why the single controller logged zero vLLM tokens per step, and how back-to-back windows fix it

NVIDIA-NeMo/RL #5155 ยท the nightly check that caught it is in #5074 ยท permalinks pin head 9990d4b (removed code: base fc009e6)

Before
On the single-controller path, 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.
This PR
Takes one starting reading before any generation, then uses each step's end reading as the next step's start.
Status
Fixed by this PR. The older training loops (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:

SetupOld window caughtOld window missed
On-policy: full-batch wait, plus lookahead 0 or a colocated engineabout nothing โ†’ logs ~0the whole step's generation
Full-batch wait, lookahead โ‰ฅ 1the next batch's generation during trainingwhat was generated while training waited for its batch
Streaming (smaller first chunk)the later chunksthe 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.

Two steps, two ways of drawing the window

On-policy run (full-batch wait, lookahead 0). Counter = total tokens vLLM has generated. Batch 1 makes 300, batch 2 makes 500. loops start 0 300 800 Before 2 start readings generate batch 1 train step 1 generate batch 2 train step 2 300โ†’300 = 0 800โ†’800 = 0 start read: old _train_pump L2805 After 1 start reading generate batch 1 train step 1 generate batch 2 train step 2 0โ†’300 = 300 300โ†’800 = 500 start read: _run_pumps L875 end read keeps its value: L3355 start reading end reading (step end) window sees the tokens window misses them generation training Before: 0 + 0 = 0 logged out of 800. After: 300 + 500 = 800, the run total.

The fix โ€” RL only, three source files

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.

Single-controller runs now log real per-step vLLM token, length and request counts, and summing them across steps gives the run total. The windows run back to back from one step end to the next, so with async rollouts a step's numbers include generation for batches trained later โ€” the same as before this PR, but without the gap. The review found no problems. The new tests pass locally and fail if any line of the fix is reverted.