Repository navigation
feat(checkpoint): trace batch age - #5049
Merged
Merged
Conversation
Batch age is the token-weighted number of policy updates between generating a token and training on it. With token capture and the rollout trace on: - the reassembler returns each finalized group's tokens by the weight version each trained call began on; - the controller writes them in a group_published event, and step_trained also records the policy version the step updated. batch_age_by_step in rollout_checkpointing/trace.py computes each step's batch age, and `python -m nemo_rl.algorithms.rollout_checkpointing.trace <file>` prints it. A call that runs across a refit counts under the version it began on, so it counts as slightly older than it is. Source: +80 / -1. Tests: +67 (2 new tests, and the 20-turn capture pipeline test checks the token counts). Docs: +12 / -1. Unit: 2111 passed (default lane), 121 passed (Gym lane). ruff and pyrefly clean. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Anish Mahishi <[email protected]>
Token capture stamps each model call with the weight version it began on, but vLLM keeps running calls across a refit, so a call's later tokens come from the new weights. Batch age counted them under the call's start version. With the rollout trace and token capture on: - each refit, while generation is paused, writes a refit_cut event: for every running captured call, how many tokens it has generated on the weights being replaced. The vLLM worker links each engine request to its captured call through a context variable set when capture begins the call, and reads the token count from vLLM's output-processor request state, which has no public API; an engine without that state, or another backend, reports nothing; - the reassembler returns each trained call's ID, start version and tokens, and group_published sums them by version but lists on their own the calls a refit paused; - tokens_by_version splits those calls at their refits, and batch_age_by_step uses the split. Nothing Gym stores or a checkpoint saves changes. Source: +196 / -41. Tests: +280 / -56 (vLLM wrapper tests and refit-split tests). Docs: +10 / -5. Unit: 2116 passed (default lane), 121 passed (Gym lane); the vLLM wrapper tests pass in vLLM 0.29's venv. ruff and pyrefly clean. On a GPU Gym run, a call a refit paused before its first token was counted under the new weights. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Anish Mahishi <[email protected]>
macandro96
force-pushed
the
amahishi/rollout-trace-batch-age
branch
from
November 6, 2026 20:20
c2bf309 to
09627ac
Compare
terrykong
reviewed
Nov 7, 2026
terrykong
left a comment
Collaborator
There was a problem hiding this comment.
Batch age is a useful number, and the per-rollout trace view is worth keeping. Splitting each call's tokens at refits is the right idea; the comments below are about getting that split into W&B and computing it correctly.
- (C7) Also log batch age to W&B, so every run shows it without turning on the trace.
- (C8) Do the split in the controller when a group publishes, so the trace and W&B agree and the trace writer keeps no state.
- (C9) Read the token counts right before resume instead of right after the pause, and make the read unable to fail the refit.
- (C10) Add a test against vLLM's real classes, since the fakes miss a rename.
Visual explainer: https://terrykong.github.io/gh-pages-poc/terryk/pr-5049-batch-age-split.html
Generated by Claude Code
…ntroller Batch age needed the opt-in trace and an offline script, and the exact split at refits happened only offline: the trace writer kept the call IDs a refit paused (forever, for groups that were dropped) and the reader joined refit_cut, weights_synced and group_published to finish it. - The controller now keeps each running captured call's refit cuts (RefitCuts) and splits a group's trained tokens by the version that made them when the group commits. group_published carries those exact counts, the writer keeps no state, and refit_cut is gone. - Each group adds two sums to its rollout metrics, and every step logs batch_age = trained version - token-weighted mean version, the same number the trace gives. - The refit read now runs whenever token capture is on, after the weight transfer and just before generation resumes, so a call that arrived during the transfer counts all its tokens on the new weights. A failed read warns and skips that refit's cuts instead of failing the refit, and the read takes the refit's timeout. - Cuts for calls too old to train are dropped at each refit, using the sampler's eviction window (now public on BaseSampler). Review comments C7, C8 and C9. Unit: 2997 passed (single-controller, experience and drift tests), Gym lane 27 passed. ruff and pyrefly clean. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Anish Mahishi <[email protected]>
…ad uses The refit read goes through vLLM internals with no public API (engine.output_processor.request_states[*].external_req_id and .detokenizer.num_output_tokens()). The existing tests use fakes, so a vLLM upgrade that renamed them would pass here and fail at a refit. This test checks vLLM's real classes. Review comment C10. vLLM lane: 3 passed against vLLM 0.29.0. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Anish Mahishi <[email protected]>
Contributor
Author
|
/ok to test 833a642 |
terrykong
approved these changes
Nov 8, 2026
macandro96
added a commit
that referenced
this pull request
Nov 10, 2026
…e's link The batch-age trace (#5049) already maps each vLLM request ID to its captured model call, through a context variable set when capture begins the call and the HTTP client's _captured_requests. Generation cuts kept a second link for the same thing: a context variable set when sampling params are built, an on_generate callback writing engine_request_id onto the capture state, and a _serving_request_ids set. Read progress by model call ID through the trace's map instead, and keep finished-request state for the requests it lists. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Anish Mahishi <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Adds batch age to the rollout trace: the token-weighted number of policy updates between generating a token and training on it, per training step.
Stacked on #5048 (the rollout event log).
How it works
group_publishedevent that sums tokens by version.step_trainedalso records the policy version the step updated.refit_cutevent.group_publishedlists those calls individually so the analysis can split them; all other calls arrive summed by version.batch_age_by_stepinrollout_checkpointing/trace.pycomputes each step's batch age;python -m nemo_rl.algorithms.rollout_checkpointing.trace <log_dir>/rollout_trace.jsonlprints it.The two commits separate the per-version count (exact except for calls that span a refit) from the exact refit split.
Notes for review
external_req_id,detokenizer.num_output_tokens(), as in vLLM 0.29). An engine without that state reports nothing, and those calls count under the version they began on. Other backends inherit a default that reports nothing.vllm_worker_async.py, the generation interface andvllm_generation.py, which feat(checkpoint): recover active vLLM generation prefixes #4506 also changes; whichever lands second needs a small rebase there.Testing
{v1: 60, v0: 30}), where counting by start version gives{v0: 90}.🤖 Generated with Claude Code