Skip to content

Guide · Open source

How to use wandb: install, log runs and compare experiments

Updated · written with AI from the project's own documentation and checked against our catalogue data

wandb is the Python library for Weights & Biases (W&B), a platform for tracking machine learning experiments and viewing them in a web dashboard. This guide is for machine learning engineers and researchers who want to record training runs without a lot of extra code. By the end you will know how to install wandb, start a run, log metrics such as accuracy and loss, and find those runs again in the dashboard.

Weights & Biaseswandb/wandb · ★ 11.3k · MIT

Quick start

  1. 1Install wandb. Run pip install wandb in your Python environment.
  2. 2Create an API key. Sign up for a W&B account and create a key at wandb.ai/settings, then store it safely.
  3. 3Configure the key. Optionally run wandb login, or wait for W&B to prompt you the first time you use it.
  4. 4Initialize a run. Call wandb.init() with a project name and a config dictionary of hyperparameters.
  5. 5Log metrics. Call run.log() with values such as accuracy and loss during training.
  6. 6Review results. Open wandb.ai/home to view and compare your recorded runs.

Install the wandb library

wandb is installed with pip, the Python package manager. The only prerequisite named in the source is Python.

pip install wandb

Sign up and set up your API key

Sign up for a W&B account and create an API key at wandb.ai/settings. Store the key somewhere safe such as a password manager or an environment variable, because API keys can only be viewed once when created.

You can optionally run the wandb login CLI command to configure the key on your machine. You can also skip this step, since W&B prompts you for an API key the first time you use it.

  • API keys can only be viewed once, so save them when you create them.
  • Use a password manager or environment variable to store the key.
wandb login

Start a run and log hyperparameters and metrics

In your Python script or notebook, call wandb.init() to start a run. Pass a config dictionary to record hyperparameters, such as the number of epochs and the learning rate. Inside the run, call run.log() with a dictionary of values to record metrics.

Using a with block marks the run as finished when the block exits, and marks it as failed if an exception occurs. In a notebook you can instead write run = wandb.init() and call run.finish() yourself.

  • project sets which project the run is recorded to.
  • config holds hyperparameters as a dictionary.
  • run.log() sends values such as accuracy and loss.
import wandb # Project that the run is recorded to project = "my-awesome-project" # Dictionary with hyperparameters config = {"epochs": 1337, "lr": 3e-4} # The `with` syntax marks the run as finished upon exiting the `with` block, # and it marks the run "failed" if there's an exception. # # In a notebook, it may be more convenient to write `run = wandb.init()` # and manually call `run.finish()` instead of using a `with` block. with wandb.init(project=project, config=config) as run: # Training code here # Log values to W&B with run.log() run.log({"accuracy": 0.9, "loss": 0.1})

View and compare runs in the dashboard

Open wandb.ai/home to see recorded metrics such as accuracy and loss and how they changed during each training step. Each run appears in the Runs column with a generated name.

Because every run is stored, you can return to earlier experiments and compare them, which is the main reason to use a tracker instead of a single script.

Choose where your data is hosted

The source describes three hosting options. Multi-tenant Cloud is fully managed and deployed in W&B's Google Cloud Platform account in North America regions. Dedicated Cloud is single-tenant and fully managed in W&B's AWS, GCP, or Azure accounts. Self-Managed means you deploy W&B Server on your own AWS, GCP, or Azure account or on-premises infrastructure.

The default workflow uses the hosted W&B account, so if your data cannot leave your organisation, look at the self-managed option.

  • Multi-tenant Cloud: managed by W&B on GCP.
  • Dedicated Cloud: single-tenant managed on AWS, GCP, or Azure.
  • Self-Managed: you run W&B Server yourself.

Know what wandb does not cover

The README points LLM app monitoring to a separate product called Weave, which tracks, debugs, evaluates and monitors LLM apps. If that is your main need, start there instead of the experiment tracker.

The README also lists integrations with popular ML frameworks, and says developers can follow the W&B Developer Guide to add W&B to a new framework. Check the integrations documentation for the frameworks you use.

What people use it for

  • Comparing training runs over time to see which hyperparameters improved accuracy or lowered loss.
  • Tuning hyperparameters across many experiments and keeping a record of each one.
  • Sharing experiment results with colleagues through the W&B dashboard.
  • Adding tracking to existing PyTorch, TensorFlow, or Keras projects with a few lines of code.

Frequently asked questions

Is wandb free?

The source README does not state pricing or licence terms for the hosted service. The wandb library itself is listed under the MIT License, so check the W&B website and the LICENSE file for current plan details.

What is wandb used for?

wandb is used to track machine learning experiments. You record hyperparameters and metrics like accuracy and loss in a Python script, then view and compare runs in a web dashboard.

How do I install wandb?

Run pip install wandb. The README names Python as the prerequisite. Then optionally run wandb login to set your API key on the machine.

Do I need an API key to use wandb?

You can run wandb login to configure your key ahead of time. If you skip this, W&B prompts you to create an API key the first time you use it.

Can I host wandb myself?

Yes. The README describes Self-Managed hosting, where you deploy W&B Server on your AWS, GCP, or Azure account or on-premises infrastructure.

What are alternatives to wandb?

The source lists MLflow, TensorBoard, Neptune and Comet as comparable projects. Compare them on hosting, cost and the frameworks you use before choosing.

New agent skills, repos and AI tools — every week

The best new skills and open-source projects, the fastest-growing repos, and one free prompt. Five minutes to read. Unsubscribe anytime.

Our verdict

wandb suits machine learning engineers and researchers who run many training experiments and want to compare them in a shared dashboard, especially with PyTorch, TensorFlow or Keras. Skip it if you only run a script once, cannot send data to a third-party service and do not want to self-host, or only need LLM app monitoring, where the README points to Weave.

Install options & downloads