How to Track Machine Learning Experiments With Weights & Biases

October 12, 2026

Weights & Biases is an experiment tracking platform. You add a few lines to your training script and it records metrics, configs, and model files to a dashboard where you can compare runs.

Quick answer: pip install wandb, run wandb login, then call wandb.init() and wandb.log() inside your training loop. Free for personal projects and academic use.

The honest case for it: if you have ever trained five variants and could not remember which learning rate was which, you need this. If you train one model once, a print statement is fine.

How do you install and log in?

pip install wandb
wandb login

wandb login opens a browser for an API key. On a headless server, set WANDB_API_KEY as an environment variable instead and the client picks it up.

How do you log a training run?

import wandb

wandb.init(project="churn-model",
           config={"lr": 1e-3, "batch_size": 64, "epochs": 20})

for epoch in range(20):
    train_loss = train_one_epoch()
    val_loss = evaluate()
    wandb.log({"train_loss": train_loss,
               "val_loss": val_loss, "epoch": epoch})

wandb.finish()

The config dictionary is what makes runs comparable. Anything you put there shows up as a filterable column in the dashboard.

How do you compare runs?

Each wandb.init() is one run. Open the project dashboard and you get a table of runs with their configs, plus overlay charts that plot every run’s loss curve on one axis. Sorting by final validation loss tells you which config won in one glance.

What are runs and artifacts?

Concept What it holds
Run One execution: metrics, config, logs
Artifact Versioned files: datasets, model weights
Sweep A grid or Bayesian hyperparameter search
Report A shareable write-up with live charts

Artifacts are the underused feature. Version your dataset and your trained weights, and you can reproduce a run months later instead of hunting through folders.

How do you run a hyperparameter sweep?

sweep = {"method": "bayes",
         "metric": {"name": "val_loss", "goal": "minimize"},
         "parameters": {"lr": {"values": [1e-4, 1e-3, 1e-2]},
                        "batch_size": {"values": [32, 64, 128]}}}

sweep_id = wandb.sweep(sweep, project="churn-model")
wandb.agent(sweep_id, function=train)

The Bayesian method usually finds a good config in fewer runs than a full grid. You can stop a sweep early once the best metric plateaus.

Is W&B free?

Free for personal projects and academic use, with limits on storage and team members. Team and enterprise plans bill per seat and add private projects, SSO, and longer retention. For a solo practitioner the free tier is usually enough for a long time.

What are the downsides?

  • Runs are logged to their cloud by default; offline mode exists but you lose the live dashboard.
  • Logging every step of a huge run can slow training if you are careless with frequency.
  • Free-tier storage is not unlimited — large artifacts can hit the cap.
  • The Python API is stable, but the product surface changes often.

Who this suits: anyone running repeated experiments, especially teams who need to share results. Who should skip it: one-off training jobs where a text log already answers every question you have.

Quick Summary

  • W&B logs metrics, configs, and artifacts from any Python training script.
  • Use wandb.init, wandb.log, and wandb.finish in that order.
  • Config dictionaries make runs filterable and comparable.
  • Artifacts version datasets and model weights for later reproduction.
  • Free for personal and academic use; paid for teams.