Skip to content

count configured validation losses once across resumed training - #110

Open
ZenAlexa wants to merge 2 commits into
PolymathicAI:masterfrom
ZenAlexa:contrib/validation-loss-owner
Open

ZenAlexa wants to merge 2 commits into
PolymathicAI:masterfrom
ZenAlexa:contrib/validation-loss-owner

Conversation

@ZenAlexa

@ZenAlexa ZenAlexa commented Nov 14, 2026 •

Copy link
Copy Markdown

Why

Trainer appends the configured loss to the default validation metric suite. When that exact metric type is already present, both results accumulate under the same output key. On two trajectories with amplitudes 1 and 3, zero predictions give training RMSE 2 and validation RMSE 4. A configured RMSE instance whose forward hook multiplies the result by 3 gives training loss 6 and validation loss 8.

What changed

Let the configured instance own its exact metric type in each Trainer's suite. Retain the other metric types and leave the shared default list unchanged. MSE, custom subclasses and partial callables retain their existing paths.

Also preserve best-model selection when resuming older checkpoints that used an overlapping loss. Their saved scores combine the default and configured instances, so dividing by 2 would be wrong for the hook example. A version marker distinguishes the single-loss score definition. Affected legacy resumes re-evaluate the actual best.pt weights once under the current loss and the same full/short validation sample stream before comparing the current model.

The calibration skips saved evaluation artifacts and restores the current parameters, registered buffer bindings and values, module modes, RNG, explicit loader generators and DDP synchronization state. It doesn't load the old best's optimizer. Pending checkpoints retain the legacy marker until current validation succeeds. An external best-checkpoint source is preserved when input and output directories differ, and a colocated best remains checkpoint-local so the run directory can move together. New best checkpoints save the selected score as their best threshold. Relative checkpoint paths retain their original source directory for this deferred read.

If a historical best score exists and its weights are missing, training identifies the required best.pt path and preserves the existing recovery/evaluation boundary. An early checkpoint with no prior best can continue, and evaluation-only remains available. This stays separate from the scheduler/scaler restoration in #102 and from changes to sampling or the metric formulas.

Verification

Could a maintainer approve the Tests run for 691eccb5 so the Linux Python 3.10 and 3.13 jobs check validation-loss counting and resumed checkpoints?

  • Actual HDF5 loading, train_one_epoch, validation and saved curves cover 11 loss configurations, including the default suite types, the configured hook, MSE, a partial with explicit epsilon and custom losses. The original implementation fails five of those configuration checks.
  • The original resume repro has best-model RMSE 2, saved legacy score 4 and current-model RMSE 3. The corrected resume preserves the better model. The hook case checks a non-factor-of-two migration and a genuine improvement.
  • Checkpoint scenarios cover pre-validation interruption, absent best weights, repeated resume, evaluation-only, legacy MSE and relative-path recovery after the working directory changes. Additional scenarios resume to a new output directory or move the complete run directory, interrupt after writing recent.pt or a periodic checkpoint, then restart while preserving the original best. Checkpoints written after successful calibration no longer depend on that old file. Calibration failure preserves the original exception and current training state.
  • Registered buffers are checked across in-place updates, Tensor rebinding, None initialization, aliases and persistent inference-mode values. Successful calibration and a current-definition control produce identical subsequent state and artifacts.
  • Short-validation recovery is exercised with 0 and 2 DataLoader workers. Real two-process Gloo/DDP execution preserves the old best and matches the control's parameters, BatchNorm buffers, optimizer, RNG and saved arrays.
  • The final new and existing metric/trainer regression selection gives 29 passed. Ruff 0.6.4, formatting and git diff --check pass.

Execution used CPU, Python 3.11.18 and PyTorch 2.15.0. Affected legacy resumes pay for one extra regular validation and a CPU state snapshot, with no second GPU model. Current-format and unaffected MSE resumes keep their existing path. CUDA RNG restoration, NCCL, minimum PyTorch and the remaining Python/platform matrix remain unrun.

Partially sampled versus full validation, DDP sampler padding, rank-local curves, different loss classes that produce the same key, and arbitrary changes of loss configuration keep their existing behavior.

Copilot AI balanced review requested due to automatic review settings November 14, 2026 09:16

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants