How do you track experiments and manage model versions?
Written by the mlprep team · Updated
How do you track ML experiments and manage model versions in a team setting? What breaks down when you don't have a system for this?
Without an experiment tracking system, teams end up with dozens of model files named model_v2_final_FINAL.pkl, no record of what hyperparameters produced them, and no way to reproduce a result from three weeks ago. The cost compounds as the team grows.
What to track per experiment#
Every training run should log:
- Parameters: hyperparameters, model architecture config, data version/hash, preprocessing settings
- Metrics: loss curves, eval metrics at each epoch, final test performance
- Artifacts: model weights, confusion matrices, sample predictions
- Environment: library versions, hardware, random seeds
- Code: git commit hash (so you can check out the exact code that produced it)
Tools#
MLflow is the most common open-source option. You instrument your training code:
with mlflow.start_run():
mlflow.log_params({"lr": 0.001, "batch_size": 32})
mlflow.log_metric("val_auc", 0.87, step=epoch)
mlflow.sklearn.log_model(model, "model")MLflow stores all runs in a queryable database. You can compare runs side-by-side, filter by metric, and retrieve any artifact. Weights & Biases offers similar functionality with better visualization; Neptune and Comet are alternatives.
The model registry#
A model registry is a separate concern from experiment tracking: it manages the lifecycle of models from development to production. A model graduates from an experiment to the registry when it's a candidate for deployment.
The registry tracks:
- Model name and version (v1, v2, v3...)
- Stage (staging, production, archived)
- Lineage: which experiment produced this version
- Metadata: who approved it, when it was deployed, what eval it passed
In MLflow, you promote a run's model artifact to the registry:
mlflow.register_model("runs:/abc123/model", "fraud-detector")
mlflow.models.transition_model_version_stage(
name="fraud-detector", version=3, stage="Production"
)Your serving infrastructure reads from "fraud-detector:Production" — it doesn't care about specific version numbers. When you promote v4, your serving infrastructure picks it up without a code change.
What breaks without it#
Coordination: two engineers run the same experiment with slightly different data splits and get different results — neither knows why. Reproducibility: a model in production starts degrading and you want to retrain, but you can't reconstruct the training run. Auditability: in regulated industries, you need to prove what model made what decision. All of these require the tracking and registry infrastructure.
You mentioned logging the git commit hash for reproducibility — what else do you need to actually reproduce a training run, and what's usually missing in practice?
Full reproducibility requires pinning four things: code, data, environment, and randomness.
Code: Git commit hash covers this if all changes are committed. The common failure mode is running uncommitted code ("I was just experimenting") and not realizing the result was important.
Data: This is the hardest one. A git hash tells you nothing about the training data. Options:
- Hash the dataset file and log the hash. Simple, but breaks for large datasets processed from a warehouse.
- Log the query + timestamp used to pull training data. Works if your warehouse is immutable (append-only).
- DVC: tracks data files in a content-addressable store, like git for data. Log the DVC hash.
- Log a data snapshot version from your feature store.
In practice, many teams log "used data from 2024-01-15 snapshot" and call it good — which is fine as long as snapshots are actually preserved.
Environment: A requirements.txt or pip freeze output captures Python dependencies. Docker images are more reliable — an exact image digest pins the full environment including system libraries. The failure mode: library behavior changes between minor versions (sklearn's default hyperparameters, numpy's random number generator behavior).
Randomness: Log the random seed and set it explicitly everywhere — Python's random, NumPy, PyTorch, the data loader shuffle. The subtle failure: multi-GPU training with non-deterministic CUDA ops is inherently non-reproducible even with a fixed seed. You can get "close but not identical" results.
What's usually missing#
In practice, teams get code and metrics right (MLflow handles this) but fall short on data versioning and environment pinning. The most common scenario: you can find the experiment, see the hyperparameters, but can't reconstruct the exact training set because the data pipeline ran on live data without snapshotting. Investing in data versioning before you need it pays off when debugging production regressions.
The key takeaway unlocks after you reveal an expert answer.
Key Takeaway
Experiment tracking logs parameters, metrics, artifacts, and code per run — enabling comparison and retrieval. A model registry manages lifecycle from experiment to production, decoupling deployment from version numbers. Full reproducibility requires pinning code (git hash), data (DVC or snapshots), environment (Docker), and random seeds. Data versioning is the piece most teams skip and most often regret.
Follow-up Questions to Test Yourself
Interviewers often pivot here once you cover the core concept.
- How would you design an experiment tracking system for a team that runs 500 experiments per day?
- What's the difference between a model registry and a model store, and when do you need both?
- How do you handle the case where two experiments produce identical offline metrics but different production performance?
How confident do you feel explaining this?
Track your understanding or flag it to revisit before your next loop.
Related Questions