Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Weights & Biases

Weights & Biases documentation Example Usage

What it is

Weights & Biases (W&B) is a cloud-hosted experiment tracker. Results are stored at wandb.ai and every run gets a shareable URL so there is no local infrastructure required for anyone who needs to view them.

Why use it

W&B takes the same idea as MLflow: logs parameters, metrics, and artifacts per run and makes the results accessible from anywhere via a browser link. That makes it the natural choice for distributed teams: a collaborator clicks a URL and sees the dashboards, no local setup, no shared filesystem.

When to use it

How to use it

Install

uv sync   # wandb is in pyproject.toml
# or: uv add wandb

Authenticate (one-time)

wandb login
# Stores the API key in ~/.netrc

For CI or containers, set the key as an environment variable instead:

export WANDB_API_KEY=your_api_key_here

Configure with environment variables

VariablePurpose
WANDB_PROJECTProject to log to
WANDB_ENTITYUser or team namespace
WANDB_MODEonline, offline, or disabled
WANDB_DATA_DIRLocal directory for run files
DATA_ROOTApplication-level path to training data

Run and track

python scripts/train_sst_wandb.py --run-name "experiment_1"
# → Run URL printed to console

What gets tracked per run

Each run in workshop-sst logs:

TypeValues
Parametersn_lags, test_size, seed, roll
MetricsR², RMSE
ConfigDVC data MD5, DVC model MD5, package version
Artifactsconfig JSON, predictions CSV, feature importance CSV, plot PNG
Modellinked to the W&B Model Registry with a version alias (e.g. v0.6.2)

Load a registered model

import joblib
from pathlib import Path
import wandb

run = wandb.init()
artifact = run.use_artifact("wandb-registry-workshop-sst/models:v0.6.2")
model = joblib.load(Path(artifact.download()) / "model.joblib")

Run offline on HPC

If the cluster has no outbound network access:

WANDB_MODE=offline python scripts/train_sst_wandb.py

Sync the runs when network is available:

wandb sync wandb/offline-run-*

Notes from use

A few things worth knowing before you wire W&B into a training script:

Pros and cons

ProsCons
Shareable run URLs with no local setup for viewersRequires an account
Rich built-in dashboardsFree tier: 5-model registry limit
Offline sync for restricted networksData is stored on W&B servers
Team roles and project visibility controlsSingle-point metrics render as empty charts

Reference