Repository navigation
[rl] Take a training sample's min policy version over all its turns - #5954
Conversation
A training sample kept its opening turn's min_policy_version and widened only the max. A later turn can be older: the router moves a session off an overloaded generator (repin_load_ratio), and the new generator may not have finished the same model state dict load. The sample's age then read too low. Widen the min the same way as the max, as the verifiers generation server already does.
|
Reply from claude: @claude please review |
|
Claude finished @felipemello1's task in 1m 21s —— View job Approve -- please address the items below before merging (the human-written summary is empty): review |
There was a problem hiding this comment.
Verdict: Approve -- please address the items below before merging -- the bug is real on main, the fix is the smallest one possible (it mirrors the existing max-widening and what examples/verifiers/generation_server.py:248 already does), and it can't newly trip the max_offpolicy_steps invariant.
What this PR does. rollout_to_training_samples took a packed sample's min_policy_version from its first turn only, but TrainingSample.min_policy_version is documented as "Oldest policy version among this branch's trained turns" (training_sample_builder.py:47). A later turn can be older: PrefixAwareRouting moves an overloaded session to another generator (routing/strategies.py:202, repin_load_ratio), and generators load model state dicts independently. The PR now widens the min over every turn, the same way the max is widened.
Example.
turn 0 -> generator 0 (on v4): stamp 4
turn 1 -> repinned to generator 1 (still on v3): stamp 3
trainer at v6
main: sample min 4 -> policy_age 2 (understated)
PR: sample min 3 -> policy_age 3
Affected consumers: rollout/min_policy_version (training_sample_builder.py:242), train_batch/policy_age* and the over-target warning (controller/metrics.py:203-227). Metric keys stay the same; only the values get more accurate.
Must fix
- PR description -- the "Summary (human-written)" section is empty. The author needs to fill it in before merge (per
CONTRIBUTING.md, agents don't write it).
Details
max_offpolicy_steps safety. compute_policy_age_metrics raises RuntimeError when trainer_version - min_policy_version > max_offpolicy_steps (metrics.py:208), so making the min smaller could in principle make it fire. It can't fire because of this PR. A turn on generator 1 is stamped either with generator 1's current version (KV reset on load) or with generator 1's _group_min_policy_versions.setdefault(group_id, ...) pin (engine_loop.py:519-528). Both are >= generator 1's version when the group was admitted, because versions only increase. On main, the group's turn 0 could already have been routed to generator 1 at admission and stamped with that version, so the PR adds no new worst case.
Same-generator multi-turn (no repin): every rollout in the group shares the per-group pin, so turn k's stamp can never be below turn 0's. The fix only matters across generators, as the inline comment says.
Test. The change parametrizes the existing test, (3,4) plus the new (4,3); no new test function. (4,3) fails on main, so it guards the regression.
Overlap. #5953 (re-prefill on next turn, drop the KV reset on load) is in the same area but changes stamping, not packing. The two are independent.
A maintainer still needs to review (touches torchtitan/rl/trainer/).
tianyu-l
left a comment
There was a problem hiding this comment.
Each generator pins a group to the version it has when it first serves that group
I found this description to be less accurate
- generator's local salt is based on
group_id - but routing is based on
session_idhttps://github.com/pytorch/torchtitan/blob/main/torchtitan/rl/routing/strategies.py#L212
I think here you meant session, not group
|
Reply from claude: @tianyu-l thanks. You're right that routing is per session. The version pin is per group, though, and the bug needs both:
So B's session moves to gen 1, where group 7 was already pinned to v3 by sibling A, and B's turn 1 gets min 3. I reworded that paragraph to name both keys and added a picture of the example under the TLDR. |
Summary (human-written)
small nit to cover edge case if a sample is moved to a generator with an older policy version
Agent details
TLDR: A training sample's
min_policy_versionnow takes the oldest version over all its turns, not only itsfirst turn's. Its docstring already promised that ("Oldest policy version among this branch's trained turns",
training_sample_builder.py:47). The value feeds the policy-age metrics and theirmax_offpolicy_stepscheck, whichthis PR can't newly trip (Effect 3 below), so this is a metrics fix: 3 lines, the same widening the max already gets.
How a later turn can carry an older version
Two different keys are involved:
group_id,engine_loop.py:524-526). That pin is the turn'smin_policy_versionand its prefix-cache salt(
vllm/engine.py:359).session_id,routing/strategies.py:212),so siblings can sit on different generators. A session also moves when its generator is busy (
repin_load_ratio,routing/strategies.py:149-152).The bug needs both: a session moves to a generator where its group was pinned earlier.
B's first request reaches generator 0 after the load when its environment starts slowly (a sandbox that takes a
while to boot), or when the earlier siblings all went to generator 1.
Effect
train_batch/policy_age(mean) andtrain_batch/pct_samples_over_target_age(controller/metrics.py:203-232).max_offpolicy_stepscheck, the over-target warning androllout/min_policy_versionuse the batch max age or min version, and a sibling like A already carries min 3.max_offpolicy_steps: generator versions only grow, so no turn's pin is older than theoldest generator's version when its group was admitted. On main, turn 0 alone could already carry that pin.
examples/verifiers/generation_server.py:246-252already takes the min over turns.Test plan