How batch age counts a call that runs across a refit

NVIDIA-NeMo/RL #5049 (part 3 of the rollout-checkpointing stack, on top of #5048; see also the #5048 page). Permalinks pin the reviewed head c2bf309a, and 09627ac2 (the same two commits rebased onto main) for the W&B section.

Before
The only staleness number was weight_version_lag: how many updates old the oldest group in a step was. Nothing said how old the average trained token was.
This PR
Adds batch age per step to the rollout trace. Commit 1 counts each call's tokens under the version the call began on. Commit 2 also splits a call that runs across a refit, using vLLM's live token count at the pause.
Status
New feature; the exact split is the right idea. The review keeps the trace and the split, and asks for four changes: also log batch age to W&B, do the split in the controller so the trace and W&B agree, read the token counts right before resume (which fixes call B below), and make that read safe.
Background. The trainer updates the policy once per step. Each update gets a number, the version. A refit copies the new weights into vLLM while generation is paused. With token capture, each model call is stamped with the version in use when it began (vllm_worker_async.py#L754). Batch age = for every trained token, (version the step trains) − (version that made the token), averaged over tokens. Dotted words have a short explanation: hover or tap them.

vLLM keeps a paused call alive across a refit, so its later tokens come from the new weights. Commit 1 does not see that: it sums each call under its start version (commit 1). Commit 2 asks every vLLM engine, during the pause, how many tokens each running call has made (captured_call_progress), writes that as a refit_cut event, and splits the call there offline (tokens_by_version). The figure runs both on two calls trained by a step that updates version 6.

weights v4 refit generation paused weights v5 refit_cut read call A began on v4 30 tokens 60 tokens call B began during refit stamped v4 40 tokens stamp moves to v5 only after resume Counted as (tokens @ version). Age = 6 − version. Legend: v4 = age 2 v5 = age 1 red = wrong version by start version commit 1 only exact split the PR (commits 1+2) what really happened call A 90 @ v4 30 @ v4 + 60 @ v5 30 @ v4 + 60 @ v5 call B 40 @ v4 40 @ v4 40 @ v5 batch age 260/130 = 2.00 200/130 = 1.54 160/130 = 1.23

Both methods read high, never low: a token is never made by a version older than its call's stamp. Commit 1 is exact for every call that does not span a refit. The gap here is large only because one of two calls spans the refit; in a real batch most calls span none, and the PR's 6-step GPU run reports batch age only with the split, so the real gap is unknown. Call B shows a gap in the PR's split: the token counts are read right after the pause, before call B arrives, and its version stamp only moves after resume. Reading the counts right before resume instead sees call B with 0 tokens, so all 40 count on v5 and the exact split matches what really happened (1.23). The stamp itself should not move: it also decides which groups are evicted as stale.

What the review asks — proposed, not in the PR

Where the fix lands: RL only, no vLLM change. single_controller.py (W&B metric, split at publish, read timing), trace.py (the writer keeps no state), and one vLLM-lane test.

AskWhy
Also log batch age to W&B — two sums per group (tokens, tokens × version), one division per step next to weight_version_lag. The trace is opt-in and needs an offline script, so most runs never see the number. The per-group metric path already reaches the train pump (_capture_token_metrics → per_group_rollout_metrics). Miles logs the same token-weighted number (code).
Do the split in the controller when a group publishes, with the PR's own loop, and write the exact counts into group_published. Today the split exists only offline, so W&B can't use it, and the writer's _cut_calls set (trace.py#L117) keeps call IDs of dropped groups forever.
Read the token counts right before resume, not right after the pause. vLLM registers new requests even while paused (async_llm.py#L507), so call B shows up with 0 tokens. Left over: calls added after the read and before the stamp moves, and counts that can trail by about one decode step (vLLM: "not required for correctness").
Make the read safe: catch errors, give its ray.get a timeout, and test against vLLM's real classes. It reads vLLM private fields inside the refit try, which only catches RefitAborted/RayActorError; any other error skips resume. The tests use fakes, so a rename passes CI.
proposed — single_controller.py, _train_pump, next to weight_version_lag
+tokens = sum(per_group_rollout_metrics.pop("batch_age/trained_tokens", []))
+version_sum = sum(per_group_rollout_metrics.pop("batch_age/token_version_sum", []))
+if tokens:
+    step_metrics["batch_age"] = version_during_step - version_sum / tokens

🟠 C7 — W&B C8 — split at publish C9 — read before resume, safe read C10 — real vLLM classes

So what. With these four changes the exact split gets call A and call B right, the trace keeps the per-rollout view, and every run shows the same token-weighted batch age in W&B. Counting by start version alone would read high (2.00 vs 1.23 in the figure).