Skip to main content

Quickstart

This guide outlines a common method for integrating W&B into your code. There are for main steps:

  1. Set up W&B
  2. Track metrics
  3. Track hyperparameters
  4. Get an alert

Set up W&B

Satisfy the following requirements to get started with W&B:

  1. Sign up for a free account at https://wandb.ai/site and then login to your wandb account.
  2. Install the wandb library on your machine in a Python 3 environment using pip.
  3. Login to the wandb library on your machine. You will find your API key here: https://wandb.ai/authorize.

The following code snippets demonstrate how to install and log into W&B using the W&B CLI and Python Library:

Install the CLI and Python library for interacting with the Weights and Biases API:

pip install wandb

Next, log in to W&B:

wandb login

Or if you're using W&B Server:

wandb login --host=http://wandb.your-shared-local-host.com

Start a new Run

Initialize a new Run in W&B in your Python script or notebook with wandb.init(). At the top of your training script add the following code snippet:

import wandb
wandb.init(project="my-awesome-project")

W&B tracks system metrics and console logs when you call the wandb.init() API.

Run your code and put in your API key when prompted. In the next step, we will show you how to track metrics.

Track metrics

Use wandb.log() to track metrics or a framework integration for easy instrumentation.

wandb.log({'accuracy': train_acc, 'loss': train_loss})

W&B saves metrics you log with wandb.log to the Run object you initialized. In this case, the accuracy and loss are associated with the W&B Run we initialized in the previous step.

Track hyperparameters

Save hyperparameters with wandb.config. Tracking hyperparameters makes it easy to compare experiments with the W&B App.

wandb.config.dropout = 0.2

Attributes stored in a wandb.config object are associated with the most recent initialized Run object.

Get alerts

Get notified by Slack or email if your W&B Run has crashed or with a custom trigger. For example, you can create a trigger to notify you if your loss reports NaN or a step in your ML pipeline has completed.

Follow the procedure outlined below to set up an alert:

  1. Turn on Alerts in your W&B User Settings.
  2. Add wandb.alert() to your code.
wandb.alert(
title="Low accuracy",
text=f"Accuracy {acc} is below threshold {thresh}"
)

You will receive an email or Slack alert when your alert criteria is met. For example, the proceeding image demonstrates a Slack alert:

W&B Alerts in a Slack channel

See the Alerts docs for more information on how to set up an alert. For more information about setting options, see the Settings page.

What next?

  1. Collaborative Reports: Snapshot results, take notes, and share findings
  2. Data + Model Versioning: Track dependencies and results in your ML pipeline
  3. Data Visualization: Visualize and query datasets and model evaluations
  4. Hyperparameter Tuning: Quickly automate optimizing hyperparameters
  5. Private-Hosting: The enterprise solution for private cloud or on-prem hosting of W&B

Common Questions

Where do I find my API key? Once you've signed in to www.wandb.ai, the API key will be on the Authorize page.

How do I use W&B in an automated environment? If you are training models in an automated environment where it's inconvenient to run shell commands, such as Google's CloudML, you should look at our guide to configuration with Environment Variables.

Do you offer local, on-prem installs? Yes, you can privately host W&B locally on your own machines or in a private cloud, try this quick tutorial notebook to see how. Note, to login to wandb local server you can set the host flag to the address of the local instance. ****

How do I turn off wandb logging temporarily? If you're testing code and want to disable wandb syncing, set the environment variable WANDB_MODE=offline.

Was this page helpful?👍👎