C.W.K.
Stream
Lesson 06 of 06 · published

MLOps — Experiment Tracking, Versioning, Monitoring

~12 min · mlops, wandb, mlflow, monitoring

Level 0Tensor Curious
0 XP0/62 lessons0/13 achievements
0/120 XP to next level120 XP to go0% complete

The infrastructure that keeps models alive in production

A model that ships and then sits there is a model that quietly degrades. MLOps is the practice of treating ML models like any other production system: version them, monitor them, retrain them when reality drifts.

The four MLOps pillars

  1. Experiment tracking — log every hyperparameter, metric, and artifact for every run. W&B, MLflow, Comet are the popular tools.
  2. Model versioning — save model + training data + code + environment together. Git LFS, DVC, MLflow Model Registry, or just blob storage with manifest files.
  3. Production monitoring — track latency, throughput, error rate, AND model behavior (prediction distribution, input distribution). Drift detection.
  4. Retraining triggers — automated pipelines that retrain when monitoring signals degradation.

The minimum viable setup

For an indie project, you don't need Kubernetes-managed Kubeflow. You need:

  • One experiment tracker (W&B or MLflow). Pick one and use it consistently.
  • Model files saved with a manifest (date, dataset version, metrics).
  • Production logging that captures inputs and outputs (sampled — don't log every request).
  • A weekly script that compares production prediction distribution to training distribution. Alert on shifts.

That's it. The big-co MLOps stacks add power but are overkill for a team of 1-3. Start simple, add when needed.

Code

Weights & Biases — the popular tracker·python
# pip install wandb
import wandb

wandb.init(project="pytorch-quest", config={
    "lr": 1e-3,
    "epochs": 50,
    "batch_size": 32,
    "architecture": "ResNet50",
})

for epoch in range(50):
    train_loss = train_one_epoch(...)
    val_loss, val_acc = evaluate(...)

    wandb.log({
        "epoch": epoch,
        "train_loss": train_loss,
        "val_loss": val_loss,
        "val_accuracy": val_acc,
        "learning_rate": optimizer.param_groups[0]['lr'],
    })

wandb.save("best_model.pth")    # ship the model artifact too
wandb.finish()
MLflow — the open-source alternative·python
# pip install mlflow
import mlflow

mlflow.set_experiment("pytorch-quest")

with mlflow.start_run():
    mlflow.log_params({
        "lr": 1e-3,
        "epochs": 50,
        "model": "ResNet50",
    })

    for epoch in range(50):
        train_loss = train_one_epoch(...)
        mlflow.log_metric("train_loss", train_loss, step=epoch)

    mlflow.pytorch.log_model(model, "model")
    # mlflow ui  → http://127.0.0.1:5000 to browse runs
Production monitoring — sampled request logging·python
import json
import random
import time
from pathlib import Path

LOG_DIR = Path("/var/log/pippa-pred")
LOG_DIR.mkdir(parents=True, exist_ok=True)

def log_prediction(input_data, prediction, sample_rate=0.01):
    """Log roughly 1% of predictions for offline analysis."""
    if random.random() > sample_rate:
        return
    record = {
        'ts': time.time(),
        'input_summary': summarize_input(input_data),     # avoid logging raw inputs if PII
        'prediction': prediction,
    }
    fname = LOG_DIR / f"{time.strftime('%Y%m%d')}.jsonl"
    with open(fname, 'a') as f:
        f.write(json.dumps(record) + '\n')

# In your serving code:
# log_prediction(req, response.dict())
CI/CD shape — GitHub Actions example·python
# .github/workflows/ml-pipeline.yml
name: ML Pipeline

on:
  push:
    branches: [main]
  schedule:
    - cron: '0 6 * * 0'       # weekly retrain on Sundays

jobs:
  train-evaluate-deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Setup Python
        uses: actions/setup-python@v5
        with:
          python-version: '3.12'
      - name: Install
        run: pip install -r requirements.txt
      - name: Tests
        run: pytest tests/
      - name: Train
        run: python train.py --config config.yaml
      - name: Evaluate
        run: python evaluate.py --threshold 0.90
      - name: Upload artifact
        uses: actions/upload-artifact@v4
        with:
          name: model
          path: outputs/model.pt

External links

Exercise

Pick W&B or MLflow. Add it to ANY training script you've written. Run a sweep over 3 different learning rates. Look at the resulting dashboard / UI — the visual diff between runs is much easier to read than scrolling through console output. That habit alone justifies the 5 minutes of setup.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.