Repository navigation
test(checkpoint): add Workplace prefix-recovery parity - #4507
Conversation
5bccccd to
082e927
Compare
082e927 to
1a6de5c
Compare
1a6de5c to
cc5d8bc
Compare
cc5d8bc to
deb0e14
Compare
1 similar comment
deb0e14 to
24050b2
Compare
terrykong
left a comment
There was a problem hiding this comment.
Thanks for this. It adds the token-level parity against an uninterrupted run that was asked for on #4500 (discussion) and #4266 (discussion), which is the right check for prefix recovery.
Two comments are about what the test proves:
- restored rows are excused too widely, so a changed tool result or turn-1 token passes (parity L516);
top_p=0.000001keeps rewards out of the gradient (script L194).
Size. About 1,040 of the 2,098 added lines can go without weakening a check:
| What | Source lines | Unit-test lines |
|---|---|---|
Use the built-in log_full_train_data dump instead of the recorder (hook L57) |
~125 | ~28 |
| Ordering / timeline / Kendall-tau code (parity L691) | ~215 | ~127 |
| Hand-rolled Spearman / Pearson / percentiles (parity L548) | ~125 | ~70 |
| Restored-row excusal (parity L516) | ~70 | ~115 |
| Small repeated checks, fallbacks and copied helpers (L346, L367, L285, L304), plus the report printing and script plumbing that only feed the code above | ~165 | — |
A version with the same checks is about 330 source lines plus 260 unit-test lines.
This PR also builds on #4506, whose 25 review comments (including its ~300-line size ask) are still open. Please apply #4506's size asks first, so this PR shrinks on top of a smaller base; the prefix-recovery stack is already over 20k lines.
Gym pin. This test also needs Gym 7a254e8e98 and 994cd12404 (prefix mode and the SimpleAgent _prepare_model_request_for_turn hook) on Gym main. Same ask as the open #4500 thread (discussion).
Small nit: the PR body says "unit 37 passed", but the unit file has 38 cases.
Visual explainer: https://terrykong.github.io/gh-pages-poc/terryk/pr-4507-size-and-reuse.html
Visual explainer: https://terrykong.github.io/gh-pages-poc/terryk/pr-4507-excused-rows.html
Generated by Claude Code
|
Thanks for the review. The inline items are addressed in What the test proves: exact parity for every row, with one verified exception: a restored row whose phase-1 prefix already diverged before the cut. A real run needed it; details are in the excusal thread. The script now says the test checks data parity, not learning. Size: #4507 is now +1,503 / -125 lines against #4506 (was +2,090 / -73); the parity helper is 578 lines. The extra deletions are the turn-recovery script's copies, now shared. That is still well above your ~590-line estimate. Most of the remainder is the pre-cut check, the trainer-dump loader, and the #4506: its review round landed in Gym pin: acknowledged. The stack pins Nit: the description will list the current counts (22 parity unit cases). |
|
/ok to test 8feaa87 |
terrykong
left a comment
There was a problem hiding this comment.
Second round on #4507 (stack 6/11), checked at 7f7a7a5. Thanks for fixing C1–C14 from the first round, for the count-back fix in f5b932f with its regression test, and for sharing the readers with the turn-recovery test in 7f7a7a5.
Correctness. (C16) Up to 7 of the 8 restored rows can be set aside and the test still passes, so a run can quietly check very little. Please cap it at one.
Size. The PR is +2,242/−80, all tests. 615 of those lines are the functional test that #4506 moved here unchanged (f09626d there, 8b50c4e here). About 75 lines can go without weakening what the restore check proves, which brings it to ~2,170 (C16 adds about 6 lines back):
- (C19) Build the row index once and merge the two cut checks: about −40.
- (C20) Inline the jq builder that has one caller: about −23.
- (C21) Unused snapshot-selection options and fields: about −13.
No product function can replace the rest. nemo_rl has no reader for train_data_step*.jsonl, the restore and completion lines exist only in logs, and prefix_ids_sha256 is computed inline (prefix_recovery/recovery.py L747-L761).
CI (C15 is still open). The prefix-recovery functional test has never run in CI. On 7f7a7a5, /ok to test ran but no tests did, because the PR had no CI label at the time. CI:Lfast is on now, and 7f7a7a5 moved this test into the fast lane. Please post /ok to test again and link the passing L1_Functional_Tests_SingleController_3 job with its run time. Before it joins the fast lane, please also post a pass rate from at least 15 runs (C25).
DCO. Commit 2bd7591 carries only another person's Signed-off-by line, not yours, so the DCO check fails. Please add your own sign-off.
PR description. These lines are out of date:
- "No restored prefix key is still live in any batch the trainer consumed": since 9e3ff7a they are live at the first training step and gone after the next snapshot.
- The Workplace row builder in the "shared with the turn-recovery test" list (C20).
Visual explainers: what the test proves https://terrykong.github.io/gh-pages-poc/terryk/pr-4507-what-it-tests.html, and what can shrink https://terrykong.github.io/gh-pages-poc/terryk/pr-4507-v2-what-can-shrink.html
Generated by Claude Code
0bc9d74 to
4a9c6ea
Compare
terrykong
left a comment
There was a problem hiding this comment.
C26 · 1 action item.
TL;DR — the code side of C20 is done; the PR description still says the jq row builder is shared and the test runs in the fast lane.
Follow-up to C20. Thanks for C16, C19, C21 and C25 too; those threads are closed.
Fixed: 4a9c6ea inlines the rows into grpo_async_gym_single_controller_prefix_recovery.sh and deletes _workplace_calendar_rows.jq.
Still open (PR description only):
- The "address review of generation-prefix recovery parity" row still lists "the Workplace row builder (
_workplace_calendar_rows.jq)" as shared with the turn-recovery test. That file is gone. - The "run the prefix-recovery test in fast CI" row says
run_test fast, but L1_Functional_Tests_SingleController_3.sh#L81 now runs it at full tier. - The commit table has no row for 4a9c6ea (the intro still says 14 commits; there are 15).
AI-1
Edit the PR description: drop the jq builder from the shared list, say the test runs at full tier until a CI-GPU pass rate is posted, and add a row for the new commit. Not a suggestion block: it is the PR description, not a file.
|
Updated the PR description:
|
|
/ok to test 4a9c6ea |
The end-to-end test of generation-prefix recovery, moved here from #4506 (C28): Gym's policy proxy holds a long Workplace call mid-decode, a rollout snapshot cuts it, and after a hard kill the restored call must resume from its saved prefix and train on the same rows as an uninterrupted run. Signed-off-by: Anish Mahishi <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Anish Mahishi <[email protected]>
Make the parity test exercise many restored prefixes and separate recovery faults from run-to-run sampling noise: - Workload: four Workplace prompts per step whose closing turn lists 1..N (N = 150/250/350/450) at natural length. Group lengths are far apart, so prompt-group readiness order is deterministic. One prompt expects a different duration so rewards are not constant. Runs Qwen3-1.7B for 3 steps. - Selection/verification: require a recoverable prefix in every Workplace prompt group at the crash (Gym refuses dispatches that land during a checkpoint, so siblings may start late), and verify each cut returns to its Gym owner under attempt+1, restores its exact prefix digest, and completes once with its trained generated-token count equal to the restored prefix plus the regenerated tail. - Parity: classify token divergences relative to the restored prefix. A divergence inside the prefix is excused as phase-one noise only when the trained prefix tokens hash-match what the worker restored, and excused rows still require equal rewards and sample masks; a prompt divergence always fails. Gate vLLM generation_logprobs in aggregate over token- matched rows (bit-identical fraction, Spearman, max abs diff) since they are not batch-invariant, and require exact prompt-group readiness order. Report Kendall tau for arrival and sealing order, per-rollout timelines, and logprob statistics in parity-report.json before the strict checks run. - Hook: timestamp every event and record completion arrival separately from the ledger seal. - Relies on the Gym checkpoint test agent's natural-length closing turn (NEMO_GYM_TEST_PREFIX_MIN_TOKENS=0), pinned by the base branch. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Anish Mahishi <[email protected]>
…very parity The prefix-recovery parity harness reads each restored cut from Gym's checkpoint records and reports it. NeMo Gym now names the staged prefix prefix_token_count and prefix_digest, so the harness, its report, and its unit tests use those keys. Signed-off-by: Ananth Subramaniam <[email protected]> Signed-off-by: Anish Mahishi <[email protected]>
… test The prefix-recovery snapshot helper now imports _gym_recovery_snapshot_helpers as a sibling module. Put tests/functional on sys.path before loading it by file path, as running it as a script does. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Anish Mahishi <[email protected]>
Parity data and gates: - Compare runs on the trainer's own async_rl.log_full_train_data dump (read from the run's exp_NNN directory) instead of a recorder in the hook; the hook now only probes live staging keys per train step. - Require exact parity for every row. The one exception is a restored row whose phase-1 prefix already differed from the reference before the cut (vLLM sampling is not batch-invariant): it must start with exactly the restored tokens (prefix_ids_sha256), match up to its closing call, and keep its reward and admission; at least one restored row must match outright. - Gate generation logprobs on bit-identical fraction and max |diff|. - Default to one train step and say the test checks data, not learning (top_p=1e-6 zeroes the policy gradient). Removed: the ordering/timeline/Kendall report, the hand-rolled Spearman/Pearson gate and parity-report.json, the metric comparison, the prefix+tail==total tautology, the duplicate trained-once check, the unreachable successor Gym-manifest check, the single-cut selection fallback, and the swallowed Workplace layout errors. The JSON readers and the restored-prefix log parser are shared in _gym_recovery_snapshot_helpers. The L1 runner comment now says the test performs three runs. The Workplace calendar sentinel count lives with the shared readers, and the Workplace test rows are built by one jq module (_workplace_calendar_rows.jq). Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Anish Mahishi <[email protected]>
…agent Gym main has no checkpoint test agent, so the prefix-recovery parity test now runs the stock workplace_assistant_simple_agent behind the test hook's policy proxy, as the turn-recovery test does. With no hold and no follow-up tool, the proxy sends every call after the tool result with tool_choice none and leaves its length to the model, which is what the test agent did for the closing turn. Gym only cuts a call whose decoding is unconstrained, judged from the request its agent sends, so the rows leave tool_choice auto instead of forcing calendar_create_event: a forced tool would keep every turn out of the cut. The prompt asks for the call, and the snapshot selector already requires the calendar write to have happened exactly once. The rows name workplace_assistant_simple_agent, the script drops the test agent's config_paths override and environment-server removal, and the hook writes the proxy's events to the prefix test's events file. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Anish Mahishi <[email protected]>
…y active call The snapshot records only the cuts that succeeded, so a snapshot where Gym failed or skipped an active call's cut still qualified, and that call quietly regenerated after the restore. Read the trainer's save line for the snapshot and require zero failed and skipped cuts; a bug that keeps failing cuts now times out the selection with the counts instead of passing. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Anish Mahishi <[email protected]>
…identical On Gym main's Workplace agent the workload generates ~9.3k tokens, and four runs scored 98.89-99.13% bit-identical with every exact token, mask and reward gate passing; three fell below the old 99% floor across three different progress-read implementations. The bf16 noise floor is a property of the smaller workload, not of the restore, so the gate now sits at 98%. The max-|diff| bound stays at 0.5. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Anish Mahishi <[email protected]>
…s end The prefix-recovery parity checks located a restored call at the start of its row's last unmasked segment. When top-k/top-p filtering is on, the trainer drops positions whose recomputed logprob is -inf from token_mask (#4154), and the rows these checks read are dumped after that pass, so a masked token inside the call made the check start the call too late, miscount its tokens, and fail a correct restore. A restored call closes its row, so the total_generation_tokens it logs on completion end the row. _assert_prefix_boundary now counts back from the row's end, requires the token before the call to be untrained, checks the completion's prefix + tail = total accounting, and requires the restored prefix at that position; a dropped or duplicated token moves the position. It returns where each call starts, which _rows_diverged_before_cut reuses to compare the reference row at the same position. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Anish Mahishi <[email protected]>
…logprobs Main's sampler replay (#5006) refuses top_k/top_p filtering unless vLLM returns logprobs after the filter, since the trainer now replays it. The parity test samples with top_p=1e-6 to make regenerated tails comparable token for token, so it failed at startup. Set vllm_cfg.logprobs_mode=processed_logprobs, as main's score-centering functional test does. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Anish Mahishi <[email protected]>
…snapshot #4506's third review defers a finished call's chunk-row delete to the next snapshot, so restored prefix rows are still live when phase two first trains. Phase two now trains one step past the reference, so the snapshot after the compared step runs while the run is alive, and the hook records the live staging keys right after each flush. The parity check requires the restored rows to be live at the first training step and gone after the first flush, and compares only the reference's steps. grpo.max_num_steps is excluded from the rollout fingerprint in both phases, since only phase two's stopping point changes. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Anish Mahishi <[email protected]>
…ts readers Address C28's follow-ups from the third review of generation-prefix recovery: - The recovery hook reads one events variable, SC_GYM_RECOVERY_TEST_EVENTS, which the turn and prefix scripts both set; the turn-only name and its fallback are gone. - The prefix-recovery test runs in fast CI lanes: three launches on 2 GPUs, 7-9 minutes locally. - The turn-recovery script imports ledger_episode_index, participant_records, matching_siblings and calendar_sentinel_count from _gym_recovery_snapshot_helpers instead of keeping its own copies. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Anish Mahishi <[email protected]>
…arity Under token_capture.forest_training the trainer names each row <group>_g<i>_s<segment>, and the parity check rejected them as invalid sample IDs. Accept the single segment _s0, which still compares one trained row per rollout, and fail clearly on a later segment. With #5147 applied, the prefix-recovery test passes under forest training: 8 restored episodes seal as their next attempt and all 8 trained rows match the uninterrupted run. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Anish Mahishi <[email protected]>
… parity - C16: fail when more than one restored row is set aside as diverged before its cut. Nothing checks that a set-aside row diverged rather than restored the wrong tokens, so the cap bounds what a run leaves unchecked. - C19: build the row index once in compare and pass it to every check, and merge the prefix-boundary and divergence checks into _check_cuts, which reads the recovery log once. Same checks, order and messages. Drop the step-mixing check: JsonDebugWriter writes one file per step. - C20: inline the Workplace row builder into the prefix script and delete _workplace_calendar_rows.jq; the turn-recovery test builds its own rows. The generated test data is byte-identical. - C21: drop min_cuts, the top-level longest-cut fields and the unread per-cut resources_manifest and sentinel_event from the snapshot selection. - C25: run the test at full tier, not in fast lanes. It relies on three runs making the same near-greedy choices, and local runs have failed for reasons outside recovery, so it waits for a CI-GPU pass rate. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Anish Mahishi <[email protected]>
4a9c6ea to
8ca22f0
Compare
|
/ok to test 8ca22f0 |
What does this PR do ?
Adds an end-to-end parity test for generation-prefix recovery: an uninterrupted run and a hard-killed, prefix-restored run of the same Workplace workload must train on identical data.
Stacked on #4506. The base branch is
amahishi/ckpt-v2-prefix-recovery-pr1, so this diff shows only this PR's 15 commits. It is test code only. The functional test itself moved here from #4506 (review comment C28), so #4506 changes no functional-test files.Issues
How it works
flowchart LR B[Reference run<br/>uninterrupted] --> P[Parity compare] P1[Phase 1<br/>checkpoint with active prefixes] -->|SIGKILL| P2[Phase 2<br/>restore prefixes, generate tails] P2 --> Pworkplace_assistant_simple_agent. Each episode makes a namedcalendar_create_eventcall, then closes by listing 1..N (N = 150/250/350/450) at natural length, so prompt groups finish far apart. Gym seestool_choice: autoon every turn, so both calls are cuttable; a policy-call proxy in the test hook (the one refactor(checkpoint): move rollout checkpointing out of the single controller #5011 uses for the turn test) sends every post-tool call to vLLM withtool_choice: none. One prompt expects a different duration, so rewards are not constant.top_p=1e-6makes the regenerated tail comparable token-for-token; training applies the sametop_p, so the policy-gradient term is 0. The test checks rollout and training-data parity, not learning.-inflogprobs, fix(grpo): drop top-k/top-p -inf from token_mask #4154) cannot shift where it starts. No restored prefix key is still live in any batch the trainer consumed.async_rl.log_full_train_datadump from all three runs:prefix_ids_sha256), match token-for-token up to its closing call, and keep its reward and sample mask. At most one restored row may be set aside this way, and at least one must match the reference outright;logprobs_mode: processed_logprobswithtop_p, and after atop_p=1e-6filter every sampled token's logprob is 0, so this check is now trivially 1.0; the token-level checks above carry the parity.grpo.max_num_stepsis excluded from the rollout fingerprint.Changes
test(checkpoint): add the prefix-recovery functional testtest(checkpoint): add Workplace prefix-recovery paritytest(checkpoint): strengthen Workplace prefix-recovery paritytest(checkpoint): read the renamed generation-cut keys in prefix-recovery paritytest(checkpoint): load the shared snapshot helpers in the parity unit testtests/functionalonsys.pathbefore the unit test loads the snapshot helper.test(checkpoint): address review of generation-prefix recovery paritytrain_data_step*.jsonldump; removed the ordering/correlation report, the metric comparison and redundant checks; JSON readers, the restore-log parser, and the calendar sentinel count are shared with the turn-recovery test.test(checkpoint): run prefix-recovery parity on Gym main's Workplace agenttool_choice: autoso Gym does not skip the cuts.test(checkpoint): select only prefix-recovery snapshots that cut every active calltest(checkpoint): lower the prefix-recovery logprob floor to 98% bit-identicaltest(checkpoint): find a restored call by counting back from its row's endtest(checkpoint): run the prefix-recovery parity test with processed logprobsvllm_cfg.logprobs_mode=processed_logprobs, which main's sampler replay (#5006) requires withtop_p; the test failed at startup without it.test(checkpoint): check restored prefix rows are deleted by the next snapshottest(checkpoint): run the prefix-recovery test in fast CI and share its readersL1_Functional_Tests_SingleController_3.sh(asrun_test fast; the next review round moves it to full tier); the turn and prefix scripts share oneSC_GYM_RECOVERY_TEST_EVENTSvariable, and the turn script imports its ledger and calendar readers from_gym_recovery_snapshot_helpers.test(checkpoint): read forest training's row IDs in prefix-recovery parity<group>_g<i>_s0), still one trained row per rollout, and fails clearly on a later segment.test(checkpoint): address fourth review of generation-prefix recovery parity_check_cuts), same checks and messages (C19). The Workplace row builder is inlined into the prefix script (C20; same test data). Unused snapshot-selection fields are dropped (C21). The test runs at full tier, not in fast lanes, until a CI-GPU pass rate is shown (C25).Lines vs #4506: unit tests +680, functional tests +1560 / −80.
Testing
tests/unit/environments/test_gym_prefix_recovery_parity.py34 passed.tests/functional/grpo_async_gym_single_controller_prefix_recovery.shpasses locally on this head (1 node, 470 s): 8 restored prefixes (139–156 tokens), every row matches the reference, 0 rows needed the pre-cut exception; the restored calls' 16 chunk rows were live at the first training step and 0 remained after the next flush.tests/functional/grpo_async_gym_single_controller_turn_recovery.shpasses locally on this head (260 s) with the shared readers.main(with feat(checkpoint): recover active vLLM generation prefixes #4506): the prefix test passes again (477 s): 8 restored prefixes, every row matches, 0 rows needed the pre-cut exception.++token_capture.forest_training=trueand fix(checkpoint): keep the calls a restored turn carried over under forest training #5147 applied: the prefix test passes (455 s). All 8 restored episodes seal as their next attempt, and all 8 trained rows match, one through the pre-cut exception. Without fix(checkpoint): keep the calls a restored turn carried over under forest training #5147 the restored episodes are regenerated (see fix(checkpoint): keep the calls a restored turn carried over under forest training #5147).processed_logprobs, measured the generation-logprob check for real: 99.11% bit-identical over 9,312 tokens, max |diff| 0.212 withflat_logprobs: true; 99.10%, max |diff| 0.162 without.<tool_call>instead of1as a closing turn's first token. The restored prefix hash matched phase 1's tokens. That run's data passes with the exception (1 row set aside) and fails without it.4a9c6ea4e): the prefix test passes locally (8 restored prefixes, every row matches, 0 rows set aside, no retries).run_testinL1_Functional_Tests_SingleController_3.sh, so this PR is labeledCI:L1), not in fast lanes, until a pass rate from runs on the CI GPU is posted (C25). The L1 job time will be posted once it runs.🤖 Generated with Claude Code