Quickstart
This guide outlines a common method for integrating W&B into your code. There are for main steps:
Set up W&B
Satisfy the following requirements to get started with W&B:
- Sign up for a free account at https://wandb.ai/site and then login to your wandb account.
- Install the wandb library on your machine in a Python 3 environment using
pip
. - 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:
- Command Line
- Notebook
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
Install the CLI and Python library for interacting with the Weights and Biases API:
!pip install wandb
Next, import the W&B Python SDK and log in:
import wandb
wandb.login()
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:
- Turn on Alerts in your W&B User Settings.
- 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:
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?
- Collaborative Reports: Snapshot results, take notes, and share findings
- Data + Model Versioning: Track dependencies and results in your ML pipeline
- Data Visualization: Visualize and query datasets and model evaluations
- Hyperparameter Tuning: Quickly automate optimizing hyperparameters
- 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
.