Experiment Tracking
Every run, logged forever
Experiment tracking records every run: hyperparameters, metrics, artifacts and code version. Without it, 'which config beat the baseline?' is unknowable and every improvement is unverifiable. Tools: MLflow, W&B, custom SQLite + git.
What you will learn
- Log params, metrics, artifacts and environment per run
- Compare runs and promote the verified best
- Integrate tracking with git commit and dataset version
What is this?
Experiment tracking persists one record per training run: hyperparameters, metrics (train/val/test), artifacts (weights, model, plots), config, git commit, data version and environment. That record makes comparisons honest, regression hunts possible, and promotion decisions revertible. A tracker can be a tool (MLflow, Weights & Biases) or a thin wrapper around a SQLite table + git tags — the discipline matters more than the tool.
Why do you need it?
- You cannot compare what you didn't log — 'it worked yesterday' isn't evidence.
- Wasted compute: retraining to recall a forgotten best config is expensive.
- Audit: compliance and debugging need to know exactly what produced a model.
- Baselines become a first-class artifact, so improvements are provable.
Mental model
A lab notebook with a strict protocol
Experiment tracking
Every experiment gets a dated page: what went in, what happened, what came out, which equipment (env/seed). Months later you can open the winning page and reproduce it exactly — and you can prove to a reviewer that you tested the controls.
How it works
- Wrap the run: start_run records start time, git commit and run name/hash.
- Log hyperparameters (lr, n_estimators, data version) as params.
- Log metrics at intervals (loss, auc) and at the end (final, best-epoch).
- Store artifacts: model weights, plots, preds, eval reports with a path + hash.
- Query: list/filter runs, compare tables, diff against baseline, promote via a declared best_commit.
One run's record feeds comparison and promotion.
In production
- Hunt regressions: a metric dip ties to a specific git commit + data version.
- Compliance: per-model lineage (code, data, config, metrics) on demand.
- Auto-MLOps: winner of an HPO sweep auto-registers to a model registry.
Best practices
- Put git commit + dataset hash in EVERY run; untagged runs are worthless.
- Pick the promotion metric once (e.g. val-AUC) and log it consistently across runs.
- Snapshot baseline runs first — before touching any hyperparameter.
- Log raw numeric metrics, not just plots; plots compliment, they don't substitute.
Common mistakes
- Tuning parameters without an active run — the 'what did I change last night' trap.
- Comparing runs with different data/validation splits and calling the diff a model win.
- Logging final loss only, with no learning curve to inspect convergence.
- Letting runs overwrite the same artifact path (no per-run directory).
Common issues
Runs with identical name but different resultsNo run hash or code-not-committed
Auto-tag with commit + dataset hash and reject runs missing those tags.
Artifact path collision across runsStatic file name in a shared dir
Per-run directory (run_id/) and content hashes in artifact names.
Tracker down breaks trainingTracking treated as critical path
Local-first logging with async/retry; a tracking failure must never fail training.
Debugging tips
- Every run's loss curve should be immediately plottable — flat or spike curves localize bugs.
- A metric that 'improves' but your check fails (NaN, negative) is tracking pollution — validate before logging.
- Diff one param at a time vs baseline: attribution only survives single-variable changes.
- Check run count per day; runs you can't account for are usually config mistakes.
Interview checkpoint
Hands-on lab
- Build a minimal run-logging store
- Log params, metrics and hash per run
- Query and rank runs to pick a winner
Track Runs Like a Pro
30 min · intermediate
Quick quiz
Which is NOT a reason to log artifacts per run?
A valid comparison needs the same validation split across runs.