Repository navigation
fix(utils): TimeoutChecker budgets for the slowest step and upcoming validation - #4483
Open
linj-glitch wants to merge 7 commits into
Open
linj-glitch wants to merge 7 commits into
linj-glitch wants to merge 7 commits into
Conversation
linj-glitch
marked this pull request as draft
October 5, 2026 06:10
linj-glitch
force-pushed
the
linj/timeout-checker-slowest-step
branch
from
October 8, 2026 00:15
b3af828 to
3845728
Compare
linj-glitch
marked this pull request as ready for review
October 13, 2026 05:02
…validation Predict the next iteration with max(iteration_times) instead of the mean so a slower-than-average step cannot start right before checkpoint_must_save_by and be killed by the scheduler. check_save/would_save take an optional extra_s, and the sync GRPO loops pass one step's worth when the next step runs validation. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Lin Jia <[email protected]>
The look-ahead budgets for the slowest iteration observed so far. The inline comments claimed that a single slow iteration therefore cannot run past the deadline, which overstates it: a step slower than any seen so far can still overrun. Reword the comments in TimeoutChecker.would_save and the two sync GRPO call sites to describe the estimate as a heuristic over observed timings. Co-Authored-By: Claude Fable 5.1 <[email protected]> Signed-off-by: Lin Jia <[email protected]>
…_iterations() mark_iteration() assigned elapsed_time only when previous_iteration_time was set but appended it unconditionally, so a checker whose start_iterations() was never called raised UnboundLocalError on the first mark. Treat that first mark as the start of the first iteration instead. Not reachable from the training loops, which all call start_iterations() first, but the look-ahead now takes max(iteration_times), so the list's contents are load-bearing. Co-Authored-By: Claude Fable 5.1 <[email protected]> Signed-off-by: Lin Jia <[email protected]>
… last step next_step_validates mirrored only the periodic clause of should_run_validation, so the step before a val_at_end final step was not budgeted, and the predicate could be true on the last step, which has no successor. Move the look-ahead into _next_step_runs_validation, shared by grpo_train and grpo_train_sync, which follows should_run_validation for the next step (periodic schedule, or val_at_end when the next step is the last one by max_num_steps or by the epoch bound) and is false on the last step. Tests: parametrize test_grpo_timeout_budgets_upcoming_validation over both sync trainers and over periodic, val_start_at, val_at_end (by steps and by epochs) and no-validation schedules, assert the budgeted steps against the steps validate() really ran on, and unit-test the helper directly. Co-Authored-By: Claude Fable 5.1 <[email protected]> Signed-off-by: Lin Jia <[email protected]>
Both sync GRPO loops called timeout.start_iterations() before the optional val_at_start pass, so the first recorded iteration included the initial validation (and refit). With the look-ahead now using max(iteration_times), that outlier would set the estimate for the whole run and make the job exit several steps early. Start timing right before the training loop instead. The async GRPO loop and the other algorithms keep their ordering (follow-up). Tests: test_grpo_timeout_iterations_start_after_initial_validation checks the validate(step=0) -> start_iterations() -> mark_iteration() order for both sync trainers. Co-Authored-By: Claude Fable 5.1 <[email protected]> Signed-off-by: Lin Jia <[email protected]>
…alias Reference the helper as grpo_mod._next_step_runs_validation in its unit test instead of extending the explicit import list, which main has since grown at the same position (an adjacent-line merge conflict otherwise). The module alias is already imported for this purpose. Co-Authored-By: Claude Fable 5.1 <[email protected]> Signed-off-by: Lin Jia <[email protected]>
linj-glitch
force-pushed
the
linj/timeout-checker-slowest-step
branch
from
October 13, 2026 16:36
3845728 to
6c40f6c
Compare
Contributor
Author
|
/ok to test 6c40f6c |
Integrate current upstream main to satisfy the required CI branch freshness gate. Signed-off-by: Lin Jia <[email protected]>
Contributor
Author
|
/ok to test 9343a12 |
potatowarriors
added a commit
to potatowarriors/RL
that referenced
this pull request
Nov 25, 2026
…(decision 79) - SWE agent loop passes end to end with a scripted model Gym source: upstream 7bfccecc1 (normalize response tools for replay, NVIDIA-NeMo#3190) as a patch file under gym_patches/, applied to the submodule and the measurement checkout by tools/apply_gym_patches.sh (idempotent, 'check' mode). Plugin: alpha_vllm_model also drops the tool-result 'name' and 'provider_specific_fields' before validation (same targets as upstream NVIDIA-NeMo#4011/NVIDIA-NeMo#4483); its server venv gets nemo-gym from the package index, so a source patch would not reach it. Raising the Gym pin was rejected: every Gym containing the fixes pins vllm 0.29, and uv lock fails in a scratch copy (torchvision 0.28 vs 0.26, then transformers >=5.10.4 vs <5.9; Ray 2.58 vs 2.56.1). Verified: plugin tests 9 (2 negative controls), Gym test_openai_utils 180, R3 tallies unchanged, scripted-model loop on the installed configuration 4/4 reward 1 (student_stub7). Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_01JjdZctFTn2wkcheCmz3xKN Signed-off-by: potatowarriors <[email protected]>
This branch has not been deployed
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.
Current integration and validation (2026-10-29 UTC)
Merged upstream main
feb735f6132179d62634f515b2727952efb0dd14into this branch with a signed additive commit,9343a128fd5569e3a505129e06e6ad9547ea33b7, to satisfy the required CI freshness gate. The production patch retains exactly its original added and removed lines. An independent integration review found no new production issues.tests/:pytest unit/utils/test_timer.py unit/algorithms/test_grpo.py -k 'TimeoutChecker or timeout or next_step_runs_validation' -p no:cacheprovider -o 'addopts=-rA -q'.pre-commit run --all-files: formatting, Ruff, TOML, and recipe checks passed. Pyrefly reports 44 errors, with identical error messages, source paths, and multiplicities on pristine upstream main; there are no new diagnostics from this PR. The overall hook command therefore exits 1 for the baseline type errors.git diff --checkpassed; the commit contains current main and a DCO sign-off. Validation used the existing Python 3.13 environment and a private CPU-only Ray cluster, with module resolution verified against this PR checkout.No real Slurm timeout or functional/convergence run was performed; this refresh preserves the checkpoint look-ahead patch.
Repository CI must validate this exact head; earlier-head results do not establish that it passes. Existing reviews have been preserved.
What does this PR do ?
Makes the
checkpoint_must_save_bylook-ahead inTimeoutCheckerpredict the next step from the slowest step seen so far instead of the mean, and lets the sync GRPO loops add one more step's worth of time when the next step will also run validation (periodic schedule orval_at_end). The estimate is a heuristic over step times observed in the current process: a job may save and exit earlier than before, by roughly the gap between its slowest observed step and a typical one (plus one more step when the next step validates); it is not a hard bound on a step slower than any seen so far.Issues
None.
Usage
No new config. Every algorithm loop already constructs
TimeoutChecker(timeout=checkpointing["checkpoint_must_save_by"], fit_last_save_time=True), so the new estimate applies to any run that setscheckpointing.checkpoint_must_save_by.would_save()/check_save()gain an optionalextra_sargument (default0.0) that is only used whenfit_last_save_time=True;grpo_trainandgrpo_train_syncpass it automatically. A custom loop can do the same:Before your PR is "Ready for review"
Pre checks:
checkpoint_must_save_bybeyond the exemplar YAMLs.)Additional Information
Root cause.
checkpoint_must_save_byexists so that a job saves and exits before the scheduler's wall-clock limit. Withfit_last_save_time=True,would_save()fired whenelapsed + mean(iteration_times) >= deadline. RL step times vary widely (long-tail generation in agentic rollouts, or a step that also runs validation), so a step longer than the mean could start just before the deadline and still be running when the job was killed. That step's work was lost, and so was the checkpoint the deadline was meant to produce; users had to set the deadline much earlier than needed to stay safe.How it manifests. A job hits the Slurm time limit mid-step even though
checkpoint_must_save_bylooked like it had enough margin, and the run resumes from the previous checkpoint.Scope / changes.
nemo_rl/utils/timer.py:would_save(extra_s=0.0)/check_save(extra_s=0.0)predict the next step withmax(iteration_times) + max(0.0, extra_s)instead of the mean. With a stable step timemaxis close to the mean; with variable step times the estimate is larger. Docstring and comments describe this as a heuristic over observed timings rather than a guarantee.mark_iteration()no longer raisesUnboundLocalErrorwhenstart_iterations()was never called (the first mark then starts the first iteration); not reachable from the training loops, which all callstart_iterations()first, butiteration_timesis now load-bearing.nemo_rl/algorithms/grpo.py(_grpo_train_impl, the syncgrpo_trainpath) andnemo_rl/algorithms/grpo_sync.py(grpo_train_sync): when the next step will run validation,check_saveis called withextra_s = max(iteration_times). The look-ahead lives in a shared helper,_next_step_runs_validation, that mirrorsshould_run_validationfor steptotal_steps + 2(periodic schedule withval_period/val_start_at, orval_at_endwhen the next step is the last one bymax_num_stepsor by the epoch bound) and is false on the last step, which has no successor. A validating step costs roughly one more generation wave, and that time is not initeration_timesuntil a validating step has run in this process (for example right after a resume).timeout.start_iterations()right before the trainingwhileloop instead of before the optionalval_at_startpass, so the initial validation (and refit) is not recorded as the first, and therefore slowest, "iteration" that the max-based estimate would then use for the whole run.max-based estimate through their existingcheck_save()calls.Behaviour change. Only affects runs with
checkpoint_must_save_byset (all algorithm loops construct the checker withfit_last_save_time=True). Jobs whose step times vary may save and exit earlier than before: the early exit is bounded by the difference between the slowest observed step and a typical step, plus one step when the next step validates in the two sync GRPO loops. The estimate uses only steps observed in the current process: a step slower than every step seen so far, or the first validating step after a resume in loops other than the two sync GRPO loops, can still overrun the deadline. In loops other than the two sync GRPO loops,start_iterations()still precedesval_at_start, so an initial validation there can inflate the estimate for the rest of the run (safe direction; follow-up). Nothing changes whenfit_last_save_time=Falseor whencheckpoint_must_save_byis unset.Dependencies / stacking. None. The branch is six commits rebased onto the current
maintipf201e5b7c4be59b6030d1d185998193483c81887(fix(refit): release trainer memory before collective export (#3984)), so it is 0 commits behindmain(thepr-branch-up-to-date-checkgate fails a PR more than 10 commits behind). It does not depend on, and is not depended on by, any other open PR; #4481 (configurable NCCL collective timeout) touches different code.Commits (head
6c40f6c52562757106d8e8e64ae6424037a161eb; rebased 2026-10-13 from merge-baseb6016e67ontof201e5b7, so the SHAs differ from the pre-rebase commits3845728..9e42d4dwhile the combined diff is unchanged, see Validation).d13522f996ae8e12c06f6cd9e37a655ab5192a53fix(utils): TimeoutChecker budgets for the slowest step and upcoming validation95161f7237d2214df172f77ba452962371c0d55ddocs(utils): describe the TimeoutChecker look-ahead as a heuristic (comment-only)0f5e9918ab9de05c4bb08ba13d142ee8634e7c5afix(utils): make TimeoutChecker.mark_iteration() usable without start_iterations()b606c81e7ac8d47e34b044935d8846045e57f47dfix(grpo): budget the upcoming validation for val_at_end and skip the last stepc1e67899b12220f369dcd611e8c385e4c1c30b55fix(grpo): time TimeoutChecker iterations from the first training step6c40f6c52562757106d8e8e64ae6424037a161ebtest(grpo): reach _next_step_runs_validation through the grpo module alias (maingrew the same explicit import list; the final diff leaves the import block untouched)Self-review. A team self-review of the branch confirmed 11 findings: 7 were fixed in the last four commits above (the
val_at_end/ last-step gap in the look-ahead, theval_at_startiteration-timing order, the latentmark_iteration()crash,grpo_train_syncandval_start_attest coverage, and tying the budgeted steps to the stepsvalidate()ran on), 2 were corrections to this description (the pyrefly coverage statement and the exhaustive list of unchanged callers), and 2 need no change here: the pre-existing sleep-basedtest_fit_last_save_time_enabledpasses through the plain elapsed branch (the deterministic tests now cover the look-ahead; optional cleanup in a separate PR), and unit-test CI has not yet run on this fork PR (see Remaining gaps).Tests.
tests/unit/utils/test_timer.py:test_fit_last_save_time_uses_slowest_iteration(max fires where a mean-based check would not),test_extra_s_is_added_to_predicted_iteration(extra_sonwould_save/check_save, one-shot behaviour preserved),test_extra_s_ignored_without_fit_last_save_time,test_mark_iteration_without_start_iterations.tests/unit/algorithms/test_grpo.py::test_grpo_timeout_budgets_upcoming_validation: parametrized overgrpo_trainandgrpo_train_syncand over six schedules (periodic; periodic fromval_start_at=3;val_period=7over 6 steps so nothing validates, not even after the last step;val_at_endwith the last step set bymax_num_steps;val_at_endwith the last step set bymax_num_epochs; periodic plusval_at_end). Each case assertsextra_s == 30.0(the slowest observed step) exactly on the check before each validating step and0.0elsewhere, and thatvalidate()really ran on exactly those steps.tests/unit/algorithms/test_grpo.py::test_grpo_timeout_iterations_start_after_initial_validation: for both sync trainers,validate(step=0)(val_at_start) runs beforestart_iterations(), which precedes the firstmark_iteration().tests/unit/algorithms/test_grpo.py::test_next_step_runs_validation_for_timeout_budget: ten direct cases for the helper, including the epoch-bounded last step, a one-step-per-epoch dataloader wrapping into the final epoch,use_multiple_dataloader(onlymax_num_stepsbounds the run) and the last step itself.test_grpo_exit_on_timeout[grpo_train|async_grpo_train]cover the one-shot exit for both trainers.test_mark_iteration_without_start_iterationsraisesUnboundLocalError).Validation (2026-10-13, head
6c40f6c52562757106d8e8e64ae6424037a161eb, rebased ontomainf201e5b7).Environment: Python 3.13.14, torch 2.13.0+cu130, 1x NVIDIA L4 (23 GB), shared uv venv synced from main's
uv.lock(base +test+dev); Megatron-Core / Megatron-Bridge / TransformerEngine not installed (nomcoretests are in the selection). Native invocation: pytest fromtests/with the repo conftest starting a local Ray cluster (RAY_ENABLE_UV_RUN_RUNTIME_ENV=0), one session at a time.Rebase onto current
main(f201e5b7c4be59b6030d1d185998193483c81887):git rebase origin/mainfrom merge-baseb6016e67. Two of the six commits stopped on the same adjacent import line intests/unit/algorithms/test_grpo.py(mainadded_raise_if_length_penalty_enabled_without_nemo_gymexactly where86dde25cadded_next_step_runs_validationand9e42d4dbremoved it again); resolved by keeping both imports inb606c81eand dropping the PR's one in6c40f6c5, so the final diff does not touch the import block. The other four commits replayed unchanged (samegit patch-id). Checks after the rebase: the rebased treea333d40b49e7121683cc4c88ce63dd6f51371269is byte-identical togit merge-tree --write-tree origin/main 9e42d4dbcomputed before the rebase;git diff origin/main..HEADis content-identical to the pre-rebasegit diff b6016e67..9e42d4db(samegit patch-idc274173c, the same 5 files, +435/-17; only hunk line numbers shift);git rev-list --count HEAD..origin/mainis 0;git status --porcelainis empty. All tests above ran on the rebased head, so the earlier scratch-merge runs againstfe1d97ce(58 passed; 26 passed, 216 deselected) are superseded.🤖 Generated with Claude Code