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

Open
#154 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
55/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Active
Tech stack
python

Research direction

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.

Written by the indexing model from the issue text.

Description

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
Dominant language
Python
Stars
0
Forks
0
Avg merge
3h 50m
Merged PRs (30d)
143

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from jejjohnson/pipekit

All issues in jejjohnson/pipekit

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.