feat(train): make ValidationStep the loop's evaluator, or remove it

Aperta
#154 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
55/100
Tipo di issue
Funzionalità
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python

Direzione di ricerca

Read packages/pipekit-train/src/pipekit_train/loop.py for ValidationStep and TrainingLoop, then inspect _evaluate and the periodic and final evaluation paths in packages/pipekit-train/src/pipekit_train/adapters/equinox.py. First resolve the dependency on #122 and decide whether to wire in ValidationStep or remove it based on #125. Done means the chosen API behavior, backend handling, documentation, and listed tests are complete.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

area:code priority:p2 type:feature

Problem / Request

Either make ValidationStep the evaluator a TrainingLoop can actually use, or remove it.
ValidationStep is exported and documented, but no loop or adapter calls it.
Validation in the Equinox adapter goes through _evaluate, which can only report what loss_fn puts in its aux dict.

User Story

As a pipekit-train user, I want to name validation metrics that are not part of my loss, so that I can track them during training without writing a custom TrainTask.

Motivation

The class implies a capability that the loop does not have.
Today a metric that isn't in the loss needs a custom task, or a callback that re-runs the model itself.

Proposed API

# proposed (this issue); my_metric is a user Operator of (predicted, target)
TrainingLoop(
    model_op=op,
    dataset=train,
    validation=ValidationStep(op, val, metrics=(MSE(), my_metric)),   # instead of val_dataset=
    eval_every_n_steps=500,
)

# in the adapter, on each eval round
metrics = loop.validation.with_model(trained_op)()   # today*: ValidationStep._apply
_dispatch(loop.callbacks, "on_eval_end", loop, carry, metrics)
  • validation and val_dataset are mutually exclusive, and setting both raises ValueError.
  • with_model(op) returns a copy bound to the current weights, because the constructor fixes model_op.

Design Snapshot

ValidationStep today, from packages/pipekit-train/src/pipekit_train/loop.py @ 7c446f1:

def _apply(self) -> dict[str, float]:
    sums: dict[str, float] = {}
    count = 0
    for x, y in self.dataset:
        predicted = self.model_op(x)          # one sample at a time, eagerly
        for metric in self.metrics:
            result = metric(predicted, y)
            ...
        count += 1
    return {k: v / count for k, v in sums.items()}

It runs eagerly per sample, so it is slower than the jitted batched path of #122.

Recommended: wire it in as above, as the simple path for metrics that are means over samples.
Alternative: if #125's eval_fn covers these users, remove ValidationStep from the public API and close this issue as not planned; decide this once #125 lands.

References & Existing Code

  • ValidationStep in packages/pipekit-train/src/pipekit_train/loop.py @ 7c446f1.
  • _evaluate in packages/pipekit-train/src/pipekit_train/adapters/equinox.py @ 7c446f1.
  • LogToExperiment in callbacks.py tags metrics as eval/<name>.

Implementation Steps

  • Add validation: ValidationStep | None = None to TrainingLoop, with the exclusivity check.
  • Add ValidationStep.with_model(op).
  • Call it from the Equinox adapter's periodic and final eval, in place of _evaluate, when it is set.
  • Raise a clear NotImplementedError for validation= on the Bayesian backends.

Definition of Done

  • Code lands at the intended path.
  • Tests pass: make test.
  • Lint + typecheck pass: make lint && make typecheck.
  • Docstrings (Google-style) on all public symbols.

Testing

  • The loop's eval/* metrics equal a standalone ValidationStep's on the same model to 1e-12.
  • Setting both validation and val_dataset raises ValueError.
  • with_model leaves the original step unchanged.

Documentation

  • TrainingLoop docstring and the validation section of docs/design/api/components.md.

Relationships

  • Parent (theme epic): #144
  • Blocked by: #122
  • Related: #125
  • Related: geostack docs/reports/11_pipekit_train.md, workstream C and gate C3
Lingua principale
Python
Stelle
0
Fork
0
Merge medio
3h 50m
PR unite (30g)
143

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di jejjohnson/pipekit

Tutte le issue di jejjohnson/pipekit

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.