Repository navigation
refactor(eval): move the recovery planner out of orchestration - #5596
AdamRajfer wants to merge 26 commits into
Conversation
…m/eval/recovery Pure renames, so history follows the files: the planner (orchestration/recovery.py) becomes eval/recovery/planner.py, the evidence collector (orchestration/collect_evidence.py) becomes eval/recovery/evidence.py, and the 27 test modules that test only these two move to tests/unit_tests/eval/recovery/. The next commit updates the imports; this one alone does not import. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Adam Rajfer <[email protected]>
No behaviour change. This commit touches only imports, one constants module, two moved-path entries and the layer contract. - The planner reads nine chain-marker strings that the chain scripts write. They move unchanged from orchestration/executors/resume_script.py to eval/recovery/markers.py. resume_script imports them from there, so the planner no longer imports orchestration at all. - import-linter: the eval layer is split into its children, and the recovery package is a layer of its own below orchestration. The executors keep calling the planner, and the contract now forbids the planner from importing orchestration. - The old paths nemo_gym.orchestration.recovery and .collect_evidence are recorded in nemo_gym/_moved_paths.py, since 0.8.0 like the other moves there, and in the import-surface fixture. They are the same module objects and warn on use. - Two scripts run inside a run's pinned install: the remote Store reader and the follow-up's continuation admission. That install may predate the move, so they import the new path and fall back to the old one. - Every other import of the two modules, in code, tests and the skills, uses the new path. Signed-off-by: Adam Rajfer <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually. Contributors can view more details about this message here. |
…answers No behaviour change. Every top-level definition moves unchanged, with the comment lines above it and in its original order, from the 5,800-line planner into the module that answers its question: - evidence: the collected-evidence model and the Store selection, beside the collector script; - decision: identity states, run-level actions, the decision and outcome records; - budgets: retry, attempt and walltime budgets; - policy: the recovery outcome policy and the failure kind it selects on; - grading: saved grading artifacts and the re-verification cause; - rows: per-identity classification; - trials: trial observations and fault classes; - gate: health, metric coverage, MLflow delivery and the gate summary; - planner: decide_from_collected; - continuation: the chain's continuation admission and allocation accounting. The modules import in that order and no module imports a later one. The package docstring names the entry points. Callers import each name from the module that defines it. The old path nemo_gym.orchestration.recovery keeps serving every name it had: the moved-path registry lists each split name under it, and the planner's __getattr__ serves them with a deprecation warning. The scripts that run inside a run's pinned install now import the module that holds their function (evidence for the Store reader, continuation for the admission), still falling back to the old path on an older install. Tests that patch a function now patch the module whose code calls it; no assertion changes. Signed-off-by: Adam Rajfer <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
No behaviour change. The recovery planner had defined values a second time that already had a home elsewhere: - the failure-row keys (_ng_failure_class, _ng_failure_terminal, _ng_failure_counts_as_zero, _ng_failure_max_attempts) now all live in artifacts/rollout_rows.py, beside the failure class key that was already there. rollout_collection imports them from there. The planner's short names bind to them. - _ng_failure_events and _ng_failure_id come from FailureReportRow, which owns the failure report keys. - _ng_task_index and _ng_rollout_index come from config/global_config. - the chain's accounting file names (.gym_infra_retries, .gym_infra_retry_extension and .gym_accumulated_walltime) live in eval/recovery/markers.py, which the chain scripts and the recovery reader both import. They keep resume_script's existing names. The job script's walltime file is now rendered from the constant: the rendered prologue and epilogue are byte-identical. The planner's three duplicate names stay importable from the old module path through the moved-path registry. Signed-off-by: Adam Rajfer <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
…althy run Five fixtures were full copies of a recorded healthy run that differ from it only in the values their case changes: the reward, the grading binding, and the ids and digests that follow from them. Each is now a patch file that names its base and lists the values it sets, one per line (2,220 lines down to 142). `recorded_run` rebuilds the run. A patched run equals the file it replaces exactly; this was checked for each one before the files were removed. The repeats and verifier-error runs differ from the base in whole subtrees, so they stay full files. The detect-secrets baseline moves the entries of the removed files to their patch files. Its other entries are unchanged. Signed-off-by: Adam Rajfer <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
…urm package Pure renames, so history follows: executors/slurm.py becomes executors/slurm/executor.py and executors/judge_profile.py moves beside it. The next commit splits the executor by part and keeps the import path nemo_gym.orchestration.executors.slurm; this one alone does not import. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Adam Rajfer <[email protected]>
No behaviour change. The 2,945-line executor becomes the executors/slurm package, keeping its import path nemo_gym.orchestration.executors.slurm (the package exports SlurmExecutor): - executor.py: SlurmExecutor itself, which renders a run's job scripts, submits them with sbatch and records the submission (run, stage, dry run, export); - chain.py: recovery of a run's auto-resume chain (recovery_evidence, resubmit, walltime_plan and the journaled extension, raise, repin and operator-continuation steps), as the ChainRecovery mixin; - judge_job.py: judge-only jobs (reverify_judge_failures) as the JudgeJobs mixin, with judge_profile.py beside it; - reader.py: the remote Store reader; - scheduler.py: the Slurm commands these parts share (sbatch and its reply, partition limits, live checks). Every definition and method keeps its text, comments and order. The moved methods form the two mixins, and SlurmExecutor inherits them, so no method body changes. No scheduler-agnostic interface is added: only Slurm implements resubmit today. The executor capabilities give resubmit its seam when a second scheduler needs one. Names the old one-file module exported stay importable from the package through the moved-path registry, and executors.judge_profile is recorded as moved. Tests that patched a name on the old module now patch it on each package module that uses it; no assertion changes. Signed-off-by: Adam Rajfer <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
No behaviour change. chain.py and judge_profile.py each defined the same HH:MM:SS formatter; scheduler.py, which holds the Slurm formats the executor parts share, now defines it once. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Adam Rajfer <[email protected]>
…queued No behaviour change. reverify_judge_failures and _queue_judge_job each defined the same closure that stops the decision with a reason; a module-level _stopped(decision, reason) replaces both, called with the decision each closure read. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Adam Rajfer <[email protected]>
Brings in the recovery accounting fix (#5594) and the managed-environment locks (#4837). Resolutions: - The planner split is regenerated from the merged planner with the same mechanical split. The only change to the split modules is #5594's: RecoveryDecision.accounting_unknown, set on the two unknown-accounting stops, and the operator continuation keying on it instead of on the reason text. - import-linter layers: main's new orchestration layer entry (the two locked-environment CLI modules) keeps its place, and the recovery layer stays below it. - The test #5594 added imports OperatorBudget from its new module. - The old module path keeps serving the two unknown-accounting reasons, which the planner no longer imports. Signed-off-by: Adam Rajfer <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
Brings in the Store-backed run records and run-folder shards (#5443). #5443 does not touch the recovery planner, so the planner split is unchanged. Its edits to executors/judge_profile.py are carried into executors/slurm/judge_profile.py, where that module now lives. Its rollout_collection changes are untouched. Signed-off-by: Adam Rajfer <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
/ok to test 5b7def1 |
Brings in the unit test tree that mirrors the nemo_gym packages (#5589), with the rest of main. Resolutions, following the layout #5589 adds to AGENTS.md (a test sits with the package of the module it is named for): - The 24 recovery test modules that #5589 placed in tests/unit_tests/orchestration/ go to tests/unit_tests/eval/recovery/, beside the package they now test. The export receipt, grading result binding and saved-judge rejudge tests stay where #5589 put them (artifacts/, trajectory/, eval/): each is named for a module outside the recovery package. They keep this branch's imports. - Test-to-test imports follow both moves, and the moved tests keep #5589's path changes. - The five recorded-run fixtures this branch keeps as patches are removed from tests/unit_tests/orchestration/fixtures/, where #5589 moved them, and their patches move there, beside their healthy base and the loader that reads them. The secrets baseline follows: main's entries, without the five full fixtures, with the patch files at their new paths. - No moved test has an entry in the core shard durations. Signed-off-by: Adam Rajfer <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
main changed two files this branch moves (#5601). Its hunks are carried to their new homes: - the failed-judge-job progress rule (_judge_job_unsettled) to nemo_gym/eval/recovery/decision.py - the failed judge job note (judge_job_note) to nemo_gym/eval/recovery/gate.py - the host-collected unresolved_rejudgments field to nemo_gym/orchestration/executors/slurm/reader.py Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Adam Rajfer <[email protected]>
|
/ok to test b90c25c |
| def installed_commit(self) -> str | None: | ||
| """The Gym commit this launcher runs; the same value the judge-only job and a repin are checked against.""" | ||
| return installed_gym_commit() |
There was a problem hiding this comment.
You're right, the wrapper only forwards to installed_gym_commit(). I'll drop it and call the function where the judge-only job and the repin check need it.
| def export_tracking( | ||
| self, record: SubmissionRecord, benchmark: str, evidence: CollectedEvidence | None | ||
| ) -> dict[str, Any]: | ||
| """Send a complete run without an MLflow export receipt to MLflow with Gym's post-run export, and report | ||
| what happened: ``state`` (``succeeded``, ``skipped``, ``failed`` or ``unsupported``), ``run_id`` and ``error``. | ||
| """ | ||
| return { | ||
| "exporter": "mlflow", | ||
| "state": "unsupported", | ||
| "error": f"{type(self).__name__} cannot export a saved run; run `gym eval export mlflow " | ||
| "+rollouts_jsonl_fpath=<job dir>/artifacts/rollouts.jsonl` with the run's MLflow settings", | ||
| } |
There was a problem hiding this comment.
Why is it ML-flow specific? Seems like it (possibly) patches some corner case for when live-exporter failed to leave a receipt?
There was a problem hiding this comment.
Fair point, it's a shortcut from the recovery PR. The one case it covers is a complete run whose driver died before the live exporter wrote its receipt, and the gate only knows about the MLflow receipt. I'll generalize it: exporters taken from the run's saved config, one receipt check per exporter, no "mlflow" in the names.
| def export_tracking( | ||
| self, record: SubmissionRecord, benchmark: str, evidence: CollectedEvidence | None | ||
| ) -> dict[str, Any]: | ||
| """Run `gym eval export mlflow` on the run's saved artifacts from the login host, and report its result. | ||
|
|
||
| The export runs where the remote Store reader runs, with the run's saved pinned Gym install (and its MLflow | ||
| extra) in a temporary checkout: it only reads the saved artifacts and talks to the tracking server, so it needs | ||
| no allocation. It takes the benchmark's saved `mlflow_*` and `upload_rollouts` run settings, and its | ||
| credentials as the driver did: the submission's forwarded environment and the driver's env. Gym's export takes | ||
| the run lock, prepares the health metrics and writes the receipt bound to the artifact digests, and skips a run | ||
| that already has one. The resubmit lock is held and no job of the chain may be live meanwhile. | ||
| """ |
There was a problem hiding this comment.
Let me re-iterate from the base.py - this should be executor agnostic. In general we have a mechanism to keep track fo what is exported, what failed exporting etc. Seems like a parallel path that we should remove alltogether. We should also not scrape stdout.. If some output from gym eval export is needed, let's design it together either via JSON-formatted stdout, return code or something different
There was a problem hiding this comment.
Agreed on both. One post-run export path, driven by the exporter tracking we already have, and gym eval export returning a JSON result plus an exit code instead of us parsing its stdout. I'll write up a proposal for the output shape and we design it together before I change it.
| """The Gym commit this launcher runs; the same value the judge-only job and a repin are checked against.""" | ||
| return installed_gym_commit() | ||
|
|
||
| def gym_pin(self, record: SubmissionRecord) -> str | None: |
There was a problem hiding this comment.
This should be abstracted away to a method that calls _saved_config() <- executor-specific or possible get_file() <- executor-specific and does the extraction in the same way. Method signature TBD
There was a problem hiding this comment.
Furthermore, with landed-to-be job management PR, we have each capability expressed as a capability mixin (compare: https://github.com/NVIDIA-NeMo/Gym/pull/5295/changes#diff-770394fdd167afaa6a369aef99657627f8138f6056787752154a4a0750e5532f). This is FYI on how this might change.
There was a problem hiding this comment.
Yes. One method in the base that reads the saved config and does the extraction, with only the file read executor-specific. I'll shape it so it fits the capability mixins from #5295, thanks for the pointer.
There was a problem hiding this comment.
It isn't, by design, only by history: it was cut out of the Slurm executor, so the sbatch submission and the planning ended up in one file. The admission and journal logic already lives in eval.recovery and has nothing Slurm in it. I'll move the planning there and leave only the submission in the slurm package.
| job = record.benchmark_job(benchmark) | ||
| job_dir = Path(job.job_dir) | ||
| with get_connection(record.hostname) as conn: | ||
| config = self._saved_config(conn, Path(record.run_dir)) |
There was a problem hiding this comment.
there are multiple hidden dependencies here. JudgeJobs was only extracted from previous executor class state but it still assumes access to the executor methods
There was a problem hiding this comment.
True. It still reaches into the executor (recovery_evidence, _saved_config, _queue_judge_job) as if it were part of it. I'll give it those as explicit collaborators, a small protocol for reading the saved config, collecting evidence and submitting, so the dependencies are visible and the thing is testable on its own.
…tion outside the CLI entrypoint Signed-off-by: Tomasz Grzegorzek <[email protected]>
… and the test message Signed-off-by: Tomasz Grzegorzek <[email protected]>
…ration imports Signed-off-by: Tomasz Grzegorzek <[email protected]>
…asses and can only shrink Signed-off-by: Tomasz Grzegorzek <[email protected]>
…utils/gym_commit Signed-off-by: Tomasz Grzegorzek <[email protected]>
… H2 ping sidecar out of orchestration Signed-off-by: Tomasz Grzegorzek <[email protected]>
…importing orchestration Signed-off-by: Tomasz Grzegorzek <[email protected]>
…al/recovery/markers Signed-off-by: Tomasz Grzegorzek <[email protected]>
… slurm executor package Signed-off-by: Tomasz Grzegorzek <[email protected]>
…or directly Signed-off-by: Tomasz Grzegorzek <[email protected]>
Brings in tgrzegorzek/orchestration-boundary-moves (the boundary test and the moves of the supervisor, server_venv, sidecar, installed_gym_commit, eval status lookup and the failure kind writer), which includes current main. Conflict resolution: - main's changes to orchestration/recovery.py and collect_evidence.py are ported into the eval/recovery modules, symbol by symbol (28 changed, 9 added, 2 removed). - eval/recovery/markers.py keeps the chain markers and gains DRIVER_FAILURE_ENV and record_failure_kind; eval/recovery/__init__.py keeps the longer docstring. - the slurm executor modules import installed_gym_commit from utils.gym_commit. - the server tests that imported nemo_gym.orchestration.recovery import from the modules that define the names, so KNOWN_VIOLATIONS in the boundary test is empty. Signed-off-by: Tomasz Grzegorzek <[email protected]>
…yout main's new recovery tests patch and call names that now live in gate and evidence, and the old-path tables in _moved_paths.py and the import-surface fixture still listed names main moved or removed (installed_gym_commit, GRADING_WITHOUT_VERDICT, fault_class). Signed-off-by: Tomasz Grzegorzek <[email protected]>
…/recovery/markers This belongs in the recovery relocation (#5596), which creates eval/recovery and owns its contract. The cli/utils.py -> resume_script import returns to KNOWN_VIOLATIONS until then. When this branch is merged into #5596, those two commits must be re-applied there. Signed-off-by: Tomasz Grzegorzek <[email protected]>
…/recovery/markers This belongs in the recovery relocation (#5596), which creates eval/recovery and owns its contract. The cli/utils.py -> resume_script import returns to KNOWN_VIOLATIONS until then. When this branch is merged into #5596, those two commits must be re-applied there. Signed-off-by: Tomasz Grzegorzek <[email protected]>
e85aae2 to
e4867f1
Compare
…NeMo#5882) * refactor(utils): move installed_gym_commit out of orchestration into utils/gym_commit Signed-off-by: Tomasz Grzegorzek <[email protected]> * refactor(server_runtime): move the server supervisor, server venv and H2 ping sidecar out of orchestration Signed-off-by: Tomasz Grzegorzek <[email protected]> * refactor(cli): let gym eval status take its job-ID lookup instead of importing orchestration Signed-off-by: Tomasz Grzegorzek <[email protected]> * refactor(eval): move record_failure_kind and DRIVER_FAILURE_ENV to eval/recovery/markers Signed-off-by: Tomasz Grzegorzek <[email protected]> * Merge the updated boundary test branch (with main) into the orchestration moves Conflicts: cli/env.py, environment/in_process.py, server_runtime/__init__.py and test_in_process.py keep both main's new code and the moved server_runtime imports. agentic_if_realworld takes installed_gym_commit from nemo_gym.utils (now exported there), and KNOWN_VIOLATIONS lists only the 11 recovery importers that the recovery relocation removes. Signed-off-by: Tomasz Grzegorzek <[email protected]> * test(environment): import DRIVER_FAILURE_ENV from eval/recovery/markers in the new chain-guard test Signed-off-by: Tomasz Grzegorzek <[email protected]> * fix(compat): keep installed_gym_commit importable from nemo_gym.orchestration.jobs It shipped in v0.7.0 under that path, so the old import now resolves to nemo_gym.utils.gym_commit with a deprecation warning, and the import-surface fixture lists the name again. Signed-off-by: Tomasz Grzegorzek <[email protected]> * fix(compat): key the sidecar key-name entry under the released module path A caller of the released nemo_gym.h2_ping_sidecar.config now gets one warning that names nemo_gym.config.global_config, and scripts/migrate_imports.py rewrites to it. Signed-off-by: Tomasz Grzegorzek <[email protected]> * refactor(cli): make eval_status's job_artifact_dirs a required keyword cli/main.py is the only caller; a default would let a new caller silently lose the Gym job ID lookup. Signed-off-by: Tomasz Grzegorzek <[email protected]> * docs: redirect the old orchestration library pages of the moved modules The server supervisor, server venv and sidecar pages published from main under nemo_gym/orchestration now redirect to their server_runtime pages (plain and :version), and the section comment names server_runtime. Signed-off-by: Tomasz Grzegorzek <[email protected]> * Revert the move of record_failure_kind and DRIVER_FAILURE_ENV to eval/recovery/markers This belongs in the recovery relocation (NVIDIA-NeMo#5596), which creates eval/recovery and owns its contract. The cli/utils.py -> resume_script import returns to KNOWN_VIOLATIONS until then. When this branch is merged into NVIDIA-NeMo#5596, those two commits must be re-applied there. Signed-off-by: Tomasz Grzegorzek <[email protected]> * refactor(server_runtime): put the server startup code in server_runtime/supervisor/ The server supervisor, server venv, HTTP/2 ping sidecar (with its Go sources) and the two scripts the venv runs (_locked_env, _prepare_worker, moved from cli/) become one subpackage, so server_venv finds _locked_env.py beside itself and nothing runs it by a path into cli/. - The subpackage has its own public API (get_venv_path, run_command, setup_env_command, sync_environment); nemo_gym.server_runtime exports none of them and its docstring is back to what runs inside a server. - The layering contract puts server_runtime.supervisor above the rest of server_runtime, so nothing that runs inside a server can import it, and drops _locked_env/_prepare_worker from the orchestration layer. - Old nemo_gym.cli._locked_env and _prepare_worker paths get MOVED_MODULES entries; the docs redirects, the tests (now under tests/unit_tests/server_runtime/supervisor/) and the CI durations keys follow. Signed-off-by: Tomasz Grzegorzek <[email protected]> * test(telemetry): the active-servers gauge writer is now server_supervisor.py The supervisor module is server_runtime/supervisor/server_supervisor.py; the test, which the telemetry extra gates, still expected supervisor.py. Signed-off-by: Tomasz Grzegorzek <[email protected]> --------- Signed-off-by: Tomasz Grzegorzek <[email protected]>
Why
#5343 put the evaluation recovery policy inside
nemo_gym/orchestration. That policy covers what a run's saved evidence means, whether a run may be queued again, the budgets and the acceptance gate. Review of #5343 pointed out that much of it does not belong there: orchestration should submit, run and observe jobs. This PR moves the policy tonemo_gym/eval/recovery/, gives it a structure a reader can follow, and removes what is duplicated, all without changing behaviour. The commit groups can be reviewed in order.1. Relocation (done)
nemo_gym/orchestration/recovery.pynemo_gym/eval/recovery/planner.py(then split, see 2)nemo_gym/orchestration/collect_evidence.pynemo_gym/eval/recovery/evidence.pyorchestration/executors/resume_script.pynemo_gym/eval/recovery/markers.pytests/unit_tests/eval/recovery/nemo_gym.evalsits abovenemo_gym.orchestration, and the executors call the planner. So theevallayer is split into its children, andnemo_gym.eval.recoverybecomes a layer of its own below orchestration. The contract now forbids the recovery package from importing orchestration, with no new ignore entry.nemo_gym/_moved_paths.pyand in the import-surface fixture, like the package's other moves. They resolve to the same objects and warn on use.2. Structure and duplication (done)
The 5,800-line planner is split by the question each part answers. Every definition moves unchanged, with its comments and in its original order:
evidencedecisionbudgetspolicygradingrowstrialsgateplannerdecide_from_collected: evidence to one decisioncontinuationmarkersmain.NEMO_GYM_SUBMIT_NO_REF_CHECKis the documented escape from the remote ref check: the error message offers it, and tests use it.3. The Slurm executor (done)
The 2,945-line
executors/slurm.pybecomes theexecutors/slurm/package. Its import path does not change, and the package exportsSlurmExecutor.executor.pySlurmExecutor: render a run's job scripts, submit them with sbatch, record the submissionchain.pyrecovery_evidence,resubmit,walltime_plan, and the journaled extension, raise, repin and operator-continuation steps (ChainRecovery)judge_job.pyJudgeJobs)judge_profile.pyexecutors/)reader.pyscheduler.pyChainRecoveryandJudgeJobsmixins, andSlurmExecutorinherits them, so no method body changes.Resubmittablecapability when a second scheduler needs it.Size against
mainbefore #5343nemo_gym/orchestration/slurm/package, which keeps its chain recovery), submit 657, jobs 107, server supervisor 71, api 30nemo_gym/eval/recovery/Net change of each group:
Validation
mainit is based on (19,502 passed). Both sides collect the same 19,533 test ids, counting each moved test file as the same file.gym eval resubmit --recover --inspectran on four finished evaluation runs (one complete run, three stopped at a typed stop: a walltime-budget stop and two infra-retry-budget stops), each with and without gate score flags. It ran at each group head and atmain. Only two fields differ: the installed launcher commit and a per-call reader token. Every decision, count, gate verdict and exit code is identical:gym eval resubmit --helpandgym eval reverify --helpare unchanged.Follow-ups (not in this PR)
.jsonljournals. One journal with akindfield would be simpler, but tooling outside this package reads the current files, so their formats stay._) get public names once reviewers have the mapping.