Delv
Weights & Biases
Getting Started Guide

How to Use Weights & Biases

A practical guide to get you up and running with Weights & Biases. Written by Delv Editorial, Delv Team.

Getting started with Weights & Biases

After this guide, you'll be able to track your machine learning experiments, manage datasets, and version your models using Weights & Biases (W&B). You'll set up your account, log your first experiment, and learn tips to improve your workflow.

Step 1: Sign up and set up

  1. Go to wandb.ai.
  2. Click on the Sign Up button in the top right corner.
  3. Choose to sign up with your email or GitHub account, then fill in the required information.
  4. Once you’ve created your account, you may be prompted to install the W&B library. Follow the instructions provided to install it via pip:
pip install wandb
  1. After installation, run the command wandb login in your terminal and enter your API key, which you can find in your W&B dashboard under Settings.

Step 2: Your first experiment

  1. Create a new Python script or Jupyter notebook for your ML project.
  2. At the beginning of your script, import the W&B library with:
import wandb
  1. Before your model training code, initialise W&B with:
wandb.init(project='your_project_name')
  1. Track hyperparameters by adding:
wandb.config.learning_rate = 0.01
   wandb.config.epochs = 10
  1. Log metrics during training. After each epoch, use:
wandb.log({'loss': loss_value, 'accuracy': accuracy_value})
  1. Run your script. Your experiment will be automatically logged to your W&B dashboard.

Step 3: Get better results

  • Use wandb.watch(model) to automatically log gradients and model parameters during training for more insights.
  • Explore W&B dashboards to visualise metrics over time. You can create custom charts by clicking on Create Chart in your project dashboard.
  • Set up alerts for your experiments by going to the Settings of your project and configuring notifications for specific metrics.

Pro tip

Use wandb.save('file_path') to save important files, like model checkpoints or datasets, directly to your W&B dashboard. This keeps your workspace organised and ensures you can access your files later without hassle.

Common mistake to avoid

Avoid forgetting to call wandb.init() at the beginning of your script. If you skip this step, none of your logs or metrics will be tracked in W&B, making it difficult to analyse your experiments later.