W&B Models is the system of record for ML Practitioners who want to organize their models, boost productivity and collaboration, and deliver production ML at scale.
Configure custom automations that trigger key workflows for model CI/CD.
Machine learning practitioners rely on W&B Models as their ML system of record to track and visualize experiments, manage model versions and lineage, and optimize hyperparameters.
Track machine learning experiments with a few lines of code. You can then review the results in an interactive dashboard or export your data to Python for programmatic access using our Public API.
Utilize W&B Integrations if you use popular frameworks such as PyTorch, Keras, or Scikit. See our Integration guides for a for a full list of integrations and information on how to add W&B to your code.
The image above shows an example dashboard where you can view and compare metrics across multiple runs.
How it works
Track a machine learning experiment with a few lines of code:
Store a dictionary of hyperparameters, such as learning rate or model type, into your configuration (run.config).
Log metrics (run.log()) over time in a training loop, such as accuracy and loss.
Save outputs of a run, like the model weights or a table of predictions.
The following code demonstrates a common W&B experiment tracking workflow:
# Start a run.## When this block exits, it waits for logged data to finish uploading.# If an exception is raised, the run is marked failed.with wandb.init(entity="", project="my-project-name") as run:
# Save mode inputs and hyperparameters. run.config.learning_rate =0.01# Run your experiment code.for epoch in range(num_epochs):
# Do some training...# Log metrics over time to visualize model performance. run.log({"loss": loss})
# Upload model outputs as artifacts. run.log_artifact(model)
Get started
Depending on your use case, explore the following resources to get started with W&B Experiments:
Read the W&B Quickstart for a step-by-step outline of the W&B Python SDK commands you could use to create, track, and use a dataset artifact.
Use the W&B Python SDK to track machine learning experiments. You can then review the results in an interactive dashboard or export your data to Python for programmatic access with the W&B Public API.
This guide describes how to use W&B building blocks to create a W&B Experiment.
The following snippet creates a run in a W&B project named “cat-classification” with the description “My first experiment” to help identify this run. Tags “baseline” and “paper1” are included to remind us that this run is a baseline experiment intended for a future paper publication.
import wandb
with wandb.init(
project="cat-classification",
notes="My first experiment",
tags=["baseline", "paper1"],
) as run:
...
Note: Runs are added to pre-existing projects if that project already exists when you call wandb.init(). For example, if you already have a project called “cat-classification”, that project will continue to exist and not be deleted. Instead, a new run is added to that project.
Capture a dictionary of hyperparameters
Save a dictionary of hyperparameters such as learning rate or model type. The model settings you capture in config are useful later to organize and query your results.
with wandb.init(
...,
config={"epochs": 100, "learning_rate": 0.001, "batch_size": 128},
) as run:
...
Optionally log a W&B Artifact. Artifacts make it easy to version datasets and models.
# You can save any file or even a directory. In this example, we pretend# the model has a save() method that outputs an ONNX file.model.save("path_to_model.onnx")
run.log_artifact("path_to_model.onnx", name="trained-model", type="model")
For more information about Artifacts, see the Artifacts Chapter. For more information about versioning models, see Model Management.
Putting it all together
The full script with the preceding code snippets is found below:
import wandb
with wandb.init(
project="cat-classification",
notes="",
tags=["baseline", "paper1"],
# Record the run's hyperparameters. config={"epochs": 100, "learning_rate": 0.001, "batch_size": 128},
) as run:
# Set up model and data. model, dataloader = get_model(), get_data()
# Run your training while logging metrics to visualize model performance.for epoch in range(run.config["epochs"]):
for batch in dataloader:
loss, accuracy = model.training_step()
run.log({"accuracy": accuracy, "loss": loss})
# Upload the trained model as an artifact. model.save("path_to_model.onnx")
run.log_artifact("path_to_model.onnx", name="trained-model", type="model")
Next steps: Visualize your experiment
Use the W&B Dashboard as a central place to organize and visualize results from your machine learning models. With just a few clicks, construct rich, interactive charts like parallel coordinates plots, parameter importance analyzes, and more.
The following are some suggested guidelines to consider when you create experiments:
Finish your runs: Use wandb.init() in a with statement to automatically mark the run as finished when the code completes or raises an exception.
In Jupyter notebooks, it may be more convenient to manage the Run object yourself. In this case, you can explicitly call finish() on the Run object to mark it complete:
# In a notebook cell:run = wandb.init()
# In a different cell:run.finish()
Config: Track hyperparameters, architecture, dataset, and anything else you’d like to use to reproduce your model. These will show up in columns— use config columns to group, sort, and filter runs dynamically in the app.
Project: A project is a set of experiments you can compare together. Each project gets a dedicated dashboard page, and you can easily turn on and off different groups of runs to compare different model versions.
Notes: Set a quick commit message directly from your script. Edit and access notes in the Overview section of a run in the W&B App.
Tags: Identify baseline runs and favorite runs. You can filter runs using tags. You can edit tags at a later time on the Overview section of your project’s dashboard on the W&B App.
Create multiple run sets to compare experiments: When comparing experiments, create multiple run sets to make metrics easy to compare. You can toggle run sets on or off on the same chart or group of charts.
The following code snippet demonstrates how to define a W&B Experiment using the best practices listed above:
Use the config property of a run to save your training configuration:
hyperparameter
input settings such as the dataset name or model type
any other independent variables for your experiments.
The run.config property makes it easy to analyze your experiments and reproduce your work in the future. You can group by configuration values in the W&B App, compare the configurations of different W&B runs, and evaluate how each training configuration affects the output. The config property is a dictionary-like object that can be composed from multiple dictionary-like objects.
To save output metrics or dependent variables like loss and accuracy, use run.log instead of run.config.
Set up an experiment configuration
Configurations are typically defined in the beginning of a training script. Machine learning workflows may vary, however, so you are not required to define a configuration at the beginning of your training script.
Use dashes (-) or underscores (_) instead of periods (.) in your config variable names.
Use the dictionary access syntax ["key"]["value"] instead of the attribute access syntax config.key.value if your script accesses run.config keys below the root.
The following sections outline different common scenarios of how to define your experiments configuration.
Set the configuration at initialization
Pass a dictionary at the beginning of your script when you call the wandb.init() API to generate a background process to sync and log data as a W&B Run.
The proceeding code snippet demonstrates how to define a Python dictionary with configuration values and how to pass that dictionary as an argument when you initialize a W&B Run.
import wandb
# Define a config dictionary objectconfig = {
"hidden_layer_sizes": [32, 64],
"kernel_sizes": [3],
"activation": "ReLU",
"pool_sizes": [2],
"dropout": 0.5,
"num_classes": 10,
}
# Pass the config dictionary when you initialize W&Bwith wandb.init(project="config_example", config=config) as run:
...
If you pass a nested dictionary as the config, W&B flattens the names using dots.
Access the values from the dictionary similarly to how you access other dictionaries in Python:
# Access values with the key as the index valuehidden_layer_sizes = run.config["hidden_layer_sizes"]
kernel_sizes = run.config["kernel_sizes"]
activation = run.config["activation"]
# Python dictionary get() methodhidden_layer_sizes = run.config.get("hidden_layer_sizes")
kernel_sizes = run.config.get("kernel_sizes")
activation = run.config.get("activation")
Throughout the Developer Guide and examples we copy the configuration values into separate variables. This step is optional. It is done for readability.
Set the configuration with argparse
You can set your configuration with an argparse object. argparse, short for argument parser, is a standard library module in Python 3.2 and above that makes it easy to write scripts that take advantage of all the flexibility and power of command line arguments.
This is useful for tracking results from scripts that are launched from the command line.
The proceeding Python script demonstrates how to define a parser object to define and set your experiment config. The functions train_one_epoch and evaluate_one_epoch are provided to simulate a training loop for the purpose of this demonstration:
# config_experiment.pyimport argparse
import random
import numpy as np
import wandb
# Training and evaluation demo codedeftrain_one_epoch(epoch, lr, bs):
acc =0.25+ ((epoch /30) + (random.random() /10))
loss =0.2+ (1- ((epoch -1) /10+ random.random() /5))
return acc, loss
defevaluate_one_epoch(epoch):
acc =0.1+ ((epoch /20) + (random.random() /10))
loss =0.25+ (1- ((epoch -1) /10+ random.random() /6))
return acc, loss
defmain(args):
# Start a W&B Runwith wandb.init(project="config_example", config=args) as run:
# Access values from config dictionary and store them# into variables for readability lr = run.config["learning_rate"]
bs = run.config["batch_size"]
epochs = run.config["epochs"]
# Simulate training and logging values to W&Bfor epoch in np.arange(1, epochs):
train_acc, train_loss = train_one_epoch(epoch, lr, bs)
val_acc, val_loss = evaluate_one_epoch(epoch)
run.log(
{
"epoch": epoch,
"train_acc": train_acc,
"train_loss": train_loss,
"val_acc": val_acc,
"val_loss": val_loss,
}
)
if __name__ =="__main__":
parser = argparse.ArgumentParser(
formatter_class=argparse.ArgumentDefaultsHelpFormatter
)
parser.add_argument("-b", "--batch_size", type=int, default=32, help="Batch size")
parser.add_argument(
"-e", "--epochs", type=int, default=50, help="Number of training epochs" )
parser.add_argument(
"-lr", "--learning_rate", type=int, default=0.001, help="Learning rate" )
args = parser.parse_args()
main(args)
Set the configuration throughout your script
You can add more parameters to your config object throughout your script. The proceeding code snippet demonstrates how to add new key-value pairs to your config object:
import wandb
# Define a config dictionary objectconfig = {
"hidden_layer_sizes": [32, 64],
"kernel_sizes": [3],
"activation": "ReLU",
"pool_sizes": [2],
"dropout": 0.5,
"num_classes": 10,
}
# Pass the config dictionary when you initialize W&Bwith wandb.init(project="config_example", config=config) as run:
# Update config after you initialize W&B run.config["dropout"] =0.2 run.config.epochs =4 run.config["batch_size"] =32
You can update multiple values at a time:
run.config.update({"lr": 0.1, "channels": 16})
Set the configuration after your Run has finished
Use the W&B Public API to update a completed run’s config.
You must provide the API with your entity, project name and the run’s ID. You can find these details in the Run object or in the W&B App UI:
with wandb.init() as run:
...# Find the following values from the Run object if it was initiated from the# current script or notebook, or you can copy them from the W&B App UI.username = run.entity
project = run.project
run_id = run.id
# Note that api.run() returns a different type of object than wandb.init().api = wandb.Api()
api_run = api.run(f"{username}/{project}/{run_id}")
api_run.config["bar"] =32api_run.update()
flags.DEFINE_string("model", None, "model to run") # name, default, helprun.config.update(flags.FLAGS) # adds absl flags to config
File-Based Configs
If you place a file named config-defaults.yaml in the same directory as your run script, the run automatically picks up the key-value pairs defined in the file and passes them to run.config.
The following code snippet shows a sample config-defaults.yaml YAML file:
batch_size:
desc: Size of each mini-batchvalue: 32
You can override the default values automatically loaded from config-defaults.yaml by setting updated values in the config argument of wandb.init. For example:
import wandb
# Override config-defaults.yaml by passing custom valueswith wandb.init(config={"epochs": 200, "batch_size": 64}) as run:
...
To load a configuration file other than config-defaults.yaml, use the --configs command-line argument and specify the path to the file:
python train.py --configs other-config.yaml
Example use case for file-based configs
Suppose you have a YAML file with some metadata for the run, and then a dictionary of hyperparameters in your Python script. You can save both in the nested config object:
hyperparameter_defaults = dict(
dropout=0.5,
batch_size=100,
learning_rate=0.001,
)
config_dictionary = dict(
yaml=my_yaml_file,
params=hyperparameter_defaults,
)
with wandb.init(config=config_dictionary) as run:
...
TensorFlow v1 flags
You can pass TensorFlow flags into the wandb.config object directly.
with wandb.init() as run:
run.config.epochs =4 flags = tf.app.flags
flags.DEFINE_string("data_dir", "/tmp/data")
flags.DEFINE_integer("batch_size", 128, "Batch size.")
run.config.update(flags.FLAGS) # add tensorflow flags as config
1.3 - Projects
Compare versions of your model, explore results in a scratch workspace, and export findings to a report to save notes and visualizations
A project is a central location where you visualize results, compare experiments, view and download artifacts, create an automation, and more.
Each project has a visibility setting that determines who can access it. For more information about who can access a project, see Project visibility.
Each project contains the proceeding which you can access from the sidebar:
Reports: saved snapshots of notes, runs, and graphs
Artifacts: Contains all runs and the artifacts associated with that run
Overview tab
Project name: The name of the project. W&B creates a project for you when you initialize a run with the name you provide for the project field. You can change the name of the project at any time by selecting the Edit button in the upper right corner.
Description: A description of the project.
Project visibility: The visibility of the project. The visibility setting that determines who can access it. See Project visibility for more information.
Last active: Timestamp of the last time data is logged to this project
Owner: The entity that owns this project
Contributors: The number of users that contribute to this project
Total runs: The total number of runs in this project
Total compute: we add up all the run times in your project to get this total
Undelete runs: Click the dropdown menu and click “Undelete all runs” to recover deleted runs in your project.
Delete project: click the dot menu in the right corner to delete a project
A project’s workspace gives you a personal sandbox to compare experiments. Use projects to organize models that can be compared, working on the same problem with different architectures, hyperparameters, datasets, preprocessing etc.
Runs Sidebar: list of all the runs in your project.
Dot menu: hover over a row in the sidebar to see the menu appear on the left side. Use this menu to rename a run, delete a run, or stop and active run.
Visibility icon: click the eye to turn on and off runs on graphs
Color: change the run color to another one of our presets or a custom color
Search: search runs by name. This also filters visible runs in the plots.
Filter: use the sidebar filter to narrow down the set of runs visible
Group: select a config column to dynamically group your runs, for example by architecture. Grouping makes plots show up with a line along the mean value, and a shaded region for the variance of points on the graph.
Sort: pick a value to sort your runs by, for example runs with the lowest loss or highest accuracy. Sorting will affect which runs show up on the graphs.
Expand button: expand the sidebar into the full table
Run count: the number in parentheses at the top is the total number of runs in the project. The number (N visualized) is the number of runs that have the eye turned on and are available to be visualized in each plot. In the example below, the graphs are only showing the first 10 of 183 runs. Edit a graph to increase the max number of runs visible.
If you pin, hide, or change the order of columns in the Runs tab, the Runs sidebar reflects these customizations.
Panels layout: use this scratch space to explore results, add and remove charts, and compare versions of your models based on different metrics
Click the section dropdown menu and click “Add section” to create a new section for panels. You can rename sections, drag them to reorganize them, and expand and collapse sections.
Each section has options in the upper right corner:
Switch to custom layout: The custom layout allows you to resize panels individually.
Switch to standard layout: The standard layout lets you resize all panels in the section at once, and gives you pagination.
Add section: Add a section above or below from the dropdown menu, or click the button at the bottom of the page to add a new section.
Rename section: Change the title for your section.
Export section to report: Save this section of panels to a new report.
Delete section: Remove the whole section and all the charts. This can be undone with the undo button at the bottom of the page in the workspace bar.
Add panel: Click the plus button to add a panel to the section.
Move panels between sections
Drag and drop panels to reorder and organize into sections. You can also click the “Move” button in the upper right corner of a panel to select a section to move the panel to.
Resize panels
Standard layout: All panels maintain the same size, and there are pages of panels. You can resize the panels by clicking and dragging the lower right corner. Resize the section by clicking and dragging the lower right corner of the section.
Custom layout: All panels are sized individually, and there are no pages.
Search for metrics
Use the search box in the workspace to filter down the panels. This search matches the panel titles, which are by default the name of the metrics visualized.
Runs tab
Use the Runs tab to filter, group, and sort your runs.
The proceeding tabs demonstrate some common actions you can take in the Runs tab.
The Runs tab shows details about runs in the project. It shows a large number of columns by default.
To view all visible columns, scroll the page horizontally.
To change the order of the columns, drag a column to the left or right.
To pin a column, hover over the column name, click the action menu .... that appears, then click Pin column. Pinned columns appear near the left of the page, after the Name column. To unpin a pinned column, choose Unpin column
To hide a column, hover over the column name, click the action menu .... that appears, then click Hide column. To view all columns that are currently hidden, click Columns.
To show, hide, pin, and unpin multiple columns at once, click Columns.
Click the name of a hidden column to unhide it.
Click the name of a visible column to hide it.
Click the pin icon next to a visible column to pin it.
When you customize the Runs tab, the customization is also reflected in the Runs selector of the Workspace tab.
Sort all rows in a Table by the value in a given column.
Hover your mouse over the column title. A kebob menu will appear (three vertical docs).
Select on the kebob menu (three vertical dots).
Choose Sort Asc or Sort Desc to sort the rows in ascending or descending order, respectively.
The preceding image demonstrates how to view sorting options for a Table column called val_acc.
Filter all rows by an expression with the Filter button on the top left of the dashboard.
Select Add filter to add one or more filters to your rows. Three dropdown menus will appear. From left to right the filter types are based on: Column name, Operator , and Values
Column name
Binary relation
Value
Accepted values
String
=, ≠, ≤, ≥, IN, NOT IN,
Integer, float, string, timestamp, null
The expression editor shows a list of options for each term using autocomplete on column names and logical predicate structure. You can connect multiple logical predicates into one expression using “and” or “or” (and sometimes parentheses).
The preceding image shows a filter that is based on the `val_loss` column. The filter shows runs with a validation loss less than or equal to 1.
Group all rows by the value in a particular column with the Group by button in a column header.
By default, this turns other numeric columns into histograms showing the distribution of values for that column across the group. Grouping is helpful for understanding higher-level patterns in your data.
Reports tab
See all the snapshots of results in one place, and share findings with your team.
On the overview panel, you’ll find a variety of high-level information about the artifact, including its name and version, the hash digest used to detect changes and prevent duplication, the creation date, and any aliases. You can add or remove aliases here, take notes on both the version as well as the artifact as a whole.
Metadata panel
The metadata panel provides access to the artifact’s metadata, which is provided when the artifact is constructed. This metadata might include configuration arguments required to reconstruct the artifact, URLs where more information can be found, or metrics produced during the run which logged the artifact. Additionally, you can see the configuration for the run which produced the artifact as well as the history metrics at the time of logging the artifact.
Usage panel
The Usage panel provides a code snippet for downloading the artifact for use outside of the web app, for example on a local machine. This section also indicates and links to the run which output the artifact and any runs which use the artifact as an input.
Files panel
The files panel lists the files and folders associated with the artifact. W&B uploads certain files for a run automatically. For example, requirements.txt shows the versions of each library the run used, and wandb-metadata.json, and wandb-summary.json include information about the run. Other files may be uploaded, such as artifacts or media, depending on the run’s configuration. You can navigate through this file tree and view the contents directly in the W&B web app.
Tables associated with artifacts are particularly rich and interactive in this context. Learn more about using Tables with Artifacts here.
Lineage panel
The lineage panel provides a view of all of the artifacts associated with a project and the runs that connect them to each other. It shows run types as blocks and artifacts as circles, with arrows to indicate when a run of a given type consumes or produces an artifact of a given type. The type of the particular artifact selected in the left-hand column is highlighted.
Click the Explode toggle to view all of the individual artifact versions and the specific runs that connect them.
Action History Audit tab
The action history audit tab shows all of the alias actions and membership changes for a Collection so you can audit the entire evolution of the resource.
Versions tab
The versions tab shows all versions of the artifact as well as columns for each of the numeric values of the Run History at the time of logging the version. This allows you to compare performance and quickly identify versions of interest.
Star a project
Add a star to a project to mark that project as important. Projects that you and your team mark as important with stars appear at the top of your organization’s home page.
For example, the proceeding image shows two projects that are marked as important, the zoo_experiment and registry_demo. Both projects appear within the top of the organization’s home page within the Starred projects section.
There are two ways to mark a project as important: within a project’s overview tab or within your team’s profile page.
Navigate to your W&B project on the W&B App at https://wandb.ai/<team>/<project-name>.
Select the Overview tab from the project sidebar.
Choose the star icon in the upper right corner next to the Edit button.
Navigate to your team’s profile page at https://wandb.ai/<team>/projects.
Select the Projects tab.
Hover your mouse next to the project you want to star. Click on star icon that appears.
For example, the proceeding image shows the star icon next to the “Compare_Zoo_Models” project.
Confirm that your project appears on the landing page of your organization by clicking on the organization name in the top left corner of the app.
Delete a project
You can delete your project by clicking the three dots on the right of the overview tab.
If the project is empty, you can delete it by clicking the dropdown menu in the top-right and selecting Delete project.
Add notes to a project
Add notes to your project either as a description overview or as a markdown panel within your workspace.
Add description overview to a project
Descriptions you add to your page appear in the Overview tab of your profile.
Navigate to your W&B project
Select the Overview tab from the project sidebar
Choose Edit in the upper right hand corner
Add your notes in the Description field
Select the Save button
Create reports to create descriptive notes comparing runs
You can also create a W&B Report to add plots and markdown side by side. Use different sections to show different runs, and tell a story about what you worked on.
Add notes to run workspace
Navigate to your W&B project
Select the Workspace tab from the project sidebar
Choose the Add panels button from the top right corner
Select the TEXT AND CODE dropdown from the modal that appears
Select Markdown
Add your notes in the markdown panel that appears in your workspace
1.4 - View experiments results
A playground for exploring run data with interactive visualizations
W&B workspace is your personal sandbox to customize charts and explore model results. A W&B workspace consists of Tables and Panel sections:
Tables: All runs logged to your project are listed in the project’s table. Turn on and off runs, change colors, and expand the table to see notes, config, and summary metrics for each run.
Panel sections: A section that contains one or more panels. Create new panels, organize them, and export to reports to save snapshots of your workspace.
Workspace types
There are two main workspace categories: Personal workspaces and Saved views.
Personal workspaces: A customizable workspace for in-depth analysis of models and data visualizations. Only the owner of the workspace can edit and save changes. Teammates can view a personal workspace but teammates can not make changes to someone else’s personal workspace.
Saved views: Saved views are collaborative snapshots of a workspace. Anyone on your team can view, edit, and save changes to saved workspace views. Use saved workspace views for reviewing and discussing experiments, runs, and more.
The proceeding image shows multiple personal workspaces created by Cécile-parker’s teammates. In this project, there are no saved views:
Saved workspace views
Improve team collaboration with tailored workspace views. Create Saved Views to organize your preferred setup of charts and data.
Create a new saved workspace view
Navigate to a personal workspace or a saved view.
Make edits to the workspace.
Click on the meatball menu (three horizontal dots) at the top right corner of your workspace. Click on Save as a new view.
New saved views appear in the workspace navigation menu.
Update a saved workspace view
Saved changes overwrite the previous state of the saved view. Unsaved changes are not retained. To update a saved workspace view in W&B:
Navigate to a saved view.
Make the desired changes to your charts and data within the workspace.
Click the Save button to confirm your changes.
A confirmation dialog appears when you save your updates to a workspace view. If you prefer not to see this prompt in the future, select the option Do not show this modal next time before confirming your save.
Delete a saved workspace view
Remove saved views that are no longer needed.
Navigate to the saved view you want to remove.
Select the three horizontal lines (…) at the top right of the view.
Choose Delete view.
Confirm the deletion to remove the view from your workspace menu.
Share a workspace view
Share your customized workspace with your team by sharing the workspace URL directly. All users with access to the workspace project can see the saved Views of that workspace.
Programmatically creating workspaces
wandb-workspaces is a Python library for programmatically working with W&B workspaces and reports.
Define a workspace programmatically with wandb-workspaces. wandb-workspaces is a Python library for programmatically working with W&B workspaces and reports.
You can define the workspace’s properties, such as:
Set panel layouts, colors, and section orders.
Configure workspace settings like default x-axis, section order, and collapse states.
Add and customize panels within sections to organize workspace views.
Load and modify existing workspaces using a URL.
Save changes to existing workspaces or save as new views.
Filter, group, and sort runs programmatically using simple expressions.
Customize run appearance with settings like colors and visibility.
Copy views from one workspace to another for integration and reuse.
Install Workspace API
In addition to wandb, ensure that you install wandb-workspaces:
pip install wandb wandb-workspaces
Define and save a workspace view programmatically
import wandb_workspaces.reports.v2 as wr
workspace = ws.Workspace(entity="your-entity", project="your-project", views=[...])
workspace.save()
Learn about the basic building block of W&B, Runs.
A run is a single unit of computation logged by W&B. You can think of a W&B run as an atomic element of your whole project. In other words, each run is a record of a specific computation, such as training a model and logging the results, hyperparameter sweeps, and so forth.
Common patterns for initiating a run include, but are not limited to:
Training a model
Changing a hyperparameter and conducting a new experiment
Conducting a new machine learning experiment with a different model
W&B stores runs that you create into projects. You can view runs and their properties within the run’s project workspace on the W&B App UI. You can also programmatically access run properties with the wandb.Api.Run object.
Anything you log with run.log is recorded in that run. Consider the proceeding code snippet.
import wandb
run = wandb.init(entity="nico", project="awesome-project")
run.log({"accuracy": 0.9, "loss": 0.1})
The first line imports the W&B Python SDK. The second line initializes a run in the project awesome-project under the entity nico. The third line logs the accuracy and loss of the model to that run.
Within the terminal, W&B returns:
wandb: Syncing run earnest-sunset-1
wandb: ⭐️ View project at https://wandb.ai/nico/awesome-project
wandb: 🚀 View run at https://wandb.ai/nico/awesome-project/runs/1jx1ud12
wandb:
wandb:
wandb: Run history:
wandb: accuracy ▁
wandb: loss ▁
wandb:
wandb: Run summary:
wandb: accuracy 0.9
wandb: loss 0.5
wandb:
wandb: 🚀 View run earnest-sunset-1 at: https://wandb.ai/nico/awesome-project/runs/1jx1ud12
wandb: ⭐️ View project at: https://wandb.ai/nico/awesome-project
wandb: Synced 6 W&B file(s), 0 media file(s), 0 artifact file(s) and 0 other file(s)wandb: Find logs at: ./wandb/run-20241105_111006-1jx1ud12/logs
The URL W&B returns in the terminal to redirects you to the run’s workspace in the W&B App UI. Note that the panels generated in the workspace corresponds to the single point.
Logging a metrics at a single point of time might not be that useful. A more realistic example in the case of training discriminative models is to log metrics at regular intervals. For example, consider the proceeding code snippet:
The training script calls run.log 10 times. Each time the script calls run.log, W&B logs the accuracy and loss for that epoch. Selecting the URL that W&B prints from the preceding output, directs you to the run’s workspace in the W&B App UI.
Note that W&B captures the simulated training loop within a single run called jolly-haze-4. This is because the script calls wandb.init method only once.
As another example, during a sweep, W&B explores a hyperparameter search space that you specify. W&B implements each new hyperparameter combination that the sweep creates as a unique run.
Initialize a run
Initialize a W&B run with wandb.init(). The proceeding code snippet shows how to import the W&B Python SDK and initialize a run.
Ensure to replace values enclosed in angle brackets (< >) with your own values:
import wandb
run = wandb.init(entity="<entity>", project="<project>")
When you initialize a run, W&B logs your run to the project you specify for the project field (wandb.init(project="<project>"). W&B creates a new project if the project does not already exist. If the project already exists, W&B stores the run in that project.
If you do not specify a project name, W&B stores the run in a project called Uncategorized.
For example, consider the proceeding code snippet:
import wandb
run = wandb.init(entity="wandbee", project="awesome-project")
The code snippet produces the proceeding output:
🚀 View run exalted-darkness-6 at:
https://wandb.ai/nico/awesome-project/runs/pgbn9y21
Find logs at: wandb/run-20241106_090747-pgbn9y21/logs
Since the preceding code did not specify an argument for the id parameter, W&B creates a unique run ID. Where nico is the entity that logged the run, awesome-project is the name of the project the run is logged to, exalted-darkness-6 is the name of the run, and pgbn9y21 is the run ID.
Notebook users
Specify run.finish() at the end of your run to mark the run finished. This helps ensure that the run is properly logged to your project and does not continue in the background.
import wandb
run = wandb.init(entity="<entity>", project="<project>")
# Training code, logging, and so forthrun.finish()
Each run has a state that describes the current status of the run. See Run states for a full list of possible run states.
Run states
The proceeding table describes the possible states a run can be in:
State
Description
Finished
Run ended and fully synced data, or called wandb.finish()
Failed
Run ended with a non-zero exit status
Crashed
Run stopped sending heartbeats in the internal process, which can happen if the machine crashes
Running
Run is still running and has recently sent a heartbeat
If you do not specify a run ID when you initialize a run, W&B generates a random run ID for you. You can find the unique ID of a run in the W&B App UI.
Navigate to the W&B project you specified when you initialized the run.
Within your project’s workspace, select the Runs tab.
Select the Overview tab.
W&B displays the unique run ID in the Run path field. The run path consists of the name of your team, the name of the project, and the run ID. The unique ID is the last part of the run path.
For example, in the proceeding image, the unique run ID is 9mxi1arc:
Custom run IDs
You can specify your own run ID by passing the id parameter to the wandb.init method.
import wandb
run = wandb.init(entity="<project>", project="<project>", id="<run-id>")
You can use a run’s unique ID to directly navigate to the run’s overview page in the W&B App UI. The proceeding cell shows the URL path for a specific run:
https://wandb.ai/<entity>/<project>/<run-id>
Where values enclosed in angle brackets (< >) are placeholders for the actual values of the entity, project, and run ID.
Name your run
The name of a run is a human-readable, non-unique identifier.
By default, W&B generates a random run name when you initialize a new run. The name of a run appears within your project’s workspace and at the top of the run’s overview page.
Use run names as a way to quickly identify a run in your project workspace.
You can specify a name for your run by passing the name parameter to the wandb.init method.
import wandb
run = wandb.init(entity="<project>", project="<project>", name="<run-name>")
Add a note to a run
Notes that you add to a specific run appear on the run page in the Overview tab and in the table of runs on the project page.
Navigate to your W&B project
Select the Workspace tab from the project sidebar
Select the run you want to add a note to from the run selector
Choose the Overview tab
Select the pencil icon next to the Description field and add your notes
Stop a run
Stop a run from the W&B App or programmatically.
Navigate to the terminal or code editor where you initialized the run.
Press Ctrl+D to stop the run.
For example, following the preceding instructions, your terminal might looks similar to the following:
KeyboardInterrupt
wandb: 🚀 View run legendary-meadow-2 at: https://wandb.ai/nico/history-blaster-4/runs/o8sdbztv
wandb: Synced 5 W&B file(s), 0 media file(s), 0 artifact file(s) and 1 other file(s)wandb: Find logs at: ./wandb/run-20241106_095857-o8sdbztv/logs
Navigate to the W&B App UI to confirm the run is no longer active:
Navigate to the project that your run was logging to.
Select the name of the run.
You can find the name of the run that you stop from the output of your terminal or code editor. For example, in the preceding example, the name of the run is legendary-meadow-2.
3. Choose the **Overview** tab from the project sidebar.
Next to the State field, the run’s state changes from running to Killed.
Navigate to the project that your run is logging to.
Select the run you want to stop within the run selector.
Choose the Overview tab from the project sidebar.
Select the top button next to the State field.
Next to the State field, the run’s state changes from running to Killed.
See State fields for a full list of possible run states.
View logged runs
View a information about a specific run such as the state of the run, artifacts logged to the run, log files recorded during the run, and more.
Navigate to the W&B project you specified when you initialized the run.
Within the project sidebar, select the Workspace tab.
Within the run selector, click the run you want to view, or enter a partial run name to filter for matching runs.
By default, long run names are truncated in the middle for readability. To truncate run names at the beginning or end instead, click the action ... menu at the top of the list of runs, then set Run name cropping to crop the end, middle, or beginning.
Note that the URL path of a specific run has the proceeding format:
Where values enclosed in angle brackets (< >) are placeholders for the actual values of the team name, project name, and run ID.
Overview tab
Use the Overview tab to learn about specific run information in a project, such as:
Author: The W&B entity that creates the run.
Command: The command that initializes the run.
Description: A description of the run that you provided. This field is empty if you do not specify a description when you create the run. You can add a description to a run with the W&B App UI or programmatically with the Python SDK.
Duration: The amount of time the run is actively computing or logging data, excluding any pauses or waiting.
Git repository: The git repository associated with the run. You must enable git to view this field.
Host name: Where W&B computes the run. W&B displays the name of your machine if you initialize the run locally on your machine.
Name: The name of the run.
OS: Operating system that initializes the run.
Python executable: The command that starts the run.
Python version: Specifies the Python version that creates the run.
Run path: Identifies the unique run identifier in the form entity/project/run-ID.
Runtime: Measures the total time from the start to the end of the run. It’s the wall-clock time for the run. Runtime includes any time where the run is paused or waiting for resources, while duration does not.
Start time: The timestamp when you initialize the run.
Use the Runs tab to filter, group, and sort your runs.
The proceeding tabs demonstrate some common actions you can take in the Runs tab.
The Runs tab shows details about runs in the project. It shows a large number of columns by default.
To view all visible columns, scroll the page horizontally.
To change the order of the columns, drag a column to the left or right.
To pin a column, hover over the column name, click the action menu .... that appears, then click Pin column. Pinned columns appear near the left of the page, after the Name column. To unpin a pinned column, choose Unpin column
To hide a column, hover over the column name, click the action menu .... that appears, then click Hide column. To view all columns that are currently hidden, click Columns.
To show, hide, pin, and unpin multiple columns at once, click Columns.
Click the name of a hidden column to unhide it.
Click the name of a visible column to hide it.
Click the pin icon next to a visible column to pin it.
When you customize the Runs tab, the customization is also reflected in the Runs selector of the Workspace tab.
Sort all rows in a Table by the value in a given column.
Hover your mouse over the column title. A kebob menu will appear (three vertical docs).
Select on the kebob menu (three vertical dots).
Choose Sort Asc or Sort Desc to sort the rows in ascending or descending order, respectively.
The preceding image demonstrates how to view sorting options for a Table column called val_acc.
Filter all rows by an expression with the Filter button above the dashboard.
Select Add filter to add one or more filters to your rows. Three dropdown menus will appear. From left to right the filter types are based on: Column name, Operator , and Values
Column name
Binary relation
Value
Accepted values
String
=, ≠, ≤, ≥, IN, NOT IN,
Integer, float, string, timestamp, null
The expression editor shows a list of options for each term using autocomplete on column names and logical predicate structure. You can connect multiple logical predicates into one expression using “and” or “or” (and sometimes parentheses).
The preceding image shows a filter that is based on the `val_loss` column. The filter shows runs with a validation loss less than or equal to 1.
Group all rows by the value in a particular column with the Group by button above the dashboard.
By default, this turns other numeric columns into histograms showing the distribution of values for that column across the group. Grouping is helpful for understanding higher-level patterns in your data.
System tab
The System tab shows system metrics tracked for a specific run such as CPU utilization, system memory, disk I/O, network traffic, GPU utilization and more.
For a full list of system metrics W&B tracks, see System metrics.
Delete one or more runs from a project with the W&B App.
Navigate to the project that contains the runs you want to delete.
Select the Runs tab from the project sidebar.
Select the checkbox next to the runs you want to delete.
Choose the Delete button (trash can icon) above the table.
From the modal that appears, choose Delete.
Once a run with a specific ID is deleted, its ID may not be used again. Trying to initiate a run with a previously deleted ID will show an error and prevent initiation.
For projects that contain a large number of runs, you can use either the search bar to filter runs you want to delete using Regex or the filter button to filter runs based on their status, tags, or other properties.
Organize runs
This section provides instructions on how to organize runs using groups and job types. By assigning runs to groups (for example, experiment names) and specifying job types (for example, preprocessing, training, evaluation, debugging), you can streamline your workflow and improve model comparison.
Assign a group or job type to a run
Each run in W&B can be categorized by group and a job type:
Group: a broad category for the experiment, used to organize and filter runs.
Job type: the function of the run, such as preprocessing, training, or evaluation.
The proceeding example workspace, trains a baseline model using increasing amounts of data from the Fashion-MNIST dataset. The workspace uses colorts to represent the amount of data used:
Yellow to dark green indicate increasing amounts of data for the baseline model.
Light blue to violet to magenta indicate amounts of data for a more complex “double” model with additional parameters.
Use W&B’s filtering options and search bar to compare runs based on specific conditions, such as:
Training on the same dataset.
Evaluating on the same test set.
When you apply filters, the Table view is updated automatically. This allows you to identify performance differences between models, such as determining which classes are significantly more challenging for one model compared to another.
1.5.1 - Add labels to runs with tags
Add tags to label runs with particular features that might not be obvious from the logged metrics or artifact data.
For example, you can add a tag to a run to indicated that run’s model is in_production, that run is preemptible, this run represents the baseline, and so forth.
Add tags to one or more runs
Programmatically or interactively add tags to your runs.
Based on your use case, select the tab below that best fits your needs:
You can add tags to a run when it is created:
import wandb
run = wandb.init(
entity="entity",
project="<project-name>",
tags=["tag1", "tag2"]
)
You can also update the tags after you initialize a run. For example, the proceeding code snippet shows how to update a tag if a particular metrics crosses a pre-defined threshold:
After you create a run, you can update tags using the Public API. For example:
run = wandb.Api().run("{entity}/{project}/{run-id}")
run.tags.append("tag1") # you can choose tags based on run data hererun.update()
This method is best suited to tagging large numbers of runs with the same tag or tags.
Navigate to your project workspace.
Select Runs in the from the project sidebar.
Select one or more runs from the table.
Once you select one or more runs, select the Tag button above the table.
Type the tag you want to add and select the Create new tag checkbox to add the tag.
This method is best suited to applying a tag or tags to a single run manually.
Navigate to your project workspace.
Select a run from the list of runs within your project’s workspace.
Select Overview from the project sidebar.
Select the gray plus icon (+) button next to Tags.
Type a tag you want to add and select Add below the text box to add a new tag.
Remove tags from one or more runs
Tags can also be removed from runs with the W&B App UI.
This method is best suited to removing tags from a large numbers of runs.
In the Run sidebar of the project, select the table icon in the upper-right. This will expand the sidebar into the full runs table.
Hover over a run in the table to see a checkbox on the left or look in the header row for a checkbox to select all runs.
Select the checkbox to enable bulk actions.
Select the runs you want to remove tags.
Select the Tag button above the rows of runs.
Select the checkbox next to a tag to remove it from the run.
In the left sidebar of the Run page, select the top Overview tab. The tags on the run are visible here.
Hover over a tag and select the “x” to remove it from the run.
1.5.2 - Filter and search runs
How to use the sidebar and table on the project page
Use your project page to gain insights from runs logged to W&B. You can filter and search runs from both the Workspace page and the Runs page.
Filter runs
Filter runs based on their status, tags, or other properties with the filter button.
Filter runs with tags
Filter runs based on their tags with the filter button.
Filter runs with regex
If regex doesn’t provide you the desired results, you can make use of tags to filter out the runs in Runs Table. Tags can be added either on run creation or after they’re finished. Once the tags are added to a run, you can add a tag filter as shown in the gif below.
Search runs
Use regex to find runs with the regex you specify. When you type a query in the search box, that will filter down the visible runs in the graphs on the workspace as well as filtering the rows of the table.
Group runs
To group runs by one or more columns (including hidden columns):
Below the search box, click the Group button, which looks like a lined sheet of paper.
Select one or more columns to group results by.
Each set of grouped runs is collapsed by default. To expand it, click the arrow next to the group name.
Sort runs by minimum and maximum values
Sort the runs table by the minimum or maximum value of a logged metric. This is particularly useful if you want to view the best (or worst) recorded value.
The following steps describe how to sort the run table by a specific metric based on the minimum or maximum recorded value:
Hover your mouse over the column with the metric you want to sort with.
Select the kebob menu (three vertical lines).
From the dropdown, select either Show min or Show max.
From the same dropdown, select Sort by asc or Sort by desc to sort in ascending or descending order, respectively.
Search End Time for runs
We provide a column named End Time that logs that last heartbeat from the client process. The field is hidden by default.
Export runs table to CSV
Export the table of all your runs, hyperparameters, and summary metrics to a CSV with the download button.
1.5.3 - Fork a run
Forking a W&B run
The ability to fork a run is in private preview. Contact W&B Support at support@wandb.com to request access to this feature.
Use fork_from when you initialize a run with wandb.init() to “fork” from an existing W&B run. When you fork from a run, W&B creates a new run using the run ID and step of the source run.
Forking a run enables you to explore different parameters or models from a specific point in an experiment without impacting the original run.
Forking a run requires wandb SDK version >= 0.16.5
Forking a run requires monotonically increasing steps. You can not use non-monotonic steps defined with define_metric() to set a fork point because it would disrupt the essential chronological order of run history and system metrics.
Start a forked run
To fork a run, use the fork_from argument in wandb.init() and specify the source run ID and the step from the source run to fork from:
import wandb
# Initialize a run to be forked lateroriginal_run = wandb.init(project="your_project_name", entity="your_entity_name")
# ... perform training or logging ...original_run.finish()
# Fork the run from a specific stepforked_run = wandb.init(
project="your_project_name",
entity="your_entity_name",
fork_from=f"{original_run.id}?_step=200",
)
Using an immutable run ID
Use an immutable run ID to ensure you have a consistent and unchanging reference to a specific run. Follow these steps to obtain the immutable run ID from the user interface:
Access the Overview Tab: Navigate to the Overview tab on the source run’s page.
Copy the Immutable Run ID: Click on the ... menu (three dots) located in the top-right corner of the Overview tab. Select the Copy Immutable Run ID option from the dropdown menu.
By following these steps, you will have a stable and unchanging reference to the run, which can be used for forking a run.
Continue from a forked run
After initializing a forked run, you can continue logging to the new run. You can log the same metrics for continuity and introduce new metrics.
For example, the following code example shows how to first fork a run and then how to log metrics to the forked run starting from a training step of 200:
import wandb
import math
# Initialize the first run and log some metricsrun1 = wandb.init("your_project_name", entity="your_entity_name")
for i in range(300):
run1.log({"metric": i})
run1.finish()
# Fork from the first run at a specific step and log the metric starting from step 200run2 = wandb.init(
"your_project_name", entity="your_entity_name", fork_from=f"{run1.id}?_step=200")
# Continue logging in the new run# For the first few steps, log the metric as is from run1# After step 250, start logging the spikey patternfor i in range(200, 300):
if i <250:
run2.log({"metric": i}) # Continue logging from run1 without spikeselse:
# Introduce the spikey behavior starting from step 250 subtle_spike = i + (2* math.sin(i /3.0)) # Apply a subtle spikey pattern run2.log({"metric": subtle_spike})
# Additionally log the new metric at all steps run2.log({"additional_metric": i *1.1})
run2.finish()
Rewind and forking compatibility
Forking compliments a rewind by providing more flexibility in managing and experimenting with your runs.
When you fork from a run, W&B creates a new branch off a run at a specific point to try different parameters or models.
When you rewind a run, W&B let’s you correct or modify the run history itself.
1.5.4 - Group runs into experiments
Group training and evaluation runs into larger experiments
Group individual jobs into experiments by passing a unique group name to wandb.init().
Use cases
Distributed training: Use grouping if your experiments are split up into different pieces with separate training and evaluation scripts that should be viewed as parts of a larger whole.
Multiple processes: Group multiple smaller processes together into an experiment.
K-fold cross-validation: Group together runs with different random seeds to see a larger experiment. Here’s an example of k-fold cross-validation with sweeps and grouping.
There are three ways to set grouping:
1. Set group in your script
Pass an optional group and job_type to wandb.init(). This gives you a dedicated group page for each experiment, which contains the individual runs. For example:wandb.init(group="experiment_1", job_type="eval")
2. Set a group environment variable
Use WANDB_RUN_GROUP to specify a group for your runs as an environment variable. For more on this, check our docs for Environment Variables. Group should be unique within your project and shared by all runs in the group. You can use wandb.util.generate_id() to generate a unique 8 character string to use in all your processes— for example, os.environ["WANDB_RUN_GROUP"] = "experiment-" + wandb.util.generate_id()
3. Toggle grouping in the UI
You can dynamically group by any config column. For example, if you use wandb.config to log batch size or learning rate, you can then group by those hyperparameters dynamically in the web app.
Distributed training with grouping
Suppose you set grouping in wandb.init(), we will group runs by default in the UI. You can toggle this on and off by clicking the Group button at the top of the table. Here’s an example project generated from sample code where we set grouping. You can click on each “Group” row in the sidebar to get to a dedicated group page for that experiment.
From the project page above, you can click a Group in the left sidebar to get to a dedicated page like this one:
Grouping dynamically in the UI
You can group runs by any column, for example by hyperparameter. Here’s an example of what that looks like:
Sidebar: Runs are grouped by the number of epochs.
Graphs: Each line represents the group’s mean, and the shading indicates the variance. This behavior can be changed in the graph settings.
Turn off grouping
Click the grouping button and clear group fields at any time, which returns the table and graphs to their ungrouped state.
Grouping graph settings
Click the edit button in the upper right corner of a graph and select the Advanced tab to change the line and shading. You can select the mean, minimum, or maximum value for the line in each group. For the shading, you can turn off shading, and show the min and max, the standard deviation, and the standard error.
1.5.5 - Move runs
This page shows how to move a run from one project to another, into or out of a team, or from one team to another. You must have access to the run at its current and new locations.
When you move a run, historical artifacts associated with it are not moved. To move an artifact manually, you can use the wandb artifact get SDK command or the Api.artifact API to download the artifact, then use wandb artifact put or the Api.artifact API to upload it to the run’s new location.
Navigate to the project that contains the runs you want to move.
Select the Runs tab from the project sidebar.
Select the checkbox next to the runs you want to move.
Choose the Move button above the table.
Select the destination project from the dropdown.
Move runs to a team
Move runs to a team you are a member of:
Navigate to the project that contains the runs you want to move.
Select the Runs tab from the project sidebar.
Select the checkbox next to the runs you want to move.
Choose the Move button above the table.
Select the destination team and project from the dropdown.
1.5.6 - Resume a run
Resume a paused or exited W&B Run
Specify how a run should behave in the event that run stops or crashes. To resume or enable a run to automatically resume, you will need to specify the unique run ID associated with that run for the id parameter:
run = wandb.init(entity="<entity>", \
project="<project>", id="<run ID>", resume="<resume>")
W&B encourages you to provide the name of the W&B Project where you want to store the run.
Pass one of the following arguments to the resume parameter to determine how W&B should respond. In each case, W&B first checks if the run ID already exists.
Argument
Description
Run ID exists
Run ID does not exist
Use case
"must"
W&B must resume run specified by the run ID.
W&B resumes run with the same run ID.
W&B raises an error.
Resume a run that must use the same run ID.
"allow"
Allow W&B to resume run if run ID exists.
W&B resumes run with the same run ID.
W&B initializes a new run with specified run ID.
Resume a run without overriding an existing run.
"never"
Never allow W&B to resume a run specified by run ID.
W&B raises an error.
W&B initializes a new run with specified run ID.
You can also specify resume="auto" to let W&B to automatically try to restart the run on your behalf. However, you will need to ensure that you restart your run from the same directory. See the Enable runs to automatically resume section for more information.
For all the examples below, replace values enclosed within <> with your own.
Resume a run that must use the same run ID
If a run is stopped, crashes, or fails, you can resume it using the same run ID. To do so, initialize a run and specify the following:
Set the resume parameter to "must" (resume="must")
Provide the run ID of the run that stopped or crashed
The following code snippet shows how to accomplish this with the W&B Python SDK:
run = wandb.init(entity="<entity>", \
project="<project>", id="<run ID>", resume="must")
Unexpected results will occur if multiple processes use the same id concurrently.
Resume a run that stopped or crashed without overriding the existing run. This is especially helpful if your process doesn’t exit successfully. The next time you start W&B, W&B will start logging from the last step.
Set the resume parameter to "allow" (resume="allow") when you initialize a run with W&B. Provide the run ID of the run that stopped or crashed. The following code snippet shows how to accomplish this with the W&B Python SDK:
import wandb
run = wandb.init(entity="<entity>", \
project="<project>", id="<run ID>", resume="allow")
Enable runs to automatically resume
The following code snippet shows how to enable runs to automatically resume with the Python SDK or with environment variables.
The following code snippet shows how to specify a W&B run ID with the Python SDK.
Replace values enclosed within <> with your own:
run = wandb.init(entity="<entity>", \
project="<project>", id="<run ID>", resume="<resume>")
The following example shows how to specify the W&B WANDB_RUN_ID variable in a bash script:
Within your terminal, you could run the shell script along with the W&B run ID. The following code snippet passes the run ID akj172:
sh run_experiment.sh akj172
Automatic resuming only works if the process is restarted on top of the same filesystem as the failed process.
For example, suppose you execute a python script called train.py in a directory called Users/AwesomeEmployee/Desktop/ImageClassify/training/. Within train.py, the script creates a run that enables automatic resuming. Suppose next that the training script is stopped. To resume this run, you would need to restart your train.py script within Users/AwesomeEmployee/Desktop/ImageClassify/training/ .
If you can not share a filesystem, specify the WANDB_RUN_ID environment variable or pass the run ID with the W&B Python SDK. See the Custom run IDs section in the “What are runs?” page for more information on run IDs.
Resume preemptible Sweeps runs
Automatically requeue interrupted sweep runs. This is particularly useful if you run a sweep agent in a compute environment that is subject to preemption such as a SLURM job in a preemptible queue, an EC2 spot instance, or a Google Cloud preemptible VM.
Use the mark_preempting function to enable W&B to automatically requeue interrupted sweep runs. For example, the following code snippet
run = wandb.init() # Initialize a runrun.mark_preempting()
The following table outlines how W&B handles runs based on the exit status of the a sweep run.
Status
Behavior
Status code 0
Run is considered to have terminated successfully and it will not be requeued.
Nonzero status
W&B automatically appends the run to a run queue associated with the sweep.
No status
Run is added to the sweep run queue. Sweep agents consume runs off the run queue until the queue is empty. Once the queue is empty, the sweep queue resumes generating new runs based on the sweep search algorithm.
1.5.7 - Rewind a run
Rewind
Rewind a run
The option to rewind a run is in private preview. Contact W&B Support at support@wandb.com to request access to this feature.
W&B currently does not support:
Log rewind: Logs are reset in the new run segment.
System metrics rewind: W&B logs only new system metrics after the rewind point.
Artifact association: W&B associates artifacts with the source run that produces them.
To rewind a run, you must have W&B Python SDK version >= 0.17.1.
You must use monotonically increasing steps. You can not use non-monotonic steps defined with define_metric() because it disrupts the required chronological order of run history and system metrics.
Rewind a run to correct or modify the history of a run without losing the original data. In addition, when you
rewind a run, you can log new data from that point in time. W&B recomputes the summary metrics for the run you rewind based on the newly logged history. This means the following behavior:
History truncation: W&B truncates the history to the rewind point, allowing new data logging.
Summary metrics: Recomputed based on the newly logged history.
Configuration preservation: W&B preserves the original configurations and you can merge new configurations.
When you rewind a run, W&B resets the state of the run to the specified step, preserving the original data and maintaining a consistent run ID. This means that:
Run archiving: W&B archives the original runs. Runs are accessible from the Run Overview tab.
Artifact association: Associates artifacts with the run that produce them.
Immutable run IDs: Introduced for consistent forking from a precise state.
Copy immutable run ID: A button to copy the immutable run ID for improved run management.
Rewind and forking compatibility
Forking compliments a rewind.
When you fork from a run, W&B creates a new branch off a run at a specific point to try different parameters or models.
When you rewind a run, W&B lets you correct or modify the run history itself.
Rewind a run
Use resume_from with wandb.init() to “rewind” a run’s history to a specific step. Specify the name of the run and the step you want to rewind from:
import wandb
import math
# Initialize the first run and log some metrics# Replace with your_project_name and your_entity_name!run1 = wandb.init(project="your_project_name", entity="your_entity_name")
for i in range(300):
run1.log({"metric": i})
run1.finish()
# Rewind from the first run at a specific step and log the metric starting from step 200run2 = wandb.init(project="your_project_name", entity="your_entity_name", resume_from=f"{run1.id}?_step=200")
# Continue logging in the new run# For the first few steps, log the metric as is from run1# After step 250, start logging the spikey patternfor i in range(200, 300):
if i <250:
run2.log({"metric": i, "step": i}) # Continue logging from run1 without spikeselse:
# Introduce the spikey behavior starting from step 250 subtle_spike = i + (2* math.sin(i /3.0)) # Apply a subtle spikey pattern run2.log({"metric": subtle_spike, "step": i})
# Additionally log the new metric at all steps run2.log({"additional_metric": i *1.1, "step": i})
run2.finish()
View an archived run
After you rewind a run, you can explore archived run with the W&B App UI. Follow these steps to view archived runs:
Access the Overview Tab: Navigate to the Overview tab on the run’s page. This tab provides a comprehensive view of the run’s details and history.
Locate the Forked From field: Within the Overview tab, find the Forked From field. This field captures the history of the resumptions. The Forked From field includes a link to the source run, allowing you to trace back to the original run and understand the entire rewind history.
By using the Forked From field, you can effortlessly navigate the tree of archived resumptions and gain insights into the sequence and origin of each rewind.
Fork from a run that you rewind
To fork from a rewound run, use the fork_from argument in wandb.init() and specify the source run ID and the step from the source run to fork from:
import wandb
# Fork the run from a specific stepforked_run = wandb.init(
project="your_project_name",
entity="your_entity_name",
fork_from=f"{rewind_run.id}?_step=500",
)
# Continue logging in the new runfor i in range(500, 1000):
forked_run.log({"metric": i*3})
forked_run.finish()
1.5.8 - Send an alert
Send alerts, triggered from your Python code, to your Slack or email
Create alerts with Slack or email if your run crashes or with a custom trigger. For example, you can create an alert if the gradient of your training loop starts to blow up (reports NaN) or a step in your ML pipeline completes. Alerts apply to all projects where you initialize runs, including both personal and team projects.
And then see W&B Alerts messages in Slack (or your email):
How to create an alert
The following guide only applies to alerts in multi-tenant cloud.
If you’re using W&B Server in your Private Cloud or on W&B Dedicated Cloud, then please refer to this documentation to setup Slack alerts.
Turn on Scriptable run alerts to receive alerts from run.alert()
Use Connect Slack to pick a Slack channel to post alerts. We recommend the Slackbot channel because it keeps the alerts private.
Email will go to the email address you used when you signed up for W&B. We recommend setting up a filter in your email so all these alerts go into a folder and don’t fill up your inbox.
You will only have to do this the first time you set up W&B Alerts, or when you’d like to modify how you receive alerts.
2. Add run.alert() to your code
Add run.alert() to your code (either in a Notebook or Python script) wherever you’d like it to be triggered
import wandb
run = wandb.init()
run.alert(title="High Loss", text="Loss is increasing rapidly")
3. Check your Slack or email
Check your Slack or emails for the alert message. If you didn’t receive any, make sure you’ve got emails or Slack turned on for Scriptable Alerts in your User Settings
Example
This simple alert sends a warning when accuracy falls below a threshold. In this example, it only sends alerts at least 5 minutes apart.
import wandb
from wandb import AlertLevel
run = wandb.init()
if acc < threshold:
run.alert(
title="Low accuracy",
text=f"Accuracy {acc} is below the acceptable threshold {threshold}",
level=AlertLevel.WARN,
wait_duration=300,
)
How to tag or mention users
Use the at sign @ followed by the Slack user ID to tag yourself or your colleagues in either the title or the text of the alert. You can find a Slack user ID from their Slack profile page.
run.alert(title="Loss is NaN", text=f"Hey <@U1234ABCD> loss has gone to NaN")
Team alerts
Team admins can set up alerts for the team on the team settings page: wandb.ai/teams/your-team.
Team alerts apply to everyone on your team. W&B recommends using the Slackbot channel because it keeps alerts private.
Change Slack channel to send alerts to
To change what channel alerts are sent to, click Disconnect Slack and then reconnect. After you reconnect, pick a different Slack channel.
1.6 - Log objects and media
Keep track of metrics, videos, custom plots, and more
Log a dictionary of metrics, media, or custom objects to a step with the W&B Python SDK. W&B collects the key-value pairs during each step and stores them in one unified dictionary each time you log data with wandb.log(). Data logged from your script is saved locally to your machine in a directory called wandb, then synced to the W&B cloud or your private server.
Key-value pairs are stored in one unified dictionary only if you pass the same value for each step. W&B writes all of the collected keys and values to memory if you log a different value for step.
Each call to wandb.log is a new step by default. W&B uses steps as the default x-axis when it creates charts and panels. You can optionally create and use a custom x-axis or capture a custom summary metric. For more information, see Customize log axes.
Use wandb.log() to log consecutive values for each step: 0, 1, 2, and so on. It is not possible to write to a specific history step. W&B only writes to the “current” and “next” step.
Automatically logged data
W&B automatically logs the following information during a W&B Experiment:
System metrics: CPU and GPU utilization, network, etc. These are shown in the System tab on the run page. For the GPU, these are fetched with nvidia-smi.
Command line: The stdout and stderr are picked up and show in the logs tab on the run page.
Git commit: Pick up the latest git commit and see it on the overview tab of the run page, as well as a diff.patch file if there are any uncommitted changes.
Dependencies: The requirements.txt file will be uploaded and shown on the files tab of the run page, along with any files you save to the wandb directory for the run.
What data is logged with specific W&B API calls?
With W&B, you can decide exactly what you want to log. The following lists some commonly logged objects:
Datasets: You have to specifically log images or other dataset samples for them to stream to W&B.
Plots: Use wandb.plot with wandb.log to track charts. See Log Plots for more information.
Tables: Use wandb.Table to log data to visualize and query with W&B. See Log Tables for more information.
PyTorch gradients: Add wandb.watch(model) to see gradients of the weights as histograms in the UI.
Configuration information: Log hyperparameters, a link to your dataset, or the name of the architecture you’re using as config parameters, passed in like this: wandb.init(config=your_config_dictionary). See the PyTorch Integrations page for more information.
Metrics: Use wandb.log to see metrics from your model. If you log metrics like accuracy and loss from inside your training loop, you’ll get live updating graphs in the UI.
Common workflows
Compare the best accuracy: To compare the best value of a metric across runs, set the summary value for that metric. By default, summary is set to the last value you logged for each key. This is useful in the table in the UI, where you can sort and filter runs based on their summary metrics, to help compare runs in a table or bar chart based on their best accuracy, instead of final accuracy. For example: wandb.run.summary["best_accuracy"] = best_accuracy
View multiple metrics on one chart: Log multiple metrics in the same call to wandb.log, like this: wandb.log({"acc'": 0.9, "loss": 0.1}) and they will both be available to plot against in the UI
Customize the x-axis: Add a custom x-axis to the same log call to visualize your metrics against a different axis in the W&B dashboard. For example: wandb.log({'acc': 0.9, 'epoch': 3, 'batch': 117}). To set the default x-axis for a given metric use Run.define_metric()
Create and track plots from machine learning experiments.
Using the methods in wandb.plot, you can track charts with wandb.log, including charts that change over time during training. To learn more about our custom charting framework, check out this guide.
Basic charts
These simple charts make it easy to construct basic visualizations of metrics and results.
wandb.plot.line()
Log a custom line plot—a list of connected and ordered points on arbitrary axes.
data = [[x, y] for (x, y) in zip(x_values, y_values)]
table = wandb.Table(data=data, columns=["x", "y"])
wandb.log(
{
"my_custom_plot_id": wandb.plot.line(
table, "x", "y", title="Custom Y vs X Line Plot" )
}
)
You can use this to log curves on any two dimensions. If you’re plotting two lists of values against each other, the number of values in the lists must match exactly. For example, each point must have an x and a y.
Log a custom scatter plot—a list of points (x, y) on a pair of arbitrary axes x and y.
data = [[x, y] for (x, y) in zip(class_x_scores, class_y_scores)]
table = wandb.Table(data=data, columns=["class_x", "class_y"])
wandb.log({"my_custom_id": wandb.plot.scatter(table, "class_x", "class_y")})
You can use this to log scatter points on any two dimensions. If you’re plotting two lists of values against each other, the number of values in the lists must match exactly. For example, each point must have an x and a y.
Log a custom histogram—sort a list of values into bins by count/frequency of occurrence—natively in a few lines. Let’s say I have a list of prediction confidence scores (scores) and want to visualize their distribution:
data = [[s] for s in scores]
table = wandb.Table(data=data, columns=["scores"])
wandb.log({"my_histogram": wandb.plot.histogram(table, "scores", title="Histogram")})
You can use this to log arbitrary histograms. Note that data is a list of lists, intended to support a 2D array of rows and columns.
Note that the number of x and y points must match exactly. You can supply one list of x values to match multiple lists of y values, or a separate list of x values for each list of y values.
These preset charts have built-in wandb.plot methods that make it quick and easy to log charts directly from your script and see the exact information you’re looking for in the UI.
cm = wandb.plot.confusion_matrix(
y_true=ground_truth, preds=predictions, class_names=class_names
)
wandb.log({"conf_mat": cm})
You can log this wherever your code has access to:
a model’s predicted labels on a set of examples (preds) or the normalized probability scores (probs). The probabilities must have the shape (number of examples, number of classes). You can supply either probabilities or predictions but not both.
the corresponding ground truth labels for those examples (y_true)
a full list of the labels/class names as strings of class_names. Examples: class_names=["cat", "dog", "bird"] if index 0 is cat, 1 is dog, 2 is bird.
For full customization, tweak a built-in Custom Chart preset or create a new preset, then save the chart. Use the chart ID to log data to that custom preset directly from your script.
# Create a table with the columns to plottable = wandb.Table(data=data, columns=["step", "height"])
# Map from the table's columns to the chart's fieldsfields = {"x": "step", "value": "height"}
# Use the table to populate the new custom chart preset# To use your own saved chart preset, change the vega_spec_name# To edit the title, change the string_fieldsmy_custom_chart = wandb.plot_table(
vega_spec_name="carey/new_chart",
data_table=table,
fields=fields,
string_fields={"title": "Height Histogram"},
)
Just pass a matplotlib plot or figure object to wandb.log(). By default we’ll convert the plot into a Plotly plot. If you’d rather log the plot as an image, you can pass the plot into wandb.Image. We also accept Plotly charts directly.
If you’re getting an error “You attempted to log an empty plot” then you can store the figure separately from the plot with fig = plt.figure() and then log fig in your call to wandb.log.
Log custom HTML to W&B Tables
W&B supports logging interactive charts from Plotly and Bokeh as HTML and adding them to Tables.
Log Plotly figures to Tables as HTML
You can log interactive Plotly charts to wandb Tables by converting them to HTML.
import wandb
import plotly.express as px
# Initialize a new runrun = wandb.init(project="log-plotly-fig-tables", name="plotly_html")
# Create a tabletable = wandb.Table(columns=["plotly_figure"])
# Create path for Plotly figurepath_to_plotly_html ="./plotly_figure.html"# Example Plotly figurefig = px.scatter(x=[0, 1, 2, 3, 4], y=[0, 1, 4, 9, 16])
# Write Plotly figure to HTML# Set auto_play to False prevents animated Plotly charts# from playing in the table automaticallyfig.write_html(path_to_plotly_html, auto_play=False)
# Add Plotly figure as HTML file into Tabletable.add_data(wandb.Html(path_to_plotly_html))
# Log Tablerun.log({"test_table": table})
wandb.finish()
Log Bokeh figures to Tables as HTML
You can log interactive Bokeh charts to wandb Tables by converting them to HTML.
Use define_metric to set a custom x axis.Custom x-axes are useful in contexts where you need to log to different time steps in the past during training, asynchronously. For example, this can be useful in RL where you may track the per-episode reward and a per-step reward.
By default, all metrics are logged against the same x-axis, which is the W&B internal step. Sometimes, you might want to log to a previous step, or use a different x-axis.
Here’s an example of setting a custom x-axis metric, instead of the default step.
import wandb
wandb.init()
# define our custom x axis metricwandb.define_metric("custom_step")
# define which metrics will be plotted against itwandb.define_metric("validation_loss", step_metric="custom_step")
for i in range(10):
log_dict = {
"train_loss": 1/ (i +1),
"custom_step": i**2,
"validation_loss": 1/ (i +1),
}
wandb.log(log_dict)
The x-axis can be set using globs as well. Currently, only globs that have string prefixes are available. The following example will plot all logged metrics with the prefix "train/" to the x-axis "train/step":
import wandb
wandb.init()
# define our custom x axis metricwandb.define_metric("train/step")
# set all other train/ metrics to use this stepwandb.define_metric("train/*", step_metric="train/step")
for i in range(10):
log_dict = {
"train/step": 2**i, # exponential growth w/ internal W&B step"train/loss": 1/ (i +1), # x-axis is train/step"train/accuracy": 1- (1/ (1+ i)), # x-axis is train/step"val/loss": 1/ (1+ i), # x-axis is internal wandb step }
wandb.log(log_dict)
1.6.3 - Log distributed training experiments
Use W&B to log distributed training experiments with multiple GPUs.
In distributed training, models are trained using multiple GPUs in parallel. W&B supports two patterns to track distributed training experiments:
One process: Initialize W&B (wandb.init) and log experiments (wandb.log) from a single process. This is a common solution for logging distributed training experiments with the PyTorch Distributed Data Parallel (DDP) Class. In some cases, users funnel data over from other processes using a multiprocessing queue (or another communication primitive) to the main logging process.
Many processes: Initialize W&B (wandb.init) and log experiments (wandb.log) in every process. Each process is effectively a separate experiment. Use the group parameter when you initialize W&B (wandb.init(group='group-name')) to define a shared experiment and group the logged values together in the W&B App UI.
The proceeding examples demonstrate how to track metrics with W&B using PyTorch DDP on two GPUs on a single machine. PyTorch DDP (DistributedDataParallel intorch.nn) is a popular library for distributed training. The basic principles apply to any distributed training setup, but the details of implementation may differ.
Explore the code behind these examples in the W&B GitHub examples repository here. Specifically, see the log-dpp.py Python script for information on how to implement one process and many process methods.
Method 1: One process
In this method we track only a rank 0 process. To implement this method, initialize W&B (wandb.init), commence a W&B Run, and log metrics (wandb.log) within the rank 0 process. This method is simple and robust, however, this method does not log model metrics from other processes (for example, loss values or inputs from their batches). System metrics, such as usage and memory, are still logged for all GPUs since that information is available to all processes.
Use this method to only track metrics available from a single process. Typical examples include GPU/CPU utilization, behavior on a shared validation set, gradients and parameters, and loss values on representative data examples.
Within our sample Python script (log-ddp.py), we check to see if the rank is 0. To do so, we first launch multiple processes with torch.distributed.launch. Next, we check the rank with the --local_rank command line argument. If the rank is set to 0, we set up wandb logging conditionally in the train() function. Within our Python script, we use the following check:
if __name__ =="__main__":
# Get args args = parse_args()
if args.local_rank ==0: # only on main process# Initialize wandb run run = wandb.init(
entity=args.entity,
project=args.project,
)
# Train model with DDP train(args, run)
else:
train(args)
Explore the W&B App UI to view an example dashboard of metrics tracked from a single process. The dashboard displays system metrics such as temperature and utilization, that were tracked for both GPUs.
However, the loss values as a function epoch and batch size were only logged from a single GPU.
Method 2: Many processes
In this method, we track each process in the job, calling wandb.init() and wandb.log() from each process separately. We suggest you call wandb.finish() at the end of training, to mark that the run has completed so that all processes exit properly.
This method makes more information accessible for logging. However, note that multiple W&B Runs are reported in the W&B App UI. It might be difficult to keep track of W&B Runs across multiple experiments. To mitigate this, provide a value to the group parameter when you initialize W&B to keep track of which W&B Run belongs to a given experiment. For more information about how to keep track of training and evaluation W&B Runs in experiments, see Group Runs.
Use this method if you want to track metrics from individual processes. Typical examples include the data and predictions on each node (for debugging data distribution) and metrics on individual batches outside of the main node. This method is not necessary to get system metrics from all nodes nor to get summary statistics available on the main node.
The following Python code snippet demonstrates how to set the group parameter when you initialize W&B:
if __name__ =="__main__":
# Get args args = parse_args()
# Initialize run run = wandb.init(
entity=args.entity,
project=args.project,
group="DDP", # all runs for the experiment in one group )
# Train model with DDP train(args, run)
Explore the W&B App UI to view an example dashboard of metrics tracked from multiple processes. Note that there are two W&B Runs grouped together in the left sidebar. Click on a group to view the dedicated group page for the experiment. The dedicated group page displays metrics from each process separately.
The preceding image demonstrates the W&B App UI dashboard. On the sidebar we see two experiments. One labeled ’null’ and a second (bound by a yellow box) called ‘DPP’. If you expand the group (select the Group dropdown) you will see the W&B Runs that are associated to that experiment.
Use W&B Service to avoid common distributed training issues
There are two common issues you might encounter when using W&B and distributed training:
Hanging at the beginning of training - A wandb process can hang if the wandb multiprocessing interferes with the multiprocessing from distributed training.
Hanging at the end of training - A training job might hang if the wandb process does not know when it needs to exit. Call the wandb.finish() API at the end of your Python script to tell W&B that the Run finished. The wandb.finish() API will finish uploading data and will cause W&B to exit.
We recommend using the wandb service to improve the reliability of your distributed jobs. Both of the preceding training issues are commonly found in versions of the W&B SDK where wandb service is unavailable.
Enable W&B Service
Depending on your version of the W&B SDK, you might already have W&B Service enabled by default.
W&B SDK 0.13.0 and above
W&B Service is enabled by default for versions of the W&B SDK 0.13.0 and above.
W&B SDK 0.12.5 and above
Modify your Python script to enable W&B Service for W&B SDK version 0.12.5 and above. Use the wandb.require method and pass the string "service" within your main function:
if __name__ =="__main__":
main()
defmain():
wandb.require("service")
# rest-of-your-script-goes-here
For optimal experience we do recommend you upgrade to the latest version.
W&B SDK 0.12.4 and below
Set the WANDB_START_METHOD environment variable to "thread" to use multithreading instead if you use a W&B SDK version 0.12.4 and below.
Example use cases for multiprocessing
The following code snippets demonstrate common methods for advanced distributed use cases.
Spawn process
Use the wandb.setup()method in your main function if you initiate a W&B Run in a spawned process:
import multiprocessing as mp
defdo_work(n):
run = wandb.init(config=dict(n=n))
run.log(dict(this=n * n))
defmain():
wandb.setup()
pool = mp.Pool(processes=4)
pool.map(do_work, range(4))
if __name__ =="__main__":
main()
Share a W&B Run
Pass a W&B Run object as an argument to share W&B Runs between processes:
defdo_work(run):
run.log(dict(this=1))
defmain():
run = wandb.init()
p = mp.Process(target=do_work, kwargs=dict(run=run))
p.start()
p.join()
if __name__ =="__main__":
main()
Note that we can not guarantee the logging order. Synchronization should be done by the author of the script.
1.6.4 - Log media and objects
Log rich media, from 3D point clouds and molecules to HTML and histograms
We support images, video, audio, and more. Log rich media to explore your results and visually compare your runs, models, and datasets. Read on for examples and how-to guides.
Looking for reference docs for our media types? You want this page.
In order to log media objects with the W&B SDK, you may need to install additional dependencies.
You can install these dependencies by running the following command:
pip install wandb[media]
Images
Log images to track inputs, outputs, filter weights, activations, and more.
Images can be logged directly from NumPy arrays, as PIL images, or from the filesystem.
Each time you log images from a step, we save them to show in the UI. Expand the image panel, and use the step slider to look at images from different steps. This makes it easy to compare how a model’s output changes during training.
It’s recommended to log fewer than 50 images per step to prevent logging from becoming a bottleneck during training and image loading from becoming a bottleneck when viewing results.
We assume the image is gray scale if the last dimension is 1, RGB if it’s 3, and RGBA if it’s 4. If the array contains floats, we convert them to integers between 0 and 255. If you want to normalize your images differently, you can specify the mode manually or just supply a PIL.Image, as described in the “Logging PIL Images” tab of this panel.
For full control over the conversion of arrays to images, construct the PIL.Image yourself and provide it directly.
images = [PIL.Image.fromarray(image) for image in image_array]
wandb.log({"examples": [wandb.Image(image) for image in images]})
For even more control, create images however you like, save them to disk, and provide a filepath.
im = PIL.fromarray(...)
rgb_im = im.convert("RGB")
rgb_im.save("myimage.jpg")
wandb.log({"example": wandb.Image("myimage.jpg")})
Image overlays
Log semantic segmentation masks and interact with them (altering opacity, viewing changes over time, and more) via the W&B UI.
To log an overlay, you’ll need to provide a dictionary with the following keys and values to the masks keyword argument of wandb.Image:
one of two keys representing the image mask:
"mask_data": a 2D NumPy array containing an integer class label for each pixel
"path": (string) a path to a saved image mask file
"class_labels": (optional) a dictionary mapping the integer class labels in the image mask to their readable class names
To log multiple masks, log a mask dictionary with multiple keys, as in the code snippet below.
To log a bounding box, you’ll need to provide a dictionary with the following keys and values to the boxes keyword argument of wandb.Image:
box_data: a list of dictionaries, one for each box. The box dictionary format is described below.
position: a dictionary representing the position and size of the box in one of two formats, as described below. Boxes need not all use the same format.
Option 1:{"minX", "maxX", "minY", "maxY"}. Provide a set of coordinates defining the upper and lower bounds of each box dimension.
Option 2:{"middle", "width", "height"}. Provide a set of coordinates specifying the middle coordinates as [x,y], and width and height as scalars.
class_id: an integer representing the class identity of the box. See class_labels key below.
scores: a dictionary of string labels and numeric values for scores. Can be used for filtering boxes in the UI.
domain: specify the units/format of the box coordinates. Set this to “pixel” if the box coordinates are expressed in pixel space, such as integers within the bounds of the image dimensions. By default, the domain is assumed to be a fraction/percentage of the image, expressed as a floating point number between 0 and 1.
box_caption: (optional) a string to be displayed as the label text on this box
class_labels: (optional) A dictionary mapping class_ids to strings. By default we will generate class labels class_0, class_1, etc.
Check out this example:
class_id_to_label = {
1: "car",
2: "road",
3: "building",
# ...}
img = wandb.Image(
image,
boxes={
"predictions": {
"box_data": [
{
# one box expressed in the default relative/fractional domain"position": {"minX": 0.1, "maxX": 0.2, "minY": 0.3, "maxY": 0.4},
"class_id": 2,
"box_caption": class_id_to_label[2],
"scores": {"acc": 0.1, "loss": 1.2},
# another box expressed in the pixel domain# (for illustration purposes only, all boxes are likely# to be in the same domain/format)"position": {"middle": [150, 20], "width": 68, "height": 112},
"domain": "pixel",
"class_id": 3,
"box_caption": "a building",
"scores": {"acc": 0.5, "loss": 0.7},
# ...# Log as many boxes an as needed }
],
"class_labels": class_id_to_label,
},
# Log each meaningful group of boxes with a unique key name"ground_truth": {
# ... },
},
)
wandb.log({"driving_scene": img})
Image overlays in Tables
To log Segmentation Masks in tables, you will need to provide a wandb.Image object for each row in the table.
If a sequence of numbers, such as a list, array, or tensor, is provided as the first argument, we will construct the histogram automatically by calling np.histogram. All arrays/tensors are flattened. You can use the optional num_bins keyword argument to override the default of 64 bins. The maximum number of bins supported is 512.
In the UI, histograms are plotted with the training step on the x-axis, the metric value on the y-axis, and the count represented by color, to ease comparison of histograms logged throughout training. See the “Histograms in Summary” tab of this panel for details on logging one-off histograms.
wandb.log({"gradients": wandb.Histogram(grads)})
If you want more control, call np.histogram and pass the returned tuple to the np_histogram keyword argument.
If histograms are in your summary they will appear on the Overview tab of the Run Page. If they are in your history, we plot a heatmap of bins over time on the Charts tab.
3D visualizations
Log 3D point clouds and Lidar scenes with bounding boxes. Pass in a NumPy array containing coordinates and colors for the points to render.
boxes is a NumPy array of python dictionaries with three attributes:
corners- a list of eight corners
label- a string representing the label to be rendered on the box (Optional)
color- rgb values representing the color of the box
score - a numeric value that will be displayed on the bounding box that can be used to filter the bounding boxes shown (for example, to only show bounding boxes where score > 0.75). (Optional)
type is a string representing the scene type to render. Currently the only supported value is lidar/beta
Now you can view videos in the media browser. Go to your project workspace, run workspace, or report and click Add visualization to add a rich media panel.
2D view of a molecule
You can log a 2D view of a molecule using the wandb.Image data type and rdkit:
If a numpy array is supplied we assume the dimensions are, in order: time, channels, width, height. By default we create a 4 fps gif image (ffmpeg and the moviepy python library are required when passing numpy objects). Supported formats are "gif", "mp4", "webm", and "ogg". If you pass a string to wandb.Video we assert the file exists and is a supported format before uploading to wandb. Passing a BytesIO object will create a temporary file with the specified format as the extension.
On the W&B Run and Project Pages, you will see your videos in the Media section.
Use wandb.Table to log text in tables to show up in the UI. By default, the column headers are ["Input", "Output", "Expected"]. To ensure optimal UI performance, the default maximum number of rows is set to 10,000. However, users can explicitly override the maximum with wandb.Table.MAX_ROWS = {DESIRED_MAX}.
Custom HTML can be logged at any key, and this exposes an HTML panel on the run page. By default, we inject default styles; you can turn off default styles by passing inject=False.
The following guide describes how to log models to a W&B run and interact with them.
The following APIs are useful for tracking models as a part of your experiment tracking workflow. Use the APIs listed on this page to log models to a run, and to access metrics, tables, media, and other objects.
W&B suggests that you use W&B Artifacts if you want to:
Create and keep track of different versions of serialized data besides models, such as datasets, prompts, and more.
Explore lineage graphs of a model or any other objects tracked in W&B.
Interact with the model artifacts these methods created, such as updating properties (metadata, aliases, and descriptions)
For more information on W&B Artifacts and advanced versioning use cases, see the Artifacts documentation.
Log a model to a run
Use the log_model to log a model artifact that contains content within a directory you specify. The log_model method also marks the resulting model artifact as an output of the W&B run.
You can track a model’s dependencies and the model’s associations if you mark the model as the input or output of a W&B run. View the lineage of the model within the W&B App UI. See the Explore and traverse artifact graphs page within the Artifacts chapter for more information.
Provide the path where your model files are saved to the path parameter. The path can be a local file, directory, or reference URI to an external bucket such as s3://bucket/path.
Ensure to replace values enclosed in <> with your own.
import wandb
# Initialize a W&B runrun = wandb.init(project="<your-project>", entity="<your-entity>")
# Log the modelrun.log_model(path="<path-to-model>", name="<name>")
Optionally provide a name for the model artifact for the name parameter. If name is not specified, W&B will use the basename of the input path prepended with the run ID as the name.
Keep track of the name that you, or W&B assigns, to the model. You will need the name of the model to retrieve the model path with the use_model method.
See log_model in the API Reference guide for more information on possible parameters.
Example: Log a model to a run
import os
import wandb
from tensorflow import keras
from tensorflow.keras import layers
config = {"optimizer": "adam", "loss": "categorical_crossentropy"}
# Initialize a W&B runrun = wandb.init(entity="charlie", project="mnist-experiments", config=config)
# Hyperparametersloss = run.config["loss"]
optimizer = run.config["optimizer"]
metrics = ["accuracy"]
num_classes =10input_shape = (28, 28, 1)
# Training algorithmmodel = keras.Sequential(
[
layers.Input(shape=input_shape),
layers.Conv2D(32, kernel_size=(3, 3), activation="relu"),
layers.MaxPooling2D(pool_size=(2, 2)),
layers.Conv2D(64, kernel_size=(3, 3), activation="relu"),
layers.MaxPooling2D(pool_size=(2, 2)),
layers.Flatten(),
layers.Dropout(0.5),
layers.Dense(num_classes, activation="softmax"),
]
)
# Configure the model for trainingmodel.compile(loss=loss, optimizer=optimizer, metrics=metrics)
# Save modelmodel_filename ="model.h5"local_filepath ="./"full_path = os.path.join(local_filepath, model_filename)
model.save(filepath=full_path)
# Log the model to the W&B runrun.log_model(path=full_path, name="MNIST")
run.finish()
When the user called log_model, a model artifact named MNIST was created and the file model.h5 was added to the model artifact. Your terminal or notebook will print information of where to find information about the run the model was logged to.
View run different-surf-5 at: https://wandb.ai/charlie/mnist-experiments/runs/wlby6fuw
Synced 5 W&B file(s), 0 media file(s), 1 artifact file(s) and0 other file(s)
Find logs at: ./wandb/run-20231206_103511-wlby6fuw/logs
Download and use a logged model
Use the use_model function to access and download models files previously logged to a W&B run.
Provide the name of the model artifact where the model files you are want to retrieve are stored. The name you provide must match the name of an existing logged model artifact.
If you did not define name when originally logged the files with log_model, the default name assigned is the basename of the input path, prepended with the run ID.
Ensure to replace other the values enclosed in <> with your own:
import wandb
# Initialize a runrun = wandb.init(project="<your-project>", entity="<your-entity>")
# Access and download model. Returns path to downloaded artifactdownloaded_model_path = run.use_model(name="<your-model-name>")
The use_model function returns the path of downloaded model files. Keep track of this path if you want to link this model later. In the preceding code snippet, the returned path is stored in a variable called downloaded_model_path.
Example: Download and use a logged model
For example, in the proceeding code snippet a user called the use_model API. They specified the name of the model artifact they want to fetch and they also provided a version/alias. They then stored the path that is returned from the API to the downloaded_model_path variable.
import wandb
entity ="luka"project ="NLP_Experiments"alias ="latest"# semantic nickname or identifier for the model versionmodel_artifact_name ="fine-tuned-model"# Initialize a runrun = wandb.init(project=project, entity=entity)
# Access and download model. Returns path to downloaded artifactdownloaded_model_path = run.use_model(name =f"{model_artifact_name}:{alias}")
See use_model in the API Reference guide for more information on possible parameters and return type.
Log and link a model to the W&B Model Registry
The link_model method is currently only compatible with the legacy W&B Model Registry, which will soon be deprecated. To learn how to link a model artifact to the new edition of model registry, visit the Registry docs.
Use the link_model method to log model files to a W&B run and link it to the W&B Model Registry. If no registered model exists, W&B will create a new one for you with the name you provide for the registered_model_name parameter.
You can think of linking a model similar to ‘bookmarking’ or ‘publishing’ a model to a centralized team repository of models that others members of your team can view and consume.
Note that when you link a model, that model is not duplicated in the Model Registry. That model is also not moved out of the project and intro the registry. A linked model is a pointer to the original model in your project.
Use the Model Registry to organize your best models by task, manage model lifecycle, facilitate easy tracking and auditing throughout the ML lifecyle, and automate downstream actions with webhooks or jobs.
A Registered Model is a collection or folder of linked model versions in the Model Registry. Registered models typically represent candidate models for a single modeling use case or task.
The proceeding code snippet shows how to link a model with the link_model API. Ensure to replace other the values enclosed in <> with your own:
import wandb
run = wandb.init(entity="<your-entity>", project="<your-project>")
run.link_model(path="<path-to-model>", registered_model_name="<registered-model-name>")
run.finish()
See link_model in the API Reference guide for more information on optional parameters.
If the registered-model-name matches the name of a registered model that already exists within the Model Registry, the model will be linked to that registered model. If no such registered model exists, a new one will be created and the model will be the first one linked.
For example, suppose you have an existing registered model named “Fine-Tuned-Review-Autocompletion” in your Model Registry (see example here). And suppose that a few model versions are already linked to it: v0, v1, v2. If you call link_model with registered-model-name="Fine-Tuned-Review-Autocompletion", the new model will be linked to this existing registered model as v3. If no registered model with this name exists, a new one will be created and the new model will be linked as v0.
Example: Log and link a model to the W&B Model Registry
For example, the proceeding code snippet logs model files and links the model to a registered model name "Fine-Tuned-Review-Autocompletion".
To do this, a user calls the link_model API. When they call the API, they provide a local filepath that points the content of the model (path) and they provide a name for the registered model to link it to (registered_model_name).
Reminder: A registered model houses a collection of bookmarked model versions.
1.6.6 - Log summary metrics
In addition to values that change over time during training, it is often important to track a single value that summarizes a model or a preprocessing step. Log this information in a W&B Run’s summary dictionary. A Run’s summary dictionary can handle numpy arrays, PyTorch tensors or TensorFlow tensors. When a value is one of these types we persist the entire tensor in a binary file and store high level metrics in the summary object, such as min, mean, variance, percentiles, and more.
The last value logged with wandb.log is automatically set as the summary dictionary in a W&B Run. If a summary metric dictionary is modified, the previous value is lost.
The proceeding code snippet demonstrates how to provide a custom summary metric to W&B:
You can update the summary attribute of an existing W&B Run after training has completed. Use the W&B Public API to update the summary attribute:
api = wandb.Api()
run = api.run("username/project/run_id")
run.summary["tensor"] = np.random.random(1000)
run.summary.update()
Customize summary metrics
Custom summary metrics are useful for capturing model performance at the best step of training in your wandb.summary. For example, you might want to capture the maximum accuracy or the minimum loss value, instead of the final value.
By default, the summary uses the final value from history. To customize summary metrics, pass the summary argument in define_metric. It accepts the following values:
"min"
"max"
"mean"
"best"
"last"
"none"
You can use "best" only when you also set the optional objective argument to "minimize" or "maximize".
The following example adds the min and max values of loss and accuracy to the summary:
import wandb
import random
random.seed(1)
wandb.init()
# Min and max summary values for losswandb.define_metric("loss", summary="min")
wandb.define_metric("loss", summary="max")
# Min and max summary values for accuracywandb.define_metric("acc", summary="min")
wandb.define_metric("acc", summary="max")
for i in range(10):
log_dict = {
"loss": random.uniform(0, 1/ (i +1)),
"acc": random.uniform(1/ (i +1), 1),
}
wandb.log(log_dict)
View summary metrics
View summary values in a run’s Overview page or the project’s runs table.
Navigate to the W&B App.
Select the Workspace tab.
From the list of runs, click the name of the run that logged the summary values.
Select the Overview tab.
View the summary values in the Summary section.
Navigate to the W&B App.
Select the Runs tab.
Within the runs table, you can view the summary values within the columns based on the name of the summary value.
You can use the W&B Public API to fetch the summary values of a run.
The following code example demonstrates one way to retrieve the summary values logged to a specific run using the W&B Public API and pandas:
import wandb
import pandas
entity ="<your-entity>"project ="<your-project>"run_name ="<your-run-name>"# Name of run with summary valuesall_runs = []
for run in api.runs(f"{entity}/{project_name}"):
print("Fetching details for run: ", run.id, run.name)
run_data = {
"id": run.id,
"name": run.name,
"url": run.url,
"state": run.state,
"tags": run.tags,
"config": run.config,
"created_at": run.created_at,
"system_metrics": run.system_metrics,
"summary": run.summary,
"project": run.project,
"entity": run.entity,
"user": run.user,
"path": run.path,
"notes": run.notes,
"read_only": run.read_only,
"history_keys": run.history_keys,
"metadata": run.metadata,
}
all_runs.append(run_data)
# Convert to DataFrame df = pd.DataFrame(all_runs)
# Get row based on the column name (run) and convert to dictionarydf[df['name']==run_name].summary.reset_index(drop=True).to_dict()
To define a Table, specify the columns you want to see for each row of data. Each row might be a single item in your training dataset, a particular step or epoch during training, a prediction made by your model on a test item, an object generated by your model, etc. Each column has a fixed type: numeric, text, boolean, image, video, audio, etc. You do not need to specify the type in advance. Give each column a name, and make sure to only pass data of that type into that column index. For a more detailed example, see this report.
Use the wandb.Table constructor in one of two ways:
List of Rows: Log named columns and rows of data. For example the proceeding code snippet generates a table with two rows and three columns:
Pandas DataFrame: Log a DataFrame using wandb.Table(dataframe=my_df). Column names will be extracted from the DataFrame.
From an existing array or dataframe
# assume a model has returned predictions on four images# with the following fields available:# - the image id# - the image pixels, wrapped in a wandb.Image()# - the model's predicted label# - the ground truth labelmy_data = [
[0, wandb.Image("img_0.jpg"), 0, 0],
[1, wandb.Image("img_1.jpg"), 8, 0],
[2, wandb.Image("img_2.jpg"), 7, 1],
[3, wandb.Image("img_3.jpg"), 1, 1],
]
# create a wandb.Table() with corresponding columnscolumns = ["id", "image", "prediction", "truth"]
test_table = wandb.Table(data=my_data, columns=columns)
Add data
Tables are mutable. As your script executes you can add more data to your table, up to 200,000 rows. There are two ways to add data to a table:
Add a Row: table.add_data("3a", "3b", "3c"). Note that the new row is not represented as a list. If your row is in list format, use the star notation, * ,to expand the list to positional arguments: table.add_data(*my_row_list). The row must contain the same number of entries as there are columns in the table.
Add a Column: table.add_column(name="col_name", data=col_data). Note that the length of col_data must be equal to the table’s current number of rows. Here, col_data can be a list data, or a NumPy NDArray.
Adding data incrementally
This code sample shows how to create and populate a W&B table incrementally. You define the table with predefined columns, including confidence scores for all possible labels, and add data row by row during inference. You can also add data to tables incrementally when resuming runs.
# Define the columns for the table, including confidence scores for each labelcolumns = ["id", "image", "guess", "truth"]
for digit in range(10): # Add confidence score columns for each digit (0-9) columns.append(f"score_{digit}")
# Initialize the table with the defined columnstest_table = wandb.Table(columns=columns)
# Iterate through the test dataset and add data to the table row by row# Each row includes the image ID, image, predicted label, true label, and confidence scoresfor img_id, img in enumerate(mnist_test_data):
true_label = mnist_test_data_labels[img_id] # Ground truth label guess_label = my_model.predict(img) # Predicted label test_table.add_data(
img_id, wandb.Image(img), guess_label, true_label
) # Add row data to the table
Adding data to resumed runs
You can incrementally update a W&B table in resumed runs by loading an existing table from an artifact, retrieving the last row of data, and adding the updated metrics. Then, reinitialize the table for compatibility and log the updated version back to W&B.
# Load the existing table from the artifactbest_checkpt_table = wandb.use_artifact(table_tag).get(table_name)
# Get the last row of data from the table for resumingbest_iter, best_metric_max, best_metric_min = best_checkpt_table.data[-1]
# Update the best metrics as needed# Add the updated data to the tablebest_checkpt_table.add_data(best_iter, best_metric_max, best_metric_min)
# Reinitialize the table with its updated data to ensure compatibilitybest_checkpt_table = wandb.Table(
columns=["col1", "col2", "col3"], data=best_checkpt_table.data
)
# Log the updated table to Weights & Biaseswandb.log({table_name: best_checkpt_table})
Retrieve data
Once data is in a Table, access it by column or by row:
Row Iterator: Users can use the row iterator of Table such as for ndx, row in table.iterrows(): ... to efficiently iterate over the data’s rows.
Get a Column: Users can retrieve a column of data using table.get_column("col_name") . As a convenience, users can pass convert_to="numpy" to convert the column to a NumPy NDArray of primitives. This is useful if your column contains media types such as wandb.Image so that you can access the underlying data directly.
Save tables
After you generate a table of data in your script, for example a table of model predictions, save it to W&B to visualize the results live.
Log a table to a run
Use wandb.log() to save your table to the run, like so:
Each time a table is logged to the same key, a new version of the table is created and stored in the backend. This means you can log the same table across multiple training steps to see how model predictions improve over time, or compare tables across different runs, as long as they’re logged to the same key. You can log up to 200,000 rows.
To log more than 200,000 rows, you can override the limit with:
wandb.Table.MAX_ARTIFACT_ROWS = X
However, this would likely cause performance issues, such as slower queries, in the UI.
Access tables programmatically
In the backend, Tables are persisted as Artifacts. If you are interested in accessing a specific version, you can do so with the artifact API:
with wandb.init() as run:
my_table = run.use_artifact("run-<run-id>-<table-name>:<tag>").get("<table-name>")
For more information on Artifacts, see the Artifacts Chapter in the Developer Guide.
Visualize tables
Any table logged this way will show up in your Workspace on both the Run Page and the Project Page. For more information, see Visualize and Analyze Tables.
Artifact tables
Use artifact.add() to log tables to the Artifacts section of your run instead of the workspace. This could be useful if you have a dataset that you want to log once and then reference for future runs.
run = wandb.init(project="my_project")
# create a wandb Artifact for each meaningful steptest_predictions = wandb.Artifact("mnist_test_preds", type="predictions")
# [build up your predictions data as above]test_table = wandb.Table(data=data, columns=columns)
test_predictions.add(test_table, "my_test_key")
run.log_artifact(test_predictions)
You can join tables you have locally constructed or tables you have retrieved from other artifacts using wandb.JoinedTable(table_1, table_2, join_key).
Args
Description
table_1
(str, wandb.Table, ArtifactEntry) the path to a wandb.Table in an artifact, the table object, or ArtifactEntry
table_2
(str, wandb.Table, ArtifactEntry) the path to a wandb.Table in an artifact, the table object, or ArtifactEntry
join_key
(str, [str, str]) key or keys on which to perform the join
To join two Tables you have logged previously in an artifact context, fetch them from the artifact and join the result into a new Table.
For example, demonstrates how to read one Table of original songs called 'original_songs' and another Table of synthesized versions of the same songs called 'synth_songs'. The proceeding code example joins the two tables on "song_id", and uploads the resulting table as a new W&B Table:
import wandb
run = wandb.init(project="my_project")
# fetch original songs tableorig_songs = run.use_artifact("original_songs:latest")
orig_table = orig_songs.get("original_samples")
# fetch synthesized songs tablesynth_songs = run.use_artifact("synth_songs:latest")
synth_table = synth_songs.get("synth_samples")
# join tables on "song_id"join_table = wandb.JoinedTable(orig_table, synth_table, "song_id")
join_at = wandb.Artifact("synth_summary", "analysis")
# add table to artifact and log to W&Bjoin_at.add(join_table, "synth_explore")
run.log_artifact(join_at)
Read this tutorial for an example on how to combine two previously stored tables stored in different Artifact objects.
We suggest you utilize W&B Artifacts to make it easier to re-use the contents of the CSV file easier to use.
To get started, first import your CSV file. In the proceeding code snippet, replace the iris.csv filename with the name of your CSV filename:
import wandb
import pandas as pd
# Read our CSV into a new DataFramenew_iris_dataframe = pd.read_csv("iris.csv")
Convert the CSV file to a W&B Table to utilize W&B Dashboards.
# Convert the DataFrame into a W&B Tableiris_table = wandb.Table(dataframe=new_iris_dataframe)
Next, create a W&B Artifact and add the table to the Artifact:
# Add the table to an Artifact to increase the row# limit to 200000 and make it easier to reuseiris_table_artifact = wandb.Artifact("iris_artifact", type="dataset")
iris_table_artifact.add(iris_table, "iris_table")
# Log the raw csv file within an artifact to preserve our datairis_table_artifact.add_file("iris.csv")
For more information about W&B Artifacts, see the Artifacts chapter.
Lastly, start a new W&B Run to track and log to W&B with wandb.init:
# Start a W&B run to log datarun = wandb.init(project="tables-walkthrough")
# Log the table to visualize with a run...run.log({"iris": iris_table})
# and Log as an Artifact to increase the available row limit!run.log_artifact(iris_table_artifact)
The wandb.init() API spawns a new background process to log data to a Run, and it synchronizes data to wandb.ai (by default). View live visualizations on your W&B Workspace Dashboard. The following image demonstrates the output of the code snippet demonstration.
The full script with the preceding code snippets is found below:
import wandb
import pandas as pd
# Read our CSV into a new DataFramenew_iris_dataframe = pd.read_csv("iris.csv")
# Convert the DataFrame into a W&B Tableiris_table = wandb.Table(dataframe=new_iris_dataframe)
# Add the table to an Artifact to increase the row# limit to 200000 and make it easier to reuseiris_table_artifact = wandb.Artifact("iris_artifact", type="dataset")
iris_table_artifact.add(iris_table, "iris_table")
# log the raw csv file within an artifact to preserve our datairis_table_artifact.add_file("iris.csv")
# Start a W&B run to log datarun = wandb.init(project="tables-walkthrough")
# Log the table to visualize with a run...run.log({"iris": iris_table})
# and Log as an Artifact to increase the available row limit!run.log_artifact(iris_table_artifact)
# Finish the run (useful in notebooks)run.finish()
Import and log your CSV of Experiments
In some cases, you might have your experiment details in a CSV file. Common details found in such CSV files include:
Configurations needed for your experiment (with the added benefit of being able to utilize our Sweeps Hyperparameter Tuning).
Experiment
Model Name
Notes
Tags
Num Layers
Final Train Acc
Final Val Acc
Training Losses
Experiment 1
mnist-300-layers
Overfit way too much on training data
[latest]
300
0.99
0.90
[0.55, 0.45, 0.44, 0.42, 0.40, 0.39]
Experiment 2
mnist-250-layers
Current best model
[prod, best]
250
0.95
0.96
[0.55, 0.45, 0.44, 0.42, 0.40, 0.39]
Experiment 3
mnist-200-layers
Did worse than the baseline model. Need to debug
[debug]
200
0.76
0.70
[0.55, 0.45, 0.44, 0.42, 0.40, 0.39]
…
…
…
…
…
…
…
Experiment N
mnist-X-layers
NOTES
…
…
…
…
[…, …]
W&B can take CSV files of experiments and convert it into a W&B Experiment Run. The proceeding code snippets and code script demonstrates how to import and log your CSV file of experiments:
To get started, first read in your CSV file and convert it into a Pandas DataFrame. Replace "experiments.csv" with the name of your CSV file:
import wandb
import pandas as pd
FILENAME ="experiments.csv"loaded_experiment_df = pd.read_csv(FILENAME)
PROJECT_NAME ="Converted Experiments"EXPERIMENT_NAME_COL ="Experiment"NOTES_COL ="Notes"TAGS_COL ="Tags"CONFIG_COLS = ["Num Layers"]
SUMMARY_COLS = ["Final Train Acc", "Final Val Acc"]
METRIC_COLS = ["Training Losses"]
# Format Pandas DataFrame to make it easier to work withfor i, row in loaded_experiment_df.iterrows():
run_name = row[EXPERIMENT_NAME_COL]
notes = row[NOTES_COL]
tags = row[TAGS_COL]
config = {}
for config_col in CONFIG_COLS:
config[config_col] = row[config_col]
metrics = {}
for metric_col in METRIC_COLS:
metrics[metric_col] = row[metric_col]
summaries = {}
for summary_col in SUMMARY_COLS:
summaries[summary_col] = row[summary_col]
Next, start a new W&B Run to track and log to W&B with wandb.init():
run = wandb.init(
project=PROJECT_NAME, name=run_name, tags=tags, notes=notes, config=config
)
As an experiment runs, you might want to log every instance of your metrics so they are available to view, query, and analyze with W&B. Use the run.log() command to accomplish this:
run.log({key: val})
You can optionally log a final summary metric to define the outcome of the run. Use the W&B define_metric API to accomplish this. In this example case, we will add the summary metrics to our run with run.summary.update():
Below is the full example script that converts the above sample table into a W&B Dashboard:
FILENAME ="experiments.csv"loaded_experiment_df = pd.read_csv(FILENAME)
PROJECT_NAME ="Converted Experiments"EXPERIMENT_NAME_COL ="Experiment"NOTES_COL ="Notes"TAGS_COL ="Tags"CONFIG_COLS = ["Num Layers"]
SUMMARY_COLS = ["Final Train Acc", "Final Val Acc"]
METRIC_COLS = ["Training Losses"]
for i, row in loaded_experiment_df.iterrows():
run_name = row[EXPERIMENT_NAME_COL]
notes = row[NOTES_COL]
tags = row[TAGS_COL]
config = {}
for config_col in CONFIG_COLS:
config[config_col] = row[config_col]
metrics = {}
for metric_col in METRIC_COLS:
metrics[metric_col] = row[metric_col]
summaries = {}
for summary_col in SUMMARY_COLS:
summaries[summary_col] = row[summary_col]
run = wandb.init(
project=PROJECT_NAME, name=run_name, tags=tags, notes=notes, config=config
)
for key, val in metrics.items():
if isinstance(val, list):
for _val in val:
run.log({key: _val})
else:
run.log({key: val})
run.summary.update(summaries)
run.finish()
1.7 - Track Jupyter notebooks
se W&B with Jupyter to get interactive visualizations without leaving your notebook.
Use W&B with Jupyter to get interactive visualizations without leaving your notebook. Combine custom analysis, experiments, and prototypes, all fully logged.
Use cases for W&B with Jupyter notebooks
Iterative experimentation: Run and re-run experiments, tweaking parameters, and have all the runs you do saved automatically to W&B without having to take manual notes along the way.
Code saving: When reproducing a model, it’s hard to know which cells in a notebook ran, and in which order. Turn on code saving on your settings page to save a record of cell execution for each experiment.
Custom analysis: Once runs are logged to W&B, it’s easy to get a dataframe from the API and do custom analysis, then log those results to W&B to save and share in reports.
Getting started in a notebook
Start your notebook with the following code to install W&B and link your account:
After running wandb.init() , start a new cell with %%wandb to see live graphs in the notebook. If you run this cell multiple times, data will be appended to the run.
Rendering live W&B interfaces directly in your notebooks
You can also display any existing dashboards, sweeps, or reports directly in your notebook using the %wandb magic:
# Display a project workspace
%wandb USERNAME/PROJECT
# Display a single run
%wandb USERNAME/PROJECT/runs/RUN_ID
# Display a sweep
%wandb USERNAME/PROJECT/sweeps/SWEEP_ID
# Display a report
%wandb USERNAME/PROJECT/reports/REPORT_ID
# Specify the height of embedded iframe
%wandb USERNAME/PROJECT -h 2048
As an alternative to the %%wandb or %wandb magics, after running wandb.init() you can end any cell with wandb.run to show in-line graphs, or call ipython.display(...) on any report, sweep, or run object returned from our apis.
# Initialize wandb.run firstwandb.init()
# If cell outputs wandb.run, you'll see live graphswandb.run
Easy authentication in Colab: When you call wandb.init for the first time in a Colab, we automatically authenticate your runtime if you’re currently logged in to W&B in your browser. On the overview tab of your run page, you’ll see a link to the Colab.
Jupyter Magic: Display dashboards, sweeps and reports directly in your notebooks. The %wandb magic accepts a path to your project, sweeps or reports and will render the W&B interface directly in the notebook.
Launch dockerized Jupyter: Call wandb docker --jupyter to launch a docker container, mount your code in it, ensure Jupyter is installed, and launch on port 8888.
Run cells in arbitrary order without fear: By default, we wait until the next time wandb.init is called to mark a run as finished. That allows you to run multiple cells (say, one to set up data, one to train, one to test) in whatever order you like and have them all log to the same run. If you turn on code saving in settings, you’ll also log the cells that were executed, in order and in the state in which they were run, enabling you to reproduce even the most non-linear of pipelines. To mark a run as complete manually in a Jupyter notebook, call run.finish.
import wandb
run = wandb.init()
# training script and logging goes hererun.finish()
1.8 - Experiments limits and performance
Keep your pages in W&B faster and more responsive by logging within these suggested bounds.
Keep your pages in W&B faster and more responsive by logging within the following suggested bounds.
Logging considerations
Use wandb.log to track experiment metrics. Once logged, these metrics generate charts and show up in tables. Too much logged data can make the app slow.
Distinct metric count
For faster performance, keep the total number of distinct metrics in a project under 10,000.
import wandb
wandb.log(
{
"a": 1, # "a" is a distinct metric"b": {
"c": "hello", # "b.c" is a distinct metric"d": [1, 2, 3], # "b.d" is a distinct metric },
}
)
W&B automatically flattens nested values. This means that if you pass a dictionary, W&B turns it into a dot-separated name. For config values, W&B supports 3 dots in the name. For summary values, W&B supports 4 dots.
If your workspace suddenly slows down, check whether recent runs have unintentionally logged thousands of new metrics. (This is easiest to spot by seeing sections with thousands of plots that have only one or two runs visible on them.) If they have, consider deleting those runs and recreating them with the desired metrics.
Value width
Limit the size of a single logged value to under 1 MB and the total size of a single wandb.log call to under 25 MB. This limit does not apply to wandb.Media types like wandb.Image, wandb.Audio, etc.
# ❌ not recommendedwandb.log({"wide_key": range(10000000)})
# ❌ not recommendedwith f as open("large_file.json", "r"):
large_data = json.load(f)
wandb.log(large_data)
Wide values can affect the plot load times for all metrics in the run, not just the metric with the wide values.
Data is saved and tracked even if you log values wider than the recommended amount. However, your plots may load more slowly.
Metric frequency
Pick a logging frequency that is appropriate to the metric you are logging. As a general rule of thumb, the wider the metric the less frequently you should log it. W&B recommends:
Scalars: <100,000 logged points per metric
Media: <50,000 logged points per metric
Histograms: <10,000 logged points per metric
# Training loop with 1m total stepsfor step in range(1000000):
# ❌ not recommended wandb.log(
{
"scalar": step, # 100,000 scalars"media": wandb.Image(...), # 100,000 images"histogram": wandb.Histogram(...), # 100,000 histograms }
)
# ✅ recommendedif step %1000==0:
wandb.log(
{
"histogram": wandb.Histogram(...), # 10,000 histograms },
commit=False,
)
if step %200==0:
wandb.log(
{
"media": wandb.Image(...), # 50,000 images },
commit=False,
)
if step %100==0:
wandb.log(
{
"scalar": step, # 100,000 scalars },
commit=True,
) # Commit batched, per-step metrics together
W&B continues to accept your logged data but pages may load more slowly if you exceed guidelines.
Config size
Limit the total size of your run config to less than 10 MB. Logging large values could slow down your project workspaces and runs table operations.
# ✅ recommendedwandb.init(
config={
"lr": 0.1,
"batch_size": 32,
"epochs": 4,
}
)
# ❌ not recommendedwandb.init(
config={
"steps": range(10000000),
}
)
# ❌ not recommendedwith f as open("large_config.json", "r"):
large_config = json.load(f)
wandb.init(config=large_config)
Workspace considerations
Run count
To reduce loading times, keep the total number of runs in a single project under:
100,000 on SaaS Cloud
10,000 on Dedicated Cloud or Self-managed
Run counts over these thresholds can slow down operations that involve project workspaces or runs tables, especially when grouping runs or collecting a large number of distinct metrics during runs. See also the Metric count section.
If your team accesses the same set of runs frequently, such as the set of recent runs, consider moving less frequently used runs in bulk to a new “archive” project, leaving a smaller set of runs in your working project.
Workspace performance
This section gives tips for optimizing the performance of your workspace.
Panel count
By default, a workspace is automatic, and generates standard panels for each logged key. If a workspace for a large project includes panels for many logged keys, the workspace may be slow to load and use. To improve performance, you can:
Reset the workspace to manual mode, which includes no panels by default.
Use Quick add to selectively add panels for the logged keys you need to visualize.
Deleting unused panels one at a time has little impact on performance. Instead, reset the workspace and seletively add back only those panels you need.
To learn more about configuring your workspace, refer to Panels.
Section count
Having hundreds of sections in a workspace can hurt performance. Consider creating sections based on high-level groupings of metrics and avoiding an anti-pattern of one section for each metric.
If you find you have too many sections and performance is slow, consider the workspace setting to create sections by prefix rather than suffix, which can result in fewer sections and better performance.
Metric count
When logging between 5000 and 100,000 metrics per run, W&B recommends using a [manual workspace[{{ relref “/guides/models/app/features/panels/#workspace-modes” >}}). In Manual mode, you can easily add and remove panels in bulk as you choose to explore different sets of metrics. With a more focused set of plots, the workspace loads faster. Metrics that are not plotted are still collected and stored as usual.
To reset a workspace to manual mode, click the workspace’s action ... menu, then click Reset workspace. Resetting a workspace has no impact on stored metrics for runs. Learn more about managing workspaces.
File count
Keep the total number of files uploaded for a single run under 1,000. You can use W&B Artifacts when you need to log a large number of files. Exceeding 1,000 files in a single run can slow down your run pages.
Reports vs. Workspaces
A report is a free-form composition of arbitrary arrangements of panels, text, and media, allowing you to easily share your insights with colleagues.
By contrast, a workspace allows high-density and performant analysis of dozens to thousands of metrics across hundreds to hundreds of thousands of runs. Workspaces have optimized caching, querying, and loading capabilities, when compared to reports. Workspaces are recommended for a project that is used primarily for analysis, rather than presentation, or when you need to show 20 or more plots together.
Python script performance
There are a few ways that the performance of your python script is reduced:
The size of your data is too large. Large data sizes could introduce a >1 ms overhead to the training loop.
The speed of your network and how the W&B backend is configured
Calling wandb.log more than a few times per second. This is due to a small latency added to the training loop every time wandb.log is called.
Is frequent logging slowing your training runs down? Check out this Colab for methods to get better performance by changing your logging strategy.
W&B does not assert any limits beyond rate limiting. The W&B Python SDK automatically completes an exponential “backoff” and “retry” requests that exceed limits. W&B Python SDK responds with a “Network failure” on the command line. For unpaid accounts, W&B may reach out in extreme cases where usage exceeds reasonable thresholds.
Rate limits
W&B SaaS Cloud API implements a rate limit to maintain system integrity and ensure availability. This measure prevents any single user from monopolizing available resources in the shared infrastructure, ensuring that the service remains accessible to all users. You may encounter a lower rate limit for a variety of reasons.
Rate limits are subject to change.
Rate limit HTTP headers
The preceding table describes rate limit HTTP headers:
Header name
Description
RateLimit-Limit
The amount of quota available per time window, scaled in the range of 0 to 1000
RateLimit-Remaining
The amount of quota in the current rate limit window, scaled in the range of 0 and 1000
RateLimit-Reset
The number of seconds until the current quota resets
Rate limits on metric logging API
The wandb.log calls in your script utilize a metrics logging API to log your training data to W&B. This API is engaged through either online or offline syncing. In either case, it imposes a rate limit quota limit in a rolling time window. This includes limits on total request size and request rate, where latter refers to the number of requests in a time duration.
W&B applies rate limits per W&B project. So if you have 3 projects in a team, each project has its own rate limit quota. Users on Teams and Enterprise plans have higher rate limits than those on the Free plan.
When you hit the rate limit while using the metrics logging API, you see a relevant message indicating the error in the standard output.
Suggestions for staying under the metrics logging API rate limit
Exceeding the rate limit may delay run.finish() until the rate limit resets. To avoid this, consider the following strategies:
Update your W&B Python SDK version: Ensure you are using the latest version of the W&B Python SDK. The W&B Python SDK is regularly updated and includes enhanced mechanisms for gracefully retrying requests and optimizing quota usage.
Reduce metric logging frequency:
Minimize the frequency of logging metrics to conserve your quota. For example, you can modify your code to log metrics every five epochs instead of every epoch:
if epoch %5==0: # Log metrics every 5 epochs wandb.log({"acc": accuracy, "loss": loss})
Manual data syncing: W&B store your run data locally if you are rate limited. You can manually sync your data with the command wandb sync <run-file-path>. For more details, see the wandb sync reference.
Rate limits on GraphQL API
The W&B Models UI and SDK’s public API make GraphQL requests to the server for querying and modifying data. For all GraphQL requests in SaaS Cloud, W&B applies rate limits per IP address for unauthorized requests and per user for authorized requests. The limit is based on request rate (request per second) within a fixed time window, where your pricing plan determines the default limits. For relevant SDK requests that specify a project path (for example, reports, runs, artifacts), W&B applies rate limits per project, measured by database query time.
Users on Teams and Enterprise plans receive higher rate limits than those on the Free plan.
When you hit the rate limit while using the W&B Models SDK’s public API, you see a relevant message indicating the error in the standard output.
Suggestions for staying under the GraphQL API rate limit
If you are fetching a large volume of data using the W&B Models SDK’s public API, consider waiting at least one second between requests. If you receive a 429 status code or see RateLimit-Remaining=0 in the response headers, wait for the number of seconds specified in RateLimit-Reset before retrying.
Browser considerations
The W&B app can be memory-intensive and performs best in Chrome. Depending on your computer’s memory, having W&B active in 3+ tabs at once can cause performance to degrade. If you encounter unexpectedly slow performance, consider closing other tabs or applications.
Reporting performance issues to W&B
W&B takes performance seriously and investigates every report of lag. To expedite investigation, when reporting slow loading times consider invoking W&B’s built-in performance logger that captures key metrics and performance events. Append the URL parameter &PERF_LOGGING to a page that is loading slowly, then share the output of your console with your account team or Support.
1.9 - Reproduce experiments
Reproduce an experiment that a team member creates to verify and validate their results.
Before you reproduce an experiment, you need to make note of the:
Name of the project the run was logged to
Name of the run you want to reproduce
To reproduce an experiment:
Navigate to the project where the run is logged to.
Select the Workspace tab in the left sidebar.
From the list of runs, select the run that you want to reproduce.
Click Overview.
To continue, download the experiment’s code at a given hash or clone the experiment’s entire repository.
Download the experiment’s Python script or notebook:
In the Command field, make a note of the name of the script that created the experiment.
Select the Code tab in the left navigation bar.
Click Download next to the file that corresponds to the script or notebook.
Clone the GitHub repository your teammate used when creating the experiment. To do this:
If necessary, gain access to the GitHub repository that your teammate used to create the experiment.
Copy the Git repository field, which contains the GitHub repository URL.
Clone the repository:
git clone https://github.com/your-repo.git && cd your-repo
Copy and paste the Git state field into your terminal. The Git state is a set of Git commands that checks out the exact commit that your teammate used to create the experiment. Replace values specified in the proceeding code snippet with your own:
Download the requirements.txt file and store it in your working directory. This directory should contain either the cloned GitHub repository or the downloaded Python script or notebook.
(Recommended) Create a Python virtual environment.
Install the requirements specified in the requirements.txt file.
pip install -r requirements.txt
Now that you have the code and dependencies, you can run the script or notebook to reproduce the experiment. If you cloned a repository, you might need to navigate to the directory where the script or notebook is located. Otherwise, you can run the script or notebook from your working directory.
If you downloaded a Python notebook, navigate to the directory where you downloaded the notebook and run the following command in your terminal:
jupyter notebook
If you downloaded a Python script, navigate to the directory where you downloaded the script and run the following command in your terminal; Replace values enclosed in <> with your own:
python <your-script-name>.py
1.10 - Import and export data
Import data from MLFlow, export or update data that you have saved to W&B
Export data or import data with W&B Public APIs.
This feature requires python>=3.8
Import data from MLFlow
W&B supports importing data from MLFlow, including experiments, runs, artifacts, metrics, and other metadata.
Install dependencies:
# note: this requires py38+pip install wandb[importers]
Log in to W&B. Follow the prompts if you have not logged in before.
By default, importer.collect_runs() collects all runs from the MLFlow server. If you prefer to upload a special subset, you can construct your own runs iterable and pass it to the importer.
import mlflow
from wandb.apis.importers.mlflow import MlflowRun
client = mlflow.tracking.MlflowClient(mlflow_tracking_uri)
runs: Iterable[MlflowRun] = []
for run in mlflow_client.search_runs(...):
runs.append(MlflowRun(run, client))
importer.import_runs(runs)
Set mlflow-tracking-uri="databricks" in the previous step.
To skip importing artifacts, you can pass artifacts=False:
importer.import_runs(runs, artifacts=False)
To import to a specific W&B entity and project, you can pass a Namespace:
from wandb.apis.importers import Namespace
importer.import_runs(runs, namespace=Namespace(entity, project))
Export Data
Use the Public API to export or update data that you have saved to W&B. Before using this API, log data from your script. Check the Quickstart for more details.
Use Cases for the Public API
Export Data: Pull down a dataframe for custom analysis in a Jupyter Notebook. Once you have explored the data, you can sync your findings by creating a new analysis run and logging results, for example: wandb.init(job_type="analysis")
Update Existing Runs: You can update the data logged in association with a W&B run. For example, you might want to update the config of a set of runs to include additional information, like the architecture or a hyperparameter that wasn’t originally logged.
An API key authenticates your machine to W&B. You can generate an API key from your user profile.
For a more streamlined approach, you can generate an API key by going directly to https://wandb.ai/authorize. Copy the displayed API key and save it in a secure location such as a password manager.
Click your user profile icon in the upper right corner.
Select User Settings, then scroll to the API Keys section.
Click Reveal. Copy the displayed API key. To hide the API key, reload the page.
Find the run path
To use the Public API, you’ll often need the run path which is <entity>/<project>/<run_id>. In the app UI, open a run page and click the Overview tab to get the run path.
Export Run Data
Download data from a finished or active run. Common usage includes downloading a dataframe for custom analysis in a Jupyter notebook, or using custom logic in an automated environment.
import wandb
api = wandb.Api()
run = api.run("<entity>/<project>/<run_id>")
The most commonly used attributes of a run object are:
Attribute
Meaning
run.config
A dictionary of the run’s configuration information, such as the hyperparameters for a training run or the preprocessing methods for a run that creates a dataset Artifact. Think of these as the run’s inputs.
run.history()
A list of dictionaries meant to store values that change while the model is training such as loss. The command wandb.log() appends to this object.
run.summary
A dictionary of information that summarizes the run’s results. This can be scalars like accuracy and loss, or large files. By default, wandb.log() sets the summary to the final value of a logged time series. The contents of the summary can also be set directly. Think of the summary as the run’s outputs.
You can also modify or update the data of past runs. By default a single instance of an api object will cache all network requests. If your use case requires real time information in a running script, call api.flush() to get updated values.
Understanding the Different Attributes
For the below run
n_epochs =5config = {"n_epochs": n_epochs}
run = wandb.init(project=project, config=config)
for n in range(run.config.get("n_epochs")):
run.log(
{"val": random.randint(0, 1000), "loss": (random.randint(0, 1000) /1000.00)}
)
run.finish()
these are the different outputs for the above run object attributes
run.config
{"n_epochs": 5}
run.history()
_step val loss _runtime _timestamp
00500 0.244 416443454121145 0.521 4164434541222240 0.785 416443454123331 0.305 4164434541244525 0.041 41644345412
The default history method samples the metrics to a fixed number of samples (the default is 500, you can change this with the samples __ argument). If you want to export all of the data on a large run, you can use the run.scan_history() method. For more details see the API Reference.
Querying Multiple Runs
This example script finds a project and outputs a CSV of runs with name, configs and summary stats. Replace <entity> and <project> with your W&B entity and the name of your project, respectively.
import pandas as pd
import wandb
api = wandb.Api()
entity, project ="<entity>", "<project>"runs = api.runs(entity +"/"+ project)
summary_list, config_list, name_list = [], [], []
for run in runs:
# .summary contains output keys/values for# metrics such as accuracy.# We call ._json_dict to omit large files summary_list.append(run.summary._json_dict)
# .config contains the hyperparameters.# We remove special values that start with _. config_list.append({k: v for k, v in run.config.items() ifnot k.startswith("_")})
# .name is the human-readable name of the run. name_list.append(run.name)
runs_df = pd.DataFrame(
{"summary": summary_list, "config": config_list, "name": name_list}
)
runs_df.to_csv("project.csv")
The W&B API also provides a way for you to query across runs in a project with api.runs(). The most common use case is exporting runs data for custom analysis. The query interface is the same as the one MongoDB uses.
Calling api.runs returns a Runs object that is iterable and acts like a list. By default the object loads 50 runs at a time in sequence as required, but you can change the number loaded per page with the per_page keyword argument.
api.runs also accepts an order keyword argument. The default order is -created_at. To order results ascending, specify +created_at. You can also sort by config or summary values. For example, summary.val_acc or config.experiment_name.
Error Handling
If errors occur while talking to W&B servers a wandb.CommError will be raised. The original exception can be introspected via the exc attribute.
Get the latest git commit through the API
In the UI, click on a run and then click the Overview tab on the run page to see the latest git commit. It’s also in the file wandb-metadata.json . Using the public API, you can get the git hash with run.commit.
Get a run’s name and ID during a run
After calling wandb.init() you can access the random run ID or the human readable run name from your script like this:
Unique run ID (8 character hash): wandb.run.id
Random run name (human readable): wandb.run.name
If you’re thinking about ways to set useful identifiers for your runs, here’s what we recommend:
Run ID: leave it as the generated hash. This needs to be unique across runs in your project.
Run name: This should be something short, readable, and preferably unique so that you can tell the difference between different lines on your charts.
Run notes: This is a great place to put a quick description of what you’re doing in your run. You can set this with wandb.init(notes="your notes here")
Run tags: Track things dynamically in run tags, and use filters in the UI to filter your table down to just the runs you care about. You can set tags from your script and then edit them in the UI, both in the runs table and the overview tab of the run page. See the detailed instructions here.
Public API Examples
Export data to visualize in matplotlib or seaborn
Check out our API examples for some common export patterns. You can also click the download button on a custom plot or on the expanded runs table to download a CSV from your browser.
Read metrics from a run
This example outputs timestamp and accuracy saved with wandb.log({"accuracy": acc}) for a run saved to "<entity>/<project>/<run_id>".
import wandb
api = wandb.Api()
run = api.run("<entity>/<project>/<run_id>")
if run.state =="finished":
for i, row in run.history().iterrows():
print(row["_timestamp"], row["accuracy"])
Filter runs
You can filters by using the MongoDB Query Language.
To pull specific metrics from a run, use the keys argument. The default number of samples when using run.history() is 500. Logged steps that do not include a specific metric will appear in the output dataframe as NaN. The keys argument will cause the API to sample steps that include the listed metric keys more frequently.
import wandb
api = wandb.Api()
run = api.run("<entity>/<project>/<run_id>")
if run.state =="finished":
for i, row in run.history(keys=["accuracy"]).iterrows():
print(row["_timestamp"], row["accuracy"])
Compare two runs
This will output the config parameters that are different between run1 and run2.
import pandas as pd
import wandb
api = wandb.Api()
# replace with your <entity>, <project>, and <run_id>run1 = api.run("<entity>/<project>/<run_id>")
run2 = api.run("<entity>/<project>/<run_id>")
df = pd.DataFrame([run1.config, run2.config]).transpose()
df.columns = [run1.name, run2.name]
print(df[df[run1.name] != df[run2.name]])
Update metrics for a run, after the run has finished
This example sets the accuracy of a previous run to 0.9. It also modifies the accuracy histogram of a previous run to be the histogram of numpy_array.
import wandb
api = wandb.Api()
run = api.run("<entity>/<project>/<run_id>")
run.summary["accuracy"] =0.9run.summary["accuracy_histogram"] = wandb.Histogram(numpy_array)
run.summary.update()
Rename a metric in a completed run
This example renames a summary column in your tables.
import wandb
api = wandb.Api()
run = api.run("<entity>/<project>/<run_id>")
run.summary["new_name"] = run.summary["old_name"]
del run.summary["old_name"]
run.summary.update()
Renaming a column only applies to tables. Charts will still refer to metrics by their original names.
Update config for an existing run
This examples updates one of your configuration settings.
import wandb
api = wandb.Api()
run = api.run("<entity>/<project>/<run_id>")
run.config["key"] = updated_value
run.update()
Export system resource consumptions to a CSV file
The snippet below would find the system resource consumptions and then, save them to a CSV.
import wandb
run = wandb.Api().run("<entity>/<project>/<run_id>")
system_metrics = run.history(stream="events")
system_metrics.to_csv("sys_metrics.csv")
Get unsampled metric data
When you pull data from history, by default it’s sampled to 500 points. Get all the logged data points using run.scan_history(). Here’s an example downloading all the loss data points logged in history.
import wandb
api = wandb.Api()
run = api.run("<entity>/<project>/<run_id>")
history = run.scan_history()
losses = [row["loss"] for row in history]
Get paginated data from history
If metrics are being fetched slowly on our backend or API requests are timing out, you can try lowering the page size in scan_history so that individual requests don’t time out. The default page size is 500, so you can experiment with different sizes to see what works best:
import wandb
api = wandb.Api()
run = api.run("<entity>/<project>/<run_id>")
run.scan_history(keys=sorted(cols), page_size=100)
Export metrics from all runs in a project to a CSV file
This script pulls down the runs in a project and produces a dataframe and a CSV of runs including their names, configs, and summary stats. Replace <entity> and <project> with your W&B entity and the name of your project, respectively.
import pandas as pd
import wandb
api = wandb.Api()
entity, project ="<entity>", "<project>"runs = api.runs(entity +"/"+ project)
summary_list, config_list, name_list = [], [], []
for run in runs:
# .summary contains the output keys/values# for metrics such as accuracy.# We call ._json_dict to omit large files summary_list.append(run.summary._json_dict)
# .config contains the hyperparameters.# We remove special values that start with _. config_list.append({k: v for k, v in run.config.items() ifnot k.startswith("_")})
# .name is the human-readable name of the run. name_list.append(run.name)
runs_df = pd.DataFrame(
{"summary": summary_list, "config": config_list, "name": name_list}
)
runs_df.to_csv("project.csv")
Get the starting time for a run
This code snippet retrieves the time at which the run was created.
import wandb
api = wandb.Api()
run = api.run("entity/project/run_id")
start_time = run.created_at
Upload files to a finished run
The code snippet below uploads a selected file to a finished run.
import wandb
api = wandb.Api()
run = api.run("entity/project/run_id")
run.upload_file("file_name.extension")
Download a file from a run
This finds the file “model-best.h5” associated with run ID uxte44z7 in the cifar project and saves it locally.
import wandb
api = wandb.Api()
run = api.run("<entity>/<project>/<run_id>")
run.file("model-best.h5").download()
Download all files from a run
This finds all files associated with a run and saves them locally.
import wandb
api = wandb.Api()
run = api.run("<entity>/<project>/<run_id>")
for file in run.files():
file.download()
Get runs from a specific sweep
This snippet downloads all the runs associated with a particular sweep.
The best_run is the run with the best metric as defined by the metric parameter in the sweep config.
Download the best model file from a sweep
This snippet downloads the model file with the highest validation accuracy from a sweep with runs that saved model files to model.h5.
import wandb
api = wandb.Api()
sweep = api.sweep("<entity>/<project>/<sweep_id>")
runs = sorted(sweep.runs, key=lambda run: run.summary.get("val_acc", 0), reverse=True)
val_acc = runs[0].summary.get("val_acc", 0)
print(f"Best run {runs[0].name} with {val_acc}% val accuracy")
runs[0].file("model.h5").download(replace=True)
print("Best model saved to model-best.h5")
Delete all files with a given extension from a run
This snippet deletes files with a given extension from a run.
import wandb
api = wandb.Api()
run = api.run("<entity>/<project>/<run_id>")
extension =".png"files = run.files()
for file in files:
if file.name.endswith(extension):
file.delete()
Download system metrics data
This snippet produces a dataframe with all the system resource consumption metrics for a run and then saves it to a CSV.
import wandb
api = wandb.Api()
run = api.run("<entity>/<project>/<run_id>")
system_metrics = run.history(stream="events")
system_metrics.to_csv("sys_metrics.csv")
Update summary metrics
You can pass a dictionary to update summary metrics.
summary.update({"key": val})
Get the command that ran the run
Each run captures the command that launched it on the run overview page. To pull this command down from the API, you can run:
import wandb
api = wandb.Api()
run = api.run("<entity>/<project>/<run_id>")
meta = json.load(run.file("wandb-metadata.json").download())
program = ["python"] + [meta["program"]] + meta["args"]
1.11 - Environment variables
Set W&B environment variables.
When you’re running a script in an automated environment, you can control wandb with environment variables set before the script runs or within the script.
# This is secret and shouldn't be checked into version controlWANDB_API_KEY=$YOUR_API_KEY
# Name and notes optionalWANDB_NAME="My first run"WANDB_NOTES="Smaller learning rate, more regularization."
# Only needed if you don't check in the wandb/settings fileWANDB_ENTITY=$username
WANDB_PROJECT=$project
# If you don't want your script to sync to the cloudos.environ["WANDB_MODE"] ="offline"# Add sweep ID tracking to Run objects and related classesos.environ["WANDB_SWEEP_ID"] ="b05fq58z"
Optional environment variables
Use these optional environment variables to do things like set up authentication on remote machines.
Variable name
Usage
WANDB_ANONYMOUS
Set this to allow, never, or must to let users create anonymous runs with secret urls.
WANDB_API_KEY
Sets the authentication key associated with your account. You can find your key on your settings page. This must be set if wandb login hasn’t been run on the remote machine.
WANDB_BASE_URL
If you’re using wandb/local you should set this environment variable to http://YOUR_IP:YOUR_PORT
WANDB_CACHE_DIR
This defaults to ~/.cache/wandb, you can override this location with this environment variable
WANDB_CONFIG_DIR
This defaults to ~/.config/wandb, you can override this location with this environment variable
WANDB_CONFIG_PATHS
Comma separated list of yaml files to load into wandb.config. See config.
WANDB_CONSOLE
Set this to “off” to disable stdout / stderr logging. This defaults to “on” in environments that support it.
WANDB_DATA_DIR
The location where staging artifacts are uploaded. The default location depends on your platform, because it uses the value of user_data_dir from the platformdirs Python package.
WANDB_DIR
Set this to an absolute path to store all generated files here instead of the wandb directory relative to your training script. be sure this directory exists and the user your process runs as can write to it. Note that this does not affect the location of downloaded artifacts, which can instead be set using WANDB_ARTIFACT_DIR
WANDB_ARTIFACT_DIR
Set this to an absolute path to store all downloaded artifacts here instead of the artifacts directory relative to your training script. Make sure this directory exists and the user your process runs as can write to it. Note that this does not affect the location of generated metadata files, which can instead be set using WANDB_DIR
WANDB_DISABLE_GIT
Prevent wandb from probing for a git repository and capturing the latest commit / diff.
WANDB_DISABLE_CODE
Set this to true to prevent wandb from saving notebooks or git diffs. We’ll still save the current commit if we’re in a git repo.
WANDB_DOCKER
Set this to a docker image digest to enable restoring of runs. This is set automatically with the wandb docker command. You can obtain an image digest by running wandb docker my/image/name:tag --digest
WANDB_ENTITY
The entity associated with your run. If you have run wandb init in the directory of your training script, it will create a directory named wandb and will save a default entity which can be checked into source control. If you don’t want to create that file or want to override the file you can use the environmental variable.
WANDB_ERROR_REPORTING
Set this to false to prevent wandb from logging fatal errors to its error tracking system.
WANDB_HOST
Set this to the hostname you want to see in the wandb interface if you don’t want to use the system provided hostname
WANDB_IGNORE_GLOBS
Set this to a comma separated list of file globs to ignore. These files will not be synced to the cloud.
WANDB_JOB_NAME
Specify a name for any jobs created by wandb.
WANDB_JOB_TYPE
Specify the job type, like “training” or “evaluation” to indicate different types of runs. See grouping for more info.
WANDB_MODE
If you set this to “offline” wandb will save your run metadata locally and not sync to the server. If you set this to disabled wandb will turn off completely.
WANDB_NAME
The human-readable name of your run. If not set it will be randomly generated for you
WANDB_NOTEBOOK_NAME
If you’re running in jupyter you can set the name of the notebook with this variable. We attempt to auto detect this.
WANDB_NOTES
Longer notes about your run. Markdown is allowed and you can edit this later in the UI.
WANDB_PROJECT
The project associated with your run. This can also be set with wandb init, but the environmental variable will override the value.
WANDB_RESUME
By default this is set to never. If set to auto wandb will automatically resume failed runs. If set to must forces the run to exist on startup. If you want to always generate your own unique ids, set this to allow and always set WANDB_RUN_ID.
WANDB_RUN_GROUP
Specify the experiment name to automatically group runs together. See grouping for more info.
WANDB_RUN_ID
Set this to a globally unique string (per project) corresponding to a single run of your script. It must be no longer than 64 characters. All non-word characters will be converted to dashes. This can be used to resume an existing run in cases of failure.
WANDB_SILENT
Set this to true to silence wandb log statements. If this is set all logs will be written to WANDB_DIR/debug.log
WANDB_SHOW_RUN
Set this to true to automatically open a browser with the run url if your operating system supports it.
WANDB_SWEEP_ID
Add sweep ID tracking to Run objects and related classes, and display in the UI.
WANDB_TAGS
A comma separated list of tags to be applied to the run.
WANDB_USERNAME
The username of a member of your team associated with the run. This can be used along with a service account API key to enable attribution of automated runs to members of your team.
WANDB_USER_EMAIL
The email of a member of your team associated with the run. This can be used along with a service account API key to enable attribution of automated runs to members of your team.
Singularity environments
If you’re running containers in Singularity you can pass environment variables by pre-pending the above variables with SINGULARITYENV_. More details about Singularity environment variables can be found here.
Running on AWS
If you’re running batch jobs in AWS, it’s easy to authenticate your machines with your W&B credentials. Get your API key from your settings page, and set the WANDB_API_KEY environment variable in the AWS batch job spec.
2 - Sweeps
Hyperparameter search and model optimization with W&B Sweeps
Use W&B Sweeps to automate hyperparameter search and visualize rich, interactive experiment tracking. Pick from popular search methods such as Bayesian, grid search, and random to search the hyperparameter space. Scale and parallelize sweep across one or more machines.
The preceding code snippet, and the colab linked on this page, show how to initialize and create a sweep with wht W&B CLI. See the Sweeps Walkthrough for a step-by-step outline of the W&B Python SDK commands to use to define a sweep configuration, initialize a sweep, and start a sweep.
How to get started
Depending on your use case, explore the following resources to get started with W&B Sweeps:
Read through the sweeps walkthrough for a step-by-step outline of the W&B Python SDK commands to use to define a sweep configuration, initialize a sweep, and start a sweep.
The following sections break down and explains each step in the code sample.
Set up your training code
Define a training function that takes in hyperparameter values from wandb.config and uses them to train a model and return metrics.
Optionally provide the name of the project where you want the output of the W&B Run to be stored (project parameter in wandb.init). If the project is not specified, the run is put in an “Uncategorized” project.
Both the sweep and the run must be in the same project. Therefore, the name you provide when you initialize W&B must match the name of the project you provide when you initialize a sweep.
Define the search space with a sweep configuration
Specify the hyperparameters to sweep in a dictionary. For configuration options, see Define sweep configuration.
The proceeding example demonstrates a sweep configuration that uses a random search ('method':'random'). The sweep will randomly select a random set of values listed in the configuration for the batch size, epoch, and the learning rate.
W&B minimizes the metric specified in the metric key when "goal": "minimize" is associated with it. In this case, W&B will optimize for minimizing the metric score ("name": "score").
W&B uses a Sweep Controller to manage sweeps on the cloud (standard), locally (local) across one or more machines. For more information about Sweep Controllers, see Search and stop algorithms locally.
A sweep identification number is returned when you initialize a sweep:
In the terminal, press Ctrl+C to stop the current run. Press it again to terminate the agent.
2.2 - Add W&B (wandb) to your code
Add W&B to your Python code script or Jupyter Notebook.
There are numerous ways to add the W&B Python SDK to your script or Jupyter Notebook. Outlined below is a “best practice” example of how to integrate the W&B Python SDK into your own code.
Original training script
Suppose you have the following code in a Python script. We define a function called main that mimics a typical training loop. For each epoch, the accuracy and loss is computed on the training and validation data sets. The values are randomly generated for the purpose of this example.
We defined a dictionary called config where we store hyperparameters values. At the end of the cell, we call the main function to execute the mock training code.
import random
import numpy as np
deftrain_one_epoch(epoch, lr, bs):
acc =0.25+ ((epoch /30) + (random.random() /10))
loss =0.2+ (1- ((epoch -1) /10+ random.random() /5))
return acc, loss
defevaluate_one_epoch(epoch):
acc =0.1+ ((epoch /20) + (random.random() /10))
loss =0.25+ (1- ((epoch -1) /10+ random.random() /6))
return acc, loss
# config variable with hyperparameter valuesconfig = {"lr": 0.0001, "bs": 16, "epochs": 5}
defmain():
# Note that we define values from `wandb.config`# instead of defining hard values lr = config["lr"]
bs = config["bs"]
epochs = config["epochs"]
for epoch in np.arange(1, epochs):
train_acc, train_loss = train_one_epoch(epoch, lr, bs)
val_acc, val_loss = evaluate_one_epoch(epoch)
print("epoch: ", epoch)
print("training accuracy:", train_acc, "training loss:", train_loss)
print("validation accuracy:", val_acc, "training loss:", val_loss)
Training script with W&B Python SDK
The following code examples demonstrate how to add the W&B Python SDK into your code. If you start W&B Sweep jobs in the CLI, you will want to explore the CLI tab. If you start W&B Sweep jobs within a Jupyter notebook or Python script, explore the Python SDK tab.
To create a W&B Sweep, we added the following to the code example:
Import the Weights & Biases Python SDK.
Create a dictionary object where the key-value pairs define the sweep configuration. In the proceeding example, the batch size (batch_size), epochs (epochs), and the learning rate (lr) hyperparameters are varied during each sweep. For more information on how to create a sweep configuration, see Define sweep configuration.
Pass the sweep configuration dictionary to wandb.sweep. This initializes the sweep. This returns a sweep ID (sweep_id). For more information on how to initialize sweeps, see Initialize sweeps.
Use the wandb.init() API to generate a background process to sync and log data as a W&B Run.
(Optional) define values from wandb.config instead of defining hard coded values.
Log the metric we want to optimize with wandb.log. You must log the metric defined in your configuration. Within the configuration dictionary (sweep_configuration in this example) we defined the sweep to maximize the val_acc value.
Start the sweep with the wandb.agent API call. Provide the sweep ID, the name of the function the sweep will execute (function=main), and set the maximum number of runs to try to four (count=4). For more information on how to start W&B Sweep, see Start sweep agents.
import wandb
import numpy as np
import random
# Define sweep configsweep_configuration = {
"method": "random",
"name": "sweep",
"metric": {"goal": "maximize", "name": "val_acc"},
"parameters": {
"batch_size": {"values": [16, 32, 64]},
"epochs": {"values": [5, 10, 15]},
"lr": {"max": 0.1, "min": 0.0001},
},
}
# Initialize sweep by passing in config.# (Optional) Provide a name of the project.sweep_id = wandb.sweep(sweep=sweep_configuration, project="my-first-sweep")
# Define training function that takes in hyperparameter# values from `wandb.config` and uses them to train a# model and return metricdeftrain_one_epoch(epoch, lr, bs):
acc =0.25+ ((epoch /30) + (random.random() /10))
loss =0.2+ (1- ((epoch -1) /10+ random.random() /5))
return acc, loss
defevaluate_one_epoch(epoch):
acc =0.1+ ((epoch /20) + (random.random() /10))
loss =0.25+ (1- ((epoch -1) /10+ random.random() /6))
return acc, loss
defmain():
run = wandb.init()
# note that we define values from `wandb.config`# instead of defining hard values lr = wandb.config.lr
bs = wandb.config.batch_size
epochs = wandb.config.epochs
for epoch in np.arange(1, epochs):
train_acc, train_loss = train_one_epoch(epoch, lr, bs)
val_acc, val_loss = evaluate_one_epoch(epoch)
wandb.log(
{
"epoch": epoch,
"train_acc": train_acc,
"train_loss": train_loss,
"val_acc": val_acc,
"val_loss": val_loss,
}
)
# Start sweep job.wandb.agent(sweep_id, function=main, count=4)
To create a W&B Sweep, we first create a YAML configuration file. The configuration file contains he hyperparameters we want the sweep to explore. In the proceeding example, the batch size (batch_size), epochs (epochs), and the learning rate (lr) hyperparameters are varied during each sweep.
Note that you must provide the name of your Python script for the program key in your YAML file.
Next, we add the following to the code example:
Import the Wieghts & Biases Python SDK (wandb) and PyYAML (yaml). PyYAML is used to read in our YAML configuration file.
Read in the configuration file.
Use the wandb.init() API to generate a background process to sync and log data as a W&B Run. We pass the config object to the config parameter.
Define hyperparameter values from wandb.config instead of using hard coded values.
Log the metric we want to optimize with wandb.log. You must log the metric defined in your configuration. Within the configuration dictionary (sweep_configuration in this example) we defined the sweep to maximize the val_acc value.
import wandb
import yaml
import random
import numpy as np
deftrain_one_epoch(epoch, lr, bs):
acc =0.25+ ((epoch /30) + (random.random() /10))
loss =0.2+ (1- ((epoch -1) /10+ random.random() /5))
return acc, loss
defevaluate_one_epoch(epoch):
acc =0.1+ ((epoch /20) + (random.random() /10))
loss =0.25+ (1- ((epoch -1) /10+ random.random() /6))
return acc, loss
defmain():
# Set up your default hyperparameterswith open("./config.yaml") as file:
config = yaml.load(file, Loader=yaml.FullLoader)
run = wandb.init(config=config)
# Note that we define values from `wandb.config`# instead of defining hard values lr = wandb.config.lr
bs = wandb.config.batch_size
epochs = wandb.config.epochs
for epoch in np.arange(1, epochs):
train_acc, train_loss = train_one_epoch(epoch, lr, bs)
val_acc, val_loss = evaluate_one_epoch(epoch)
wandb.log(
{
"epoch": epoch,
"train_acc": train_acc,
"train_loss": train_loss,
"val_acc": val_acc,
"val_loss": val_loss,
}
)
# Call the main function.main()
Navigate to your CLI. Within your CLI, set a maximum number of runs the sweep agent should try. This is step optional. In the following example we set the maximum number to five.
NUM=5
Next, initialize the sweep with the wandb sweep command. Provide the name of the YAML file. Optionally provide the name of the project for the project flag (--project):
wandb sweep --project sweep-demo-cli config.yaml
This returns a sweep ID. For more information on how to initialize sweeps, see Initialize sweeps.
Copy the sweep ID and replace sweepID in the proceeding code snippet to start the sweep job with the wandb agent command:
For more information on how to start sweep jobs, see Start sweep jobs.
Consideration when logging metrics
Ensure to log the metric you specify in your sweep configuration explicitly to W&B. Do not log metrics for your sweep inside of a sub-directory.
For example, consider the proceeding psuedocode. A user wants to log the validation loss ("val_loss": loss). First they pass the values into a dictionary. However, the dictionary passed to wandb.log does not explicitly access the key-value pair in the dictionary:
# Import the W&B Python Library and log into W&Bimport wandb
import random
deftrain():
offset = random.random() /5 acc =1-2**-epoch - random.random() / epoch - offset
loss =2**-epoch + random.random() / epoch + offset
val_metrics = {"val_loss": loss, "val_acc": acc}
return val_metrics
defmain():
wandb.init(entity="<entity>", project="my-first-sweep")
val_metrics = train()
# Incorrect. You must explicitly access the# key-value pair in the dictionary# See next code block to see how to correctly log metrics wandb.log({"val_loss": val_metrics})
sweep_configuration = {
"method": "random",
"metric": {"goal": "minimize", "name": "val_loss"},
"parameters": {
"x": {"max": 0.1, "min": 0.01},
"y": {"values": [1, 3, 7]},
},
}
sweep_id = wandb.sweep(sweep=sweep_configuration, project="my-first-sweep")
wandb.agent(sweep_id, function=main, count=10)
Instead, explicitly access the key-value pair within the Python dictionary. For example, the proceeding code specifies the key-value pair when you pass the dictionary to the wandb.log method:
Learn how to create configuration files for sweeps.
A W&B Sweep combines a strategy for exploring hyperparameter values with the code that evaluates them. The strategy can be as simple as trying every option or as complex as Bayesian Optimization and Hyperband (BOHB).
Define a sweep configuration either in a Python dictionary or a YAML file. How you define your sweep configuration depends on how you want to manage your sweep.
Define your sweep configuration in a YAML file if you want to initialize a sweep and start a sweep agent from the command line. Define your sweep in a Python dictionary if you initialize a sweep and start a sweep entirely within a Python script or Jupyter notebook.
The following guide describes how to format your sweep configuration. See Sweep configuration options for a comprehensive list of top-level sweep configuration keys.
Basic structure
Both sweep configuration format options (YAML and Python dictionary) utilize key-value pairs and nested structures.
Use top-level keys within your sweep configuration to define qualities of your sweep search such as the name of the sweep (name key), the parameters to search through (parameters key), the methodology to search the parameter space (method key), and more.
For example, the proceeding code snippets show the same sweep configuration defined within a YAML file and within a Python dictionary. Within the sweep configuration there are five top level keys specified: program, name, method, metric and parameters.
Define a sweep configuration in a YAML file if you want to manage sweeps interactively from the command line (CLI)
Within the top level parameters key, the following keys are nested: learning_rate, batch_size, epoch, and optimizer. For each of the nested keys you specify, you can provide one or more values, a distribution, a probability, and more. For more information, see the parameters section in Sweep configuration options.
Double nested parameters
Sweep configurations support nested parameters. To delineate a nested parameter, use an additional parameters key under the top level parameter name. Sweep configs support multi-level nesting.
Specify a probability distribution for your random variables if you use a Bayesian or random hyperparameter search. For each hyperparameter:
Create a top level parameters key in your sweep config.
Within the parameterskey, nest the following:
Specify the name of hyperparameter you want to optimize.
Specify the distribution you want to use for the distribution key. Nest the distribution key-value pair underneath the hyperparameter name.
Specify one or more values to explore. The value (or values) should be inline with the distribution key.
(Optional) Use an additional parameters key under the top level parameter name to delineate a nested parameter.
Nested parameters defined in sweep configuration overwrite keys specified in a W&B run configuration.
For example, suppose you initialize a W&B run with the following configuration in a train.py Python script (see Lines 1-2). Next, you define a sweep configuration in a dictionary called sweep_configuration (see Lines 4-13). You then pass the sweep config dictionary to wandb.sweep to initialize a sweep config (see Line 16).
The nested_param.manual_key that is passed when the W&B run is initialized is not accessible. The run.config only possess the key-value pairs that are defined in the sweep configuration dictionary.
Sweep configuration template
The following template shows how you can configure parameters and specify search constraints. Replace hyperparameter_name with the name of your hyperparameter and any values enclosed in <>.
The proceeding tabs show how to specify common command macros:
Remove the {$interpreter} macro and provide a value explicitly to hardcode the python interpreter. For example, the following code snippet demonstrates how to do this:
If your program does not use argument parsing you can avoid passing arguments all together and take advantage of wandb.init picking up sweep parameters into wandb.config automatically:
command:
- ${env} - ${interpreter} - ${program}
You can change the command to pass arguments the way tools like Hydra expect. See Hydra with W&B for more information.
A sweep configuration consists of nested key-value pairs. Use top-level keys within your sweep configuration to define qualities of your sweep search such as the parameters to search through (parameter key), the methodology to search the parameter space (method key), and more.
The proceeding table lists top-level sweep configuration keys and a brief description. See the respective sections for more information about each key.
Command structure for invoking and passing arguments to the training script
run_cap
Maximum number of runs for this sweep
See the Sweep configuration structure for more information on how to structure your sweep configuration.
metric
Use the metric top-level sweep configuration key to specify the name, the goal, and the target metric to optimize.
Key
Description
name
Name of the metric to optimize.
goal
Either minimize or maximize (Default is minimize).
target
Goal value for the metric you are optimizing. The sweep does not create new runs when if or when a run reaches a target value that you specify. Active agents that have a run executing (when the run reaches the target) wait until the run completes before the agent stops creating new runs.
parameters
In your YAML file or Python script, specify parameters as a top level key. Within the parameters key, provide the name of a hyperparameter you want to optimize. Common hyperparameters include: learning rate, batch size, epochs, optimizers, and more. For each hyperparameter you define in your sweep configuration, specify one or more search constraints.
The proceeding table shows supported hyperparameter search constraints. Based on your hyperparameter and use case, use one of the search constraints below to tell your sweep agent where (in the case of a distribution) or what (value, values, and so forth) to search or use.
Search constraint
Description
values
Specifies all valid values for this hyperparameter. Compatible with grid.
value
Specifies the single valid value for this hyperparameter. Compatible with grid.
distribution
Specify a probability distribution. See the note following this table for information on default values.
probabilities
Specify the probability of selecting each element of values when using random.
min, max
(intor float) Maximum and minimum values. If int, for int_uniform -distributed hyperparameters. If float, for uniform -distributed hyperparameters.
mu
(float) Mean parameter for normal - or lognormal -distributed hyperparameters.
sigma
(float) Standard deviation parameter for normal - or lognormal -distributed hyperparameters.
q
(float) Quantization step size for quantized hyperparameters.
parameters
Nest other parameters inside a root level parameter.
W&B sets the following distributions based on the following conditions if a distribution is not specified:
categorical if you specify values
int_uniform if you specify max and min as integers
uniform if you specify max and min as floats
constant if you provide a set to value
method
Specify the hyperparameter search strategy with the method key. There are three hyperparameter search strategies to choose from: grid, random, and Bayesian search.
Grid search
Iterate over every combination of hyperparameter values. Grid search makes uninformed decisions on the set of hyperparameter values to use on each iteration. Grid search can be computationally costly.
Grid search executes forever if it is searching within in a continuous search space.
Random search
Choose a random, uninformed, set of hyperparameter values on each iteration based on a distribution. Random search runs forever unless you stop the process from the command line, within your python script, or the W&B App UI.
Specify the distribution space with the metric key if you choose random (method: random) search.
Bayesian search
In contrast to random and grid search, Bayesian models make informed decisions. Bayesian optimization uses a probabilistic model to decide which values to use through an iterative process of testing values on a surrogate function before evaluating the objective function. Bayesian search works well for small numbers of continuous parameters but scales poorly. For more information about Bayesian search, see the Bayesian Optimization Primer paper.
Bayesian search runs forever unless you stop the process from the command line, within your python script, or the W&B App UI.
Distribution options for random and Bayesian search
Within the parameter key, nest the name of the hyperparameter. Next, specify the distribution key and specify a distribution for the value.
The proceeding tables lists distributions W&B supports.
Value for distribution key
Description
constant
Constant distribution. Must specify the constant value (value) to use.
categorical
Categorical distribution. Must specify all valid values (values) for this hyperparameter.
int_uniform
Discrete uniform distribution on integers. Must specify max and min as integers.
uniform
Continuous uniform distribution. Must specify max and min as floats.
q_uniform
Quantized uniform distribution. Returns round(X / q) * q where X is uniform. q defaults to 1.
log_uniform
Log-uniform distribution. Returns a value X between exp(min) and exp(max)such that the natural logarithm is uniformly distributed between min and max.
log_uniform_values
Log-uniform distribution. Returns a value X between min and max such that log(X) is uniformly distributed between log(min) and log(max).
q_log_uniform
Quantized log uniform. Returns round(X / q) * q where X is log_uniform. q defaults to 1.
q_log_uniform_values
Quantized log uniform. Returns round(X / q) * q where X is log_uniform_values. q defaults to 1.
inv_log_uniform
Inverse log uniform distribution. Returns X, where log(1/X) is uniformly distributed between min and max.
inv_log_uniform_values
Inverse log uniform distribution. Returns X, where log(1/X) is uniformly distributed between log(1/max) and log(1/min).
normal
Normal distribution. Return value is normally distributed with mean mu (default 0) and standard deviation sigma (default 1).
q_normal
Quantized normal distribution. Returns round(X / q) * q where X is normal. Q defaults to 1.
log_normal
Log normal distribution. Returns a value X such that the natural logarithm log(X) is normally distributed with mean mu (default 0) and standard deviation sigma (default 1).
q_log_normal
Quantized log normal distribution. Returns round(X / q) * q where X is log_normal. q defaults to 1.
early_terminate
Use early termination (early_terminate) to stop poorly performing runs. If early termination occurs, W&B stops the current run before it creates a new run with a new set of hyperparameter values.
You must specify a stopping algorithm if you use early_terminate. Nest the type key within early_terminate within your sweep configuration.
Stopping algorithm
W&B currently supports Hyperband stopping algorithm.
Hyperband hyperparameter optimization evaluates if a program should stop or if it should to continue at one or more pre-set iteration counts, called brackets.
When a W&B run reaches a bracket, the sweep compares that run’s metric to all previously reported metric values. The sweep terminates the run if the run’s metric value is too high (when the goal is minimization) or if the run’s metric is too low (when the goal is maximization).
Brackets are based on the number of logged iterations. The number of brackets corresponds to the number of times you log the metric you are optimizing. The iterations can correspond to steps, epochs, or something in between. The numerical value of the step counter is not used in bracket calculations.
Specify either min_iter or max_iter to create a bracket schedule.
Key
Description
min_iter
Specify the iteration for the first bracket
max_iter
Specify the maximum number of iterations.
s
Specify the total number of brackets (required for max_iter)
eta
Specify the bracket multiplier schedule (default: 3).
strict
Enable ‘strict’ mode that prunes runs aggressively, more closely following the original Hyperband paper. Defaults to false.
Hyperband checks which W&B runs to end once every few minutes. The end run timestamp might differ from the specified brackets if your run or iteration are short.
command
Modify the format and contents with nested values within the command key. You can directly include fixed components such as filenames.
On Unix systems, /usr/bin/env ensures that the OS chooses the correct Python interpreter based on the environment.
W&B supports the following macros for variable components of the command:
Command macro
Description
${env}
/usr/bin/env on Unix systems, omitted on Windows.
${interpreter}
Expands to python.
${program}
Training script filename specified by the sweep configuration program key.
${args}
Hyperparameters and their values in the form --param1=value1 --param2=value2.
${args_no_boolean_flags}
Hyperparameters and their values in the form --param1=value1 except boolean parameters are in the form --boolean_flag_param when True and omitted when False.
${args_no_hyphens}
Hyperparameters and their values in the form param1=value1 param2=value2.
${args_json}
Hyperparameters and their values encoded as JSON.
${args_json_file}
The path to a file containing the hyperparameters and their values encoded as JSON.
${envvar}
A way to pass environment variables. ${envvar:MYENVVAR} __ expands to the value of MYENVVAR environment variable. __
2.4 - Initialize a sweep
Initialize a W&B Sweep
W&B uses a Sweep Controller to manage sweeps on the cloud (standard), locally (local) across one or more machines. After a run completes, the sweep controller will issue a new set of instructions describing a new run to execute. These instructions are picked up by agents who actually perform the runs. In a typical W&B Sweep, the controller lives on the W&B server. Agents live on your machines.
The following code snippets demonstrate how to initialize sweeps with the CLI and within a Jupyter Notebook or Python script.
Before you initialize a sweep, make sure you have a sweep configuration defined either in a YAML file or a nested Python dictionary object in your script. For more information see, Define sweep configuration.
Both the W&B Sweep and the W&B Run must be in the same project. Therefore, the name you provide when you initialize W&B (wandb.init) must match the name of the project you provide when you initialize a W&B Sweep (wandb.sweep).
Use the W&B SDK to initialize a sweep. Pass the sweep configuration dictionary to the sweep parameter. Optionally provide the name of the project for the project parameter (project) where you want the output of the W&B Run to be stored. If the project is not specified, the run is put in an “Uncategorized” project.
The wandb.sweep function returns the sweep ID. The sweep ID includes the entity name and the project name. Make a note of the sweep ID.
Use the W&B CLI to initialize a sweep. Provide the name of your configuration file. Optionally provide the name of the project for the project flag. If the project is not specified, the W&B Run is put in an “Uncategorized” project.
Use the wandb sweep command to initialize a sweep. The proceeding code example initializes a sweep for a sweeps_demo project and uses a config.yaml file for the configuration.
wandb sweep --project sweeps_demo config.yaml
This command will print out a sweep ID. The sweep ID includes the entity name and the project name. Make a note of the sweep ID.
2.5 - Start or stop a sweep agent
Start or stop a W&B Sweep Agent on one or more machines.
Start a W&B Sweep on one or more agents on one or more machines. W&B Sweep agents query the W&B server you launched when you initialized a W&B Sweep (wandb sweep) for hyperparameters and use them to run model training.
To start a W&B Sweep agent, provide the W&B Sweep ID that was returned when you initialized a W&B Sweep. The W&B Sweep ID has the form:
entity/project/sweep_ID
Where:
entity: Your W&B username or team name.
project: The name of the project where you want the output of the W&B Run to be stored. If the project is not specified, the run is put in an “Uncategorized” project.
sweep_ID: The pseudo random, unique ID generated by W&B.
Provide the name of the function the W&B Sweep will execute if you start a W&B Sweep agent within a Jupyter Notebook or Python script.
The proceeding code snippets demonstrate how to start an agent with W&B. We assume you already have a configuration file and you have already initialized a W&B Sweep. For more information about how to define a configuration file, see Define sweep configuration.
Use the wandb agent command to start a sweep. Provide the sweep ID that was returned when you initialized the sweep. Copy and paste the code snippet below and replace sweep_id with your sweep ID:
wandb agent sweep_id
Use the W&B Python SDK library to start a sweep. Provide the sweep ID that was returned when you initialized the sweep. In addition, provide the name of the function the sweep will execute.
Random and Bayesian searches will run forever. You must stop the process from the command line, within your python script, or the Sweeps UI.
Optionally specify the number of W&B Runs a Sweep agent should try. The following code snippets demonstrate how to set a maximum number of W&B Runs with the CLI and within a Jupyter Notebook, Python script.
First, initialize your sweep. For more information, see Initialize sweeps.
sweep_id = wandb.sweep(sweep_config)
Next, start the sweep job. Provide the sweep ID generated from sweep initiation. Pass an integer value to the count parameter to set the maximum number of runs to try.
If you start a new run after the sweep agent has finished, within the same script or notebook, then you should call wandb.teardown() before starting the new run.
Parallelize W&B Sweep agents on multi-core or multi-GPU machine.
Parallelize your W&B Sweep agents on a multi-core or multi-GPU machine. Before you get started, ensure you have initialized your W&B Sweep. For more information on how to initialize a W&B Sweep, see Initialize sweeps.
Parallelize on a multi-CPU machine
Depending on your use case, explore the proceeding tabs to learn how to parallelize W&B Sweep agents using the CLI or within a Jupyter Notebook.
Use the wandb agent command to parallelize your W&B Sweep agent across multiple CPUs with the terminal. Provide the sweep ID that was returned when you initialized the sweep.
Open more than one terminal window on your local machine.
Copy and paste the code snippet below and replace sweep_id with your sweep ID:
wandb agent sweep_id
Use the W&B Python SDK library to parallelize your W&B Sweep agent across multiple CPUs within Jupyter Notebooks. Ensure you have the sweep ID that was returned when you initialized the sweep. In addition, provide the name of the function the sweep will execute for the function parameter:
Open more than one Jupyter Notebook.
Copy and past the W&B Sweep ID on multiple Jupyter Notebooks to parallelize a W&B Sweep. For example, you can paste the following code snippet on multiple jupyter notebooks to paralleliz your sweep if you have the sweep ID stored in a variable called sweep_id and the name of the function is function_name:
Follow the procedure outlined to parallelize your W&B Sweep agent across multiple GPUs with a terminal using CUDA Toolkit:
Open more than one terminal window on your local machine.
Specify the GPU instance to use with CUDA_VISIBLE_DEVICES when you start a W&B Sweep job (wandb agent). Assign CUDA_VISIBLE_DEVICES an integer value corresponding to the GPU instance to use.
For example, suppose you have two NVIDIA GPUs on your local machine. Open a terminal window and set CUDA_VISIBLE_DEVICES to 0 (CUDA_VISIBLE_DEVICES=0). Replace sweep_ID in the proceeding example with the W&B Sweep ID that is returned when you initialized a W&B Sweep:
Terminal 1
CUDA_VISIBLE_DEVICES=0 wandb agent sweep_ID
Open a second terminal window. Set CUDA_VISIBLE_DEVICES to 1 (CUDA_VISIBLE_DEVICES=1). Paste the same W&B Sweep ID for the sweep_ID mentioned in the proceeding code snippet:
Terminal 2
CUDA_VISIBLE_DEVICES=1 wandb agent sweep_ID
2.7 - Visualize sweep results
Visualize the results of your W&B Sweeps with the W&B App UI.
Visualize the results of your W&B Sweeps with the W&B App UI. Navigate to the W&B App UI at https://wandb.ai/home. Choose the project that you specified when you initialized a W&B Sweep. You will be redirected to your project workspace. Select the Sweep icon on the left panel (broom icon). From the Sweep UI, select the name of your Sweep from the list.
By default, W&B will automatically create a parallel coordinates plot, a parameter importance plot, and a scatter plot when you start a W&B Sweep job.
Parallel coordinates charts summarize the relationship between large numbers of hyperparameters and model metrics at a glance. For more information on parallel coordinates plots, see Parallel coordinates.
The scatter plot(left) compares the W&B Runs that were generated during the Sweep. For more information about scatter plots, see Scatter Plots.
The parameter importance plot(right) lists the hyperparameters that were the best predictors of, and highly correlated to desirable values of your metrics. For more information parameter importance plots, see Parameter Importance.
You can alter the dependent and independent values (x and y axis) that are automatically used. Within each panel there is a pencil icon called Edit panel. Choose Edit panel. A model will appear. Within the modal, you can alter the behavior of the graph.
For more information on all default W&B visualization options, see Panels. See the Data Visualization docs for information on how to create plots from W&B Runs that are not part of a W&B Sweep.
2.8 - Manage sweeps with the CLI
Pause, resume, and cancel a W&B Sweep with the CLI.
Pause, resume, and cancel a W&B Sweep with the CLI. Pausing a W&B Sweep tells the W&B agent that new W&B Runs should not be executed until the Sweep is resumed. Resuming a Sweep tells the agent to continue executing new W&B Runs. Stopping a W&B Sweep tells the W&B Sweep agent to stop creating or executing new W&B Runs. Cancelling a W&B Sweep tells the Sweep agent to kill currently executing W&B Runs and stop executing new Runs.
In each case, provide the W&B Sweep ID that was generated when you initialized a W&B Sweep. Optionally open a new terminal window to execute the proceeding commands. A new terminal window makes it easier to execute a command if a W&B Sweep is printing output statements to your current terminal window.
Use the following guidance to pause, resume, and cancel sweeps.
Pause sweeps
Pause a W&B Sweep so it temporarily stops executing new W&B Runs. Use the wandb sweep --pause command to pause a W&B Sweep. Provide the W&B Sweep ID that you want to pause.
wandb sweep --pause entity/project/sweep_ID
Resume sweeps
Resume a paused W&B Sweep with the wandb sweep --resume command. Provide the W&B Sweep ID that you want to resume:
wandb sweep --resume entity/project/sweep_ID
Stop sweeps
Finish a W&B sweep to stop executing newW&B Runs and let currently executing Runs finish.
wandb sweep --stop entity/project/sweep_ID
Cancel sweeps
Cancel a sweep to kill all running runs and stop running new runs. Use the wandb sweep --cancel command to cancel a W&B Sweep. Provide the W&B Sweep ID that you want to cancel.
wandb sweep --cancel entity/project/sweep_ID
For a full list of CLI command options, see the wandb sweep CLI Reference Guide.
Pause, resume, stop, and cancel a sweep across multiple agents
Pause, resume, stop, or cancel a W&B Sweep across multiple agents from a single terminal. For example, suppose you have a multi-core machine. After you initialize a W&B Sweep, you open new terminal windows and copy the Sweep ID to each new terminal.
Within any terminal, use the wandb sweep CLI command to pause, resume, stop, or cancel a W&B Sweep. For example, the proceeding code snippet demonstrates how to pause a W&B Sweep across multiple agents with the CLI:
wandb sweep --pause entity/project/sweep_ID
Specify the --resume flag along with the Sweep ID to resume the Sweep across your agents:
wandb sweep --resume entity/project/sweep_ID
For more information on how to parallelize W&B agents, see Parallelize agents.
Description: We examine agents trained with different side effect penalties on three different tasks: pattern creation, pattern removal, and navigation.
Description: How do we distinguish signal from pareidolia (imaginary patterns)? This article is showcases what is possible with W&B and aims to inspire further exploration.
Description: Explore why hyperparameter optimization matters and look at three algorithms to automate hyperparameter tuning for your machine learning models.
selfm-anaged
The following how-to-guide demonstrates how to solve real-world problems with W&B:
Description: How to use W&B Sweeps for hyperparameter tuning using XGBoost.
Sweep GitHub repository
W&B advocates open source and welcome contributions from the community. Find the GitHub repository at https://github.com/wandb/sweeps. For information on how to contribute to the W&B open source repo, see the W&B GitHub Contribution guidelines.
2.10 - Manage algorithms locally
Search and stop algorithms locally instead of using the W&B cloud-hosted service.
The hyper-parameter controller is hosted by Weights & Biased as a cloud service by default. W&B agents communicate with the controller to determine the next set of parameters to use for training. The controller is also responsible for running early stopping algorithms to determine which runs can be stopped.
The local controller feature allows the user to commence search and stop algorithms locally. The local controller gives the user the ability to inspect and instrument the code in order to debug issues as well as develop new features which can be incorporated into the cloud service.
This feature is offered to support faster development and debugging of new algorithms for the Sweeps tool. It is not intended for actual hyperparameter optimization workloads.
Before you get start, you must install the W&B SDK(wandb). Type the following code snippet into your command line:
pip install wandb sweeps
The following examples assume you already have a configuration file and a training loop defined in a python script or Jupyter Notebook. For more information about how to define a configuration file, see Define sweep configuration.
Run the local controller from the command line
Initialize a sweep similarly to how you normally would when you use hyper-parameter controllers hosted by W&B as a cloud service. Specify the controller flag (controller) to indicate you want to use the local controller for W&B sweep jobs:
wandb sweep --controller config.yaml
Alternatively, you can separate initializing a sweep and specifying that you want to use a local controller into two steps.
To separate the steps, first add the following key-value to your sweep’s YAML configuration file:
controller:
type: local
Next, initialize the sweep:
wandb sweep config.yaml
After you initialized the sweep, start a controller with wandb controller:
# wandb sweep command will print a sweep_idwandb controller {user}/{entity}/{sweep_id}
Once you have specified you want to use a local controller, start one or more Sweep agents to execute the sweep. Start a W&B Sweep similar to how you normally would. See Start sweep agents, for more information.
wandb sweep sweep_ID
Run a local controller with W&B Python SDK
The following code snippets demonstrate how to specify and use a local controller with the W&B Python SDK.
The simplest way to use a controller with the Python SDK is to pass the sweep ID to the wandb.controller method. Next, use the return objects run method to start the sweep job:
Troubleshoot common error messages with the guidance suggested.
CommError, Run does not exist and ERROR Error uploading
Your W&B Run ID might be defined if these two error messages are both returned. As an example, you might have a similar code snippet defined somewhere in your Jupyter Notebooks or Python script:
wandb.init(id="some-string")
You can not set a Run ID for W&B Sweeps because W&B automatically generates random, unique IDs for Runs created by W&B Sweeps.
W&B Run IDs need to be unique within a project.
We recommend you pass a name to the name parameter when you initialized W&B, if you want to set a custom name that will appear on tables and graphs. For example:
wandb.init(name="a helpful readable run name")
Cuda out of memory
Refactor your code to use process-based executions if you see this error message. More specifically, rewrite your code to a Python script. In addition, call the W&B Sweep Agent from the CLI, instead of the W&B Python SDK.
As an example, suppose you rewrite your code to a Python script called train.py. Add the name of the training script (train.py) to your YAML Sweep configuration file (config.yaml in this example):
Next, add the following to your train.py Python script:
if _name_ =="_main_":
train()
Navigate to your CLI and initialize a W&B Sweep with wandb sweep:
wandb sweep config.yaml
Make a note of the W&B Sweep ID that is returned. Next, start the Sweep job with wandb agent with the CLI instead of the Python SDK (wandb.agent). Replace sweep_ID in the code snippet below with the Sweep ID that was returned in the previous step:
wandb agent sweep_ID
anaconda 400 error
The following error usually occurs when you do not log the metric that you are optimizing:
wandb: ERROR Error while calling W&B API: anaconda 400 error:
{"code": 400, "message": "TypeError: bad operand type for unary -: 'NoneType'"}
Within your YAML file or nested dictionary you specify a key named “metric” to optimize. Ensure that you log (wandb.log) this metric. In addition, ensure you use the exact metric name that you defined the sweep to optimize within your Python script or Jupyter Notebook. For more information about configuration files, see Define sweep configuration.
2.12 - Sweeps UI
Describes the different components of the Sweeps UI.
The state (State), creation time (Created), the entity that started the sweep (Creator), the number of runs completed (Run count), and the time it took to compute the sweep (Compute time) are displayed in the Sweeps UI. The expected number of runs a sweep will create (Est. Runs) is provided when you do a grid search over a discrete search space. You can also click on a sweep to pause, resume, stop, or kill the sweep from the interface.
2.13 - Tutorial: Create sweep job from project
Tutorial on how to create sweep jobs from a pre-existing W&B project.
First, create a baseline. Download the PyTorch MNIST dataset example model from W&B examples GitHub repository. Next, train the model. The training script is within the examples/pytorch/pytorch-cnn-fashion directory.
Clone this repo git clone https://github.com/wandb/examples.git
Open this example cd examples/pytorch/pytorch-cnn-fashion
Run a run manually python train.py
Optionally explore the example appear in the W&B App UI dashboard.
From your project page, open the Sweep tab in the sidebar and select Create Sweep.
The auto-generated configuration guesses values to sweep over based on the runs you have completed. Edit the configuration to specify what ranges of hyperparameters you want to try. When you launch the sweep, it starts a new process on the hosted W&B sweep server. This centralized service coordinates the agents— the machines that are running the training jobs.
3. Launch agents
Next, launch an agent locally. You can launch up to 20 agents on different machines in parallel if you want to distribute the work and finish the sweep job more quickly. The agent will print out the set of parameters it’s trying next.
Now you’re running a sweep. The following image demonstrates what the dashboard looks like as the example sweep job is running. View an example project page →
Seed a new sweep with existing runs
Launch a new sweep using existing runs that you’ve previously logged.
Open your project table.
Select the runs you want to use with checkboxes on the left side of the table.
Click the dropdown to create a new sweep.
Your sweep will now be set up on our server. All you need to do is launch one or more agents to start running runs.
If you kick off the new sweep as a bayesian sweep, the selected runs will also seed the Gaussian Process.
3 - Tables
Iterate on datasets and understand model predictions
A Table is a two-dimensional grid of data where each column has a single type of data. Tables support primitive and numeric types, as well as nested lists, dictionaries, and rich media types.
import wandb
run = wandb.init(project="table-test")
# Create and log a new table.my_table = wandb.Table(columns=["a", "b"], data=[["a1", "b1"], ["a2", "b2"]])
run.log({"Table Name": my_table})
Pass a Pandas Dataframe to wandb.Table() to create a new table.
import wandb
import pandas as pd
df = pd.read_csv("my_data.csv")
run = wandb.init(project="df-table")
my_table = wandb.Table(dataframe=df)
wandb.log({"Table Name": my_table})
For more information on supported data types, see the wandb.Table in the W&B API Reference Guide.
2. Visualize tables in your project workspace
View the resulting table in your workspace.
Navigate to your project in the W&B App.
Select the name of your run in your project workspace. A new panel is added for each unique table key.
In this example, my_table, is logged under the key "Table Name".
3. Compare across model versions
Log sample tables from multiple W&B Runs and compare results in the project workspace. In this example workspace, we show how to combine rows from multiple different versions in the same table.
Use the table filter, sort, and grouping features to explore and evaluate model results.
3.2 - Visualize and analyze tables
Visualize and analyze W&B Tables.
Customize your W&B Tables to answer questions about your machine learning model’s performance, analyze your data, and more.
Interactively explore your data to:
Compare changes precisely across models, epochs, or individual examples
Understand higher-level patterns in your data
Capture and communicate your insights with visual samples
W&B Tables posses the following behaviors:
Stateless in an artifact context: any table logged alongside an artifact version resets to its default state after you close the browser window
Stateful in a workspace or report context: any changes you make to a table in a single run workspace, multi-run project workspace, or Report persists.
For information on how to save your current W&B Table view, see Save your view.
How to view two tables
Compare two tables with a merged view or a side-by-side view. For example, the image below demonstrates a table comparison of MNIST data.
Follow these steps to compare two tables:
Go to your project in the W&B App.
Select the artifacts icon on the left panel.
Select an artifact version.
In the following image we demonstrate a model’s predictions on MNIST validation data after each of five epochs (view interactive example here).
Hover over the second artifact version you want to compare in the sidebar and click Compare when it appears. For example, in the image below we select a version labeled as “v4” to compare to MNIST predictions made by the same model after 5 epochs of training.
Merged view
Initially you see both tables merged together. The first table selected has index 0 and a blue highlight, and the second table has index 1 and a yellow highlight. View a live example of merged tables here.
From the merged view, you can
choose the join key: use the dropdown at the top left to set the column to use as the join key for the two tables. Typically this is the unique identifier of each row, such as the filename of a specific example in your dataset or an incrementing index on your generated samples. Note that it’s currently possible to select any column, which may yield illegible tables and slow queries.
concatenate instead of join: select “concatenating all tables” in this dropdown to union all the rows from both tables into one larger Table instead of joining across their columns
reference each Table explicitly: use 0, 1, and * in the filter expression to explicitly specify a column in one or both table instances
visualize detailed numerical differences as histograms: compare the values in any cell at a glance
Side-by-side view
To view the two tables side-by-side, change the first dropdown from “Merge Tables: Table” to “List of: Table” and then update the “Page size” respectively. Here the first Table selected is on the left and the second one is on the right. Also, you can compare these tables vertically as well by clicking on the “Vertical” checkbox.
compare the tables at a glance: apply any operations (sort, filter, group) to both tables in tandem and spot any changes or differences quickly. For example, view the incorrect predictions grouped by guess, the hardest negatives overall, the confidence score distribution by true label, etc.
explore two tables independently: scroll through and focus on the side/rows of interest
Log a table in an artifact for each meaningful step of training to analyze model performance over training time. For example, you could log a table at the end of every validation step, after every 50 epochs of training, or any frequency that makes sense for your pipeline. Use the side-by-side view to visualize changes in model predictions.
For a more detailed walkthrough of visualizing predictions across training time, see this report and this interactive notebook example.
Compare tables across model variants
Compare two artifact versions logged at the same step for two different models to analyze model performance across different configurations (hyperparameters, base architectures, and so forth).
For example, compare predictions between a baseline and a new model variant, 2x_layers_2x_lr, where the first convolutional layer doubles from 32 to 64, the second from 128 to 256, and the learning rate from 0.001 to 0.002. From this live example, use the side-by-side view and filter down to the incorrect predictions after 1 (left tab) versus 5 training epochs (right tab).
Save your view
Tables you interact with in the run workspace, project workspace, or a report automatically saves their view state. If you apply any table operations then close your browser, the table retains the last viewed configuration when you next navigate to the table.
Tables you interact with in the artifact context remains stateless.
To save a table from a workspace in a particular state, export it to a W&B Report. To export a table to report:
Select the kebob icon (three vertical dots) in the top right corner of your workspace visualization panel.
Select either Share panel or Add to report.
Examples
These reports highlight the different use cases of W&B Tables:
The following sections highlight some of the ways you can use tables:
View your data
Log metrics and rich media during model training or evaluation, then visualize results in a persistent database synced to the cloud, or to your hosting instance.
View, sort, filter, group, join, and query tables to understand your data and model performance—no need to browse static files or rerun analysis scripts.
Zoom in to visualize a specific prediction at a specific step. Zoom out to see the aggregate statistics, identify patterns of errors, and understand opportunities for improvement. This tool works for comparing steps from a single model training, or results across different model versions.
Interact with audio tables in this report on timbre transfer. You can compare a recorded whale song with a synthesized rendition of the same melody on an instrument like violin or trumpet. You can also record your own songs and explore their synthesized versions in W&B with this colab.
Text
Browse text samples from training data or generated output, dynamically group by relevant fields, and align your evaluation across model variants or experiment settings. Render text as Markdown or use visual diff mode to compare texts. Explore a simple character-based RNN for generating Shakespeare in this report.
Video
Browse and aggregate over videos logged during training to understand your models. Here is an early example using the SafeLife benchmark for RL agents seeking to minimize side effects
Like all W&B Artifacts, Tables can be converted into pandas dataframes for easy data exporting.
Convert table to artifact
First, you’ll need to convert the table to an artifact. The easiest way to do this using artifact.get(table, "table_name"):
# Create and log a new table.with wandb.init() as r:
artifact = wandb.Artifact("my_dataset", type="dataset")
table = wandb.Table(
columns=["a", "b", "c"], data=[(i, i *2, 2**i) for i in range(10)]
)
artifact.add(table, "my_table")
wandb.log_artifact(artifact)
# Retrieve the created table using the artifact you created.with wandb.init() as r:
artifact = r.use_artifact("my_dataset:latest")
table = artifact.get("my_table")
Convert artifact to Dataframe
Then, convert the table into a dataframe:
# Following from the last code example:df = table.get_dataframe()
Export Data
Now you can export using any method dataframe supports:
# Converting the table data to .csvdf.to_csv("example.csv", encoding="utf-8")
Use workspace panel visualizations to explore your logged data by key, visualize the relationships between hyperparameters and output metrics, and more.
Workspace modes
W&B projects support two different workspace modes. The icon next to the workspace name shows its mode.
Icon
Workspace mode
Automated workspaces automatically generate panels for all keys logged in the project. Choose an automatic workspace:
To get started quickly by visualizing all available data for the project.
For a smaller projects that log fewer keys.
For more broad analysis.
If you delete a panel from an automatic workspace, you can use Quick add to recreate it.
Manual workspaces start as blank slates and display only those panels intentionally added by users. Choose a manual workspace:
When you care mainly about a fraction of the keys logged in the project.
For more focused analysis.
To improve the performance of a workspace, avoiding loading panels that are less useful to you.
Use Quick add to easily populate a manual workspace and its sections with useful visualizations rapidly.
To undo changes to your workspace, click the Undo button (arrow that points left) or type CMD + Z (macOS) or CTRL + Z (Windows / Linux).
Reset a workspace
To reset a workspace:
At the top of the workspace, click the action menu ....
Click Reset workspace.
Configure the workspace layout
To configure the workspace layout, click Settings near the top of the workspace, then click Workspace layout.
Hide empty sections during search (turned on by default)
Sort panels alphabetically (turned off by default)
Section organization (grouped by first prefix by default). To modify this setting:
Click the padlock icon.
Choose how to group panels within a section.
To configure defaults for the workspace’s line plots, refer to Line plots.
Configure a section’s layout
To configure the layout of a section, click its gear icon, then click Display preferences.
Turn on or off colored run names in tooltips (turned on by default)
Only show highlighted run in companion chart tooltips (turned off by default)
Number of runs shown in tooltips (a single run, all runs, or Default)
Display full run names on the primary chart tooltip (turned off by default)
View a panel in full-screen mode
In full-screen mode, the run selector displays and panels use full full-fidelity sampling mode plots with 10,000 buckets, rather than 1000 buckets otherwise.
To view a panel in full-screen mode:
Hover over the panel.
Click the panel’s action menu ..., then click the full-screen button, which looks like a viewfinder or an outline showing the four corners of a square.
When you share the panel while viewing it in full-screen mode, the resulting link opens in full-screen mode automatically.
To get back to a panel’s workspace from full-screen mode, click the left-pointing arrow at the top of the page.
Add panels
This section shows various ways to add panels to your workspace.
Add a panel manually
Add panels to your workspace one at a time, either globally or at the section level.
To add a panel globally, click Add panels in the control bar near the panel search field.
To add a panel directly to a section instead, click the section’s action ... menu, then click + Add panels.
Select the type of panel to add, such as a chart. The panel’s configuration details appear, with defaults selected.
Optionally, customize the panel and its display preferences. Configuration options depend on the type of panel you select. To learn more about the options for each type of panel, refer to the relevant section below, such as Line plots or Bar plots.
Click Apply.
Quick add panels
Use Quick add to add a panel automatically for each key you select, either globally or at the section level.
For an automated workspace with no deleted panels, the Quick add option is not visible because the workspace already includes panels for all logged keys. You can use Quick add to re-add a panel that you deleted.
To use Quick add to add a panel globally, click Add panels in the control bar near the panel search field, then click Quick add.
To use Quick add to add a panel directly to a section, click the section’s action ... menu, click Add panels, then click Quick add.
A list of panels appears. Each panel with a checkmark is already included in the workspace.
To add all available panels, click the Add panels button at the top of the list. The Quick Add list closes and the new panels display in the workspace.
To add an individual panel from the list, hover over the panel’s row, then click Add. Repeat this step for each panel you want to add, then click the X at the top right to close the Quick Add list. The new panels display in the workspace.
Optionally, customize the panel’s settings.
Share a panel
This section shows how to share a panel using a link.
To share a panel using a link, you can either:
While viewing the panel in full-screen mode, copy the URL from the browser.
Click the action menu ... and select Copy panel URL.
Share the link with the user or team. When they access the link, the panel opens in full-screen mode.
To return to a panel’s workspace from full-screen mode, click the left-pointing arrow at the top of the page.
Compose a panel’s full-screen link programmatically
In certain situations, such as when creating an automation, it can be useful to include the panel’s full-screen URL. This section shows the format for a panel’s full-screen URL. In the proceeding example, replace the entity, project, panel, and section names in brackets.
If multiple panels in the same section have the same name, this URL opens the first panel with the name.
Embed or share a panel on social media
To embed a panel in a website or share it on social media, the panel must be viewable by anyone with the link. If a project is private, only members of the project can view the panel. If the project is public, anyone with the link can view the panel.
To get the code to embed or share a panel on social media:
From the workspace, hover over the panel, then click its action menu ....
Click the Share tab.
Change Only those who are invited have access to Anyone with the link can view. Otherwise, the choices in the next step are not available.
Choose Share on Twitter, Share on Reddit, Share on LinkedIn, or Copy embed link.
Email a panel report
To email a single panel as a stand-alone report:
Hover over the panel, then click the panel’s action menu ....
Click Share panel in report.
Select the Invite tab.
Enter an email address or username.
Optionally, change can view to can edit.
Click Invite. W&B sends an email to the user with a clickable link to the report that contains only the panel you are sharing.
Unlike when you share a panel, the recipient cannot get to the workspace from this report.
Manage panels
Edit a panel
To edit a panel:
Click its pencil icon.
Modify the panel’s settings.
To change the panel to a different type, select the type and then configure the settings.
Click Apply.
Move a panel
To move a panel to a different section, you can use the drag handle on the panel. To select the new section from a list instead:
If necessary, create a new section by clicking Add section after the last section.
Click the action ... menu for the panel.
Click Move, then select a new section.
You can also use the drag handle to rearrange panels within a section.
Duplicate a panel
To duplicate a panel:
At the top of the panel, click the action ... menu.
Click Duplicate.
If desired, you can customize or move the duplicated panel.
Remove panels
To remove a panel:
Hover your mouse over the panel.
Select the action ... menu.
Click Delete.
To remove all panels from a manual workspace, click its action ... menu, then click Clear all panels.
To remove all panels from an automatic or manual workspace, you can reset the workspace. Select Automatic to start with the default set of panels, or select Manual to start with an empty workspace with no panels.
Manage sections
By default, sections in a workspace reflect the logging hierarchy of your keys. However, in a manual workspace, sections appear only after you start adding panels.
Add a section
To add a section, click Add section after the last section.
To add a new section before or after an existing section, you can instead click the section’s action ... menu, then click New section below or New section above.
Manage a section’s panels
Sections with a large number of panels are paginated by default if they use the Standard grid layout. The default number of panels on a page depend on the panel’s configuration and on the sizes of the panels in the section.
To check which layout a section uses, click the section’s action ... menu. To change a section’s layout, select Standard grid or Custom grid in the Layout grid section.
To resize a panel, hover over it, click the drag handle, and drag it to adjust the panel’s size.
If a section uses the Standard grid, resizing one panel resizes all panels in the section.
If a section uses the Custom grid, you can customize the size of each panel separately.
If a section is paginated, you can customize the number of panels to show on a page:
At the top of the section, click 1 to of , where <X> is the number of visible panels and <Y> is the total number of panels.
Choose how many panels to show per page, up to 100.
To show all panels when there are a large number of them, configure the panel to use the Custom grid layout. Click the section’s action ... menu, then select Custom grid in the Layout grid section
To delete a panel from a section:
Hover over the panel, then click its action ... menu.
Click Delete.
If you reset a workspace to an automated workspace, all deleted panels appear again.
Rename a section
To rename a section, click its action ... menu, then click Rename section.
Delete a section
To delete a section, click its ... menu, then click Delete section. This removes the section and its panels.
4.1.1 - Line plots
Visualize metrics, customize axes, and compare multiple lines on a plot
Line plots show up by default when you plot metrics over time with wandb.log(). Customize with chart settings to compare multiple lines on the same plot, calculate custom axes, and rename labels.
Edit line plot settings
This section shows how to edit the settings for an individual line plot panel, all line plot panels in a section, or all line plot panels in a workspace.
If you’d like to use a custom x-axis, make sure it’s logged in the same call to wandb.log() that you use to log the y-axis.
Individual line plot
A line plot’s individual settings override the line plot settings for the section or the workspace. To customize a line plot:
Hover your mouse over the panel, then click the gear icon.
Within the modal that appears, select a tab to edit its settings.
Click Apply.
Line plot settings
You can configure these settings for a line plot:
Date: Configure the plot’s data-display details.
X: Select the value to use for the X axis (defaults to Step). You can change the x-axis to Relative Time or select a custom axis based on values you log with W&B.
Relative Time (Wall) is clock time since the process started, so if you started a run and resumed it a day later and logged something that would be plotted a 24hrs.
Relative Time (Process) is time inside the running process, so if you started a run and ran for 10 seconds and resumed a day later that point would be plotted at 10s.
Wall Time is minutes elapsed since the start of the first run on the graph.
Step increments by default each time wandb.log() is called, and is supposed to reflect the number of training steps you’ve logged from your model.
Y: Select one or more y-axes from the logged values, including metrics and hyperparameters that change over time.
X Axis and Y Axis minimum and maximum values (optional).
Point aggregation method. Either Random sampling (the default) or Full fidelity. Refer to Sampling.
Smoothing: Change the smoothing on the line plot. Defaults to Time weighted EMA. Other values include No smoothing, Running average, and Gaussian.
Outliers: Rescale to exclude outliers from the default plot min and max scale.
Max number of runs or groups: Show more lines on the line plot at once by increasing this number, which defaults to 10 runs. You’ll see the message “Showing first 10 runs” on the top of the chart if there are more than 10 runs available but the chart is constraining the number visible.
Chart type: Change between a line plot, an area plot, and a percentage area plot.
Grouping: Configure whether and how to group and aggregate runs in the plot.
Group by: Select a column, and all the runs with the same value in that column will be grouped together.
Agg: Aggregation— the value of the line on the graph. The options are mean, median, min, and max of the group.
Chart: Specify titles for the panel, the X axis, and the Y axis, and the -axis, hide or show the legend, and configure its position.
Legend: Customize the appearance of the panel’s legend, if it is enabled.
Legend: The field in the legend for each line in the plot in the legend of the plot for each line.
Legend template: Define a fully customizable template for the legend, specifying exactly what text and variables you want to show up in the template at the top of the line plot as well as the legend that appears when you hover your mouse over the plot.
Expressions: Add custom calculated expressions to the panel.
Y Axis Expressions: Add calculated metrics to your graph. You can use any of the logged metrics as well as configuration values like hyperparameters to calculate custom lines.
X Axis Expressions: Rescale the x-axis to use calculated values using custom expressions. Useful variables include**_step** for the default x-axis, and the syntax for referencing summary values is ${summary:value}
All line plots in a section
To customize the default settings for all line plots in a section, overriding workspace settings for line plots:
Click the section’s gear icon to open its settings.
Within the modal that appears, select the Data or Display preferences tabs to configure the default settings for the section. For details about each Data setting, refer to the preceding section, Individual line plot. For details about each display preference, refer to Configure section layout.
All line plots in a workspace
To customize the default settings for all line plots in a workspace:
Click the workspace’s settings, which has a gear with the label Settings.
Click Line plots.
Within the modal that appears, select the Data or Display preferences tabs to configure the default settings for the workspace.
For details about each Data setting, refer to the preceding section, Individual line plot.
For details about each Display preferences section, refer to Workspace display preferences. At the workspace level, you can configure the default Zooming behavior for line plots. This setting controls whether to synchronize zooming across line plots with a matching x-axis key. Disabled by default.
Visualize average values on a plot
If you have several different experiments and you’d like to see the average of their values on a plot, you can use the Grouping feature in the table. Click “Group” above the run table and select “All” to show averaged values in your graphs.
Here is what the graph looks like before averaging:
The proceeding image shows a graph that represents average values across runs using grouped lines.
Visualize NaN value on a plot
You can also plot NaN values including PyTorch tensors on a line plot with wandb.log. For example:
wandb.log({"test": [..., float("nan"), ...]})
Compare two metrics on one chart
Select the Add panels button in the top right corner of the page.
From the left panel that appears, expand the Evaluation dropdown.
Select Run comparer
Change the color of the line plots
Sometimes the default color of runs is not helpful for comparison. To help overcome this, wandb provides two instances with which one can manually change the colors.
Each run is given a random color by default upon initialization.
Upon clicking any of the colors, a color palette appears from which we can manually choose the color we want.
Hover your mouse over the panel you want to edit its settings for.
Select the pencil icon that appears.
Choose the Legend tab.
Visualize on different x axes
If you’d like to see the absolute time that an experiment has taken, or see what day an experiment ran, you can switch the x axis. Here’s an example of switching from steps to relative time and then to wall time.
Area plots
In the line plot settings, in the advanced tab, click on different plot styles to get an area plot or a percentage area plot.
Zoom
Click and drag a rectangle to zoom vertically and horizontally at the same time. This changes the x-axis and y-axis zoom.
Hide chart legend
Turn off the legend in the line plot with this simple toggle:
4.1.1.1 - Line plot reference
X-Axis
You can set the x-axis of a line plot to any value that you have logged with W&B.log as long as it’s always logged as a number.
Y-Axis variables
You can set the y-axis variables to any value you have logged with wandb.log as long as you were logging numbers, arrays of numbers or a histogram of numbers. If you logged more than 1500 points for a variable, W&B samples down to 1500 points.
You can change the color of your y axis lines by changing the color of the run in the runs table.
X range and Y range
You can change the maximum and minimum values of X and Y for the plot.
X range default is from the smallest value of your x-axis to the largest.
Y range default is from the smallest value of your metrics and zero to the largest value of your metrics.
Max runs/groups
By default you will only plot 10 runs or groups of runs. The runs will be taken from the top of your runs table or run set, so if you sort your runs table or run set you can change the runs that are shown.
Legend
You can control the legend of your chart to show for any run any config value that you logged and meta data from the runs such as the created at time or the user who created the run.
Example:
${run:displayName} - ${config:dropout} will make the legend name for each run something like royal-sweep - 0.5 where royal-sweep is the run name and 0.5 is the config parameter named dropout.
You can set value inside[[ ]] to display point specific values in the crosshair when hovering over a chart. For example \[\[ $x: $y ($original) ]] would display something like “2: 3 (2.9)”
Supported values inside [[ ]] are as follows:
Value
Meaning
${x}
X value
${y}
Y value (Including smoothing adjustment)
${original}
Y value not including smoothing adjustment
${mean}
Mean of grouped runs
${stddev}
Standard Deviation of grouped runs
${min}
Min of grouped runs
${max}
Max of grouped runs
${percent}
Percent of total (for stacked area charts)
Grouping
You can aggregate all of the runs by turning on grouping, or group over an individual variable. You can also turn on grouping by grouping inside the table and the groups will automatically populate into the graph.
Smoothing
You can set the smoothing coefficient to be between 0 and 1 where 0 is no smoothing and 1 is maximum smoothing.
Ignore outliers
Rescale the plot to exclude outliers from the default plot min and max scale. The setting’s impact on the plot depends on the plot’s sampling mode.
For plots that use random sampling mode, when you enable Ignore outliers, only points from 5% to 95% are shown. When outliers are shown, they are not formatted differently from other points.
For plots that use full fidelity mode, all points are always shown, condensed down to the last value in each bucket. When Ignore outliers is enabled, the minimum and maximum bounds of each bucket are shaded. Otherwise, no area is shaded.
Expression
Expression lets you plot values derived from metrics like 1-accuracy. It currently only works if you are plotting a single metric. You can do simple arithmetic expressions, +, -, *, / and % as well as ** for powers.
Plot style
Select a style for your line plot.
Line plot:
Area plot:
Percentage area plot:
4.1.1.2 - Point aggregation
Use point aggregation methods within your line plots for improved data visualization accuracy and performance. There are two types of point aggregation modes: full fidelity and random sampling. W&B uses full fidelity mode by default.
Full fidelity
When you use full fidelity mode, W&B breaks the x-axis into dynamic buckets based on the number of data points. It then calculates the minimum, maximum, and average values within each bucket while rendering a point aggregation for the line plot.
There are three main advantages to using full fidelity mode for point aggregation:
Preserve extreme values and spikes: retain extreme values and spikes in your data
Configure how minimum and maximum points render: use the W&B App to interactively decide whether you want to show extreme (min/max) values as a shaded area.
Explore your data without losing data fidelity: W&B recalculates x-axis bucket sizes when you zoom into specific data points. This helps ensure that you can explore your data without losing accuracy. Caching is used to store previously computed aggregations to help reduce loading times which is particularly useful if you are navigating through large datasets.
Configure how minimum and maximum points render
Show or hide minimum and maximum values with shaded areas around your line plots.
The proceeding image shows a blue line plot. The light blue shaded area represents the minimum and maximum values for each bucket.
There are three ways to render minimum and maximum values in your line plots:
Never: The min/max values are not displayed as a shaded area. Only show the aggregated line across the x-axis bucket.
On hover: The shaded area for min/max values appears dynamically when you hover over the chart. This option keeps the view uncluttered while allowing you to inspect ranges interactively.
Always: The min/max shaded area is consistently displayed for every bucket in the chart, helping you visualize the full range of values at all times. This can introduce visual noise if there are many runs visualized in the chart.
By default, the minimum and maximum values are not displayed as shaded areas. To view one of the shaded area options, follow these steps:
Navigate to your W&B project
Select on the Workspace icon on the left tab
Select the gear icon on the top right corner of the screen next to the left of the Add panels button.
From the UI slider that appears, select Line plots
Within the Point aggregation section, choose On over or Always from the Show min/max values as a shaded area dropdown menu.
Navigate to your W&B project
Select on the Workspace icon on the left tab
Select the line plot panel you want to enable full fidelity mode for
Within the modal that appears, select On hover or Always from the Show min/max values as a shaded area dropdown menu.
Explore your data without losing data fidelity
Analyze specific regions of the dataset without missing critical points like extreme values or spikes. When you zoom in on a line plot, W&B adjusts the buckets sizes used to calculate the minimum, maximum, and average values within each bucket.
W&B divides the x-axis is dynamically into 1000 buckets by default. For each bucket, W&B calculates the following values:
Minimum: The lowest value in that bucket.
Maximum: The highest value in that bucket.
Average: The mean value of all points in that bucket.
W&B plots values in buckets in a way that preserves full data representation and includes extreme values in every plot. When zoomed in to 1,000 points or fewer, full fidelity mode renders every data point without additional aggregation.
To zoom in on a line plot, follow these steps:
Navigate to your W&B project
Select on the Workspace icon on the left tab
Optionally add a line plot panel to your workspace or navigate to an existing line plot panel.
Click and drag to select a specific region to zoom in on.
Line plot grouping and expressions
When you use Line Plot Grouping, W&B applies the following based on the mode selected:
Non-windowed sampling (grouping): Aligns points across runs on the x-axis. The average is taken if multiple points share the same x-value; otherwise, they appear as discrete points.
Windowed sampling (grouping and expressions): Divides the x-axis either into 250 buckets or the number of points in the longest line (whichever is smaller). W&B takes an average of points within each bucket.
Full fidelity (grouping and expressions): Similar to non-windowed sampling, but fetches up to 500 points per run to balance performance and detail.
Random sampling
Random sampling uses 1500 randomly sampled points to render line plots. Random sampling is useful for performance reasons when you have a large number of data points.
Random sampling samples non-deterministically. This means that random sampling sometimes excludes important outliers or spikes in the data and therefore reduces data accuracy.
Enable random sampling
By default, W&B uses full fidelity mode. To enable random sampling, follow these steps:
Navigate to your W&B project
Select on the Workspace icon on the left tab
Select the gear icon on the top right corner of the screen next to the left of the Add panels button.
From the UI slider that appears, select Line plots
Choose Random sampling from the Point aggregation section
Navigate to your W&B project
Select on the Workspace icon on the left tab
Select the line plot panel you want to enable random sampling for
Within the modal that appears, select Random sampling from the Point aggregation method section
Access non sampled data
You can access the complete history of metrics logged during a run using the W&B Run API. The following example demonstrates how to retrieve and process the loss values from a specific run:
# Initialize the W&B APIrun = api.run("l2k2/examples-numpy-boston/i0wt6xua")
# Retrieve the history of the 'Loss' metrichistory = run.scan_history(keys=["Loss"])
# Extract the loss values from the historylosses = [row["Loss"] for row in history]
4.1.1.3 - Smooth line plots
In line plots, use smoothing to see trends in noisy data.
Exponential smoothing is a technique for smoothing time series data by exponentially decaying the weight of previous points. The range is 0 to 1. See Exponential Smoothing for background. There is a de-bias term added so that early values in the time series are not biased towards zero.
The EMA algorithm takes the density of points on the line (the number of y values per unit of range on x-axis) into account. This allows consistent smoothing when displaying multiple lines with different characteristics simultaneously.
Here is sample code for how this works under the hood:
constsmoothingWeight= Math.min(Math.sqrt(smoothingParam||0), 0.999);
letlastY=yValues.length>0?0:NaN;
letdebiasWeight=0;
returnyValues.map((yPoint, index) => {
constprevX=index>0?index-1:0;
// VIEWPORT_SCALE scales the result to the chart's x-axis range
constchangeInX= ((xValues[index] -xValues[prevX]) /rangeOfX) *VIEWPORT_SCALE;
constsmoothingWeightAdj= Math.pow(smoothingWeight, changeInX);
lastY=lastY*smoothingWeightAdj+yPoint;
debiasWeight=debiasWeight*smoothingWeightAdj+1;
returnlastY/debiasWeight;
});
Gaussian smoothing (or gaussian kernel smoothing) computes a weighted average of the points, where the weights correspond to a gaussian distribution with the standard deviation specified as the smoothing parameter. See . The smoothed value is calculated for every input x value.
Gaussian smoothing is a good standard choice for smoothing if you are not concerned with matching TensorBoard’s behavior. Unlike an exponential moving average the point will be smoothed based on points occurring both before and after the value.
Running average is a smoothing algorithm that replaces a point with the average of points in a window before and after the given x value. See “Boxcar Filter” at https://en.wikipedia.org/wiki/Moving_average. The selected parameter for running average tells Weights and Biases the number of points to consider in the moving average.
Consider using Gaussian Smoothing if your points are spaced unevenly on the x-axis.
The following image demonstrates how a running app looks like in the app:
Exponential Moving Average (Deprecated)
The TensorBoard EMA algorithm has been deprecated as it cannot accurately smooth multiple lines on the same chart that do not have a consistent point density (number of points plotted per unit of x-axis).
Exponential moving average is implemented to match TensorBoard’s smoothing algorithm. The range is 0 to 1. See Exponential Smoothing for background. There is a debias term added so that early values in the time series are not biases towards zero.
Here is sample code for how this works under the hood:
All of the smoothing algorithms run on the sampled data, meaning that if you log more than 1500 points, the smoothing algorithm will run after the points are downloaded from the server. The intention of the smoothing algorithms is to help find patterns in data quickly. If you need exact smoothed values on metrics with a large number of logged points, it may be better to download your metrics through the API and run your own smoothing methods.
Hide original data
By default we show the original, unsmoothed data as a faint line in the background. Click the Show Original toggle to turn this off.
4.1.2 - Bar plots
Visualize metrics, customize axes, and compare categorical data as bars.
A bar plot presents categorical data with rectangular bars which can be plotted vertically or horizontally. Bar plots show up by default with wandb.log() when all logged values are of length one.
Customize with chart settings to limit max runs to show, group runs by any config and rename labels.
Customize bar plots
You can also create Box or Violin Plots to combine many summary statistics into one chart type**.**
Group runs via runs table.
Click ‘Add panel’ in the workspace.
Add a standard ‘Bar Chart’ and select the metric to plot.
Under the ‘Grouping’ tab, pick ‘box plot’ or ‘Violin’, etc. to plot either of these styles.
4.1.3 - Parallel coordinates
Compare results across machine learning experiments
Parallel coordinates charts summarize the relationship between large numbers of hyperparameters and model metrics at a glance.
Lines: Each line represents a single run. Mouse over a line to see a tooltip with details about the run. All lines that match the current filters will be shown, but if you turn off the eye, lines will be grayed out.
Create a parallel coordinates panel
Go to the landing page for your workspace
Click Add Panels
Select Parallel coordinates
Panel Settings
To configure the panel, click the edit button in the upper right corner of the panel.
Tooltip: On hover, a legend shows up with info on each run
Titles: Edit the axis titles to be more readable
Gradient: Customize the gradient to be any color range you like
Log scale: Each axis can be set to view on a log scale independently
Flip axis: Switch the axis direction— this is useful when you have both accuracy and loss as columns
Use scatter plots to compare multiple runs and visualize the performance of an experiment:
Plot lines for minimum, maximum, and average values.
Customize metadata tooltips.
Control point colors.
Adjust axis ranges.
Use a log scale for the axes.
Example
The following example shows a scatter plot displaying validation accuracy for different models over several weeks of experimentation. The tooltip includes batch size, dropout, and axis values. A line also shows the running average of validation accuracy.
Set the x and y axes to plot the data you want to view. Optionally, set maximum and minimum ranges for your axes or add a z axis.
Click Apply to create the scatter plot.
View the new scatter plot in the Charts panel.
4.1.5 - Save and diff code
By default, W&B only saves the latest git commit hash. You can turn on more code features to compare the code between your experiments dynamically in the UI.
Starting with wandb version 0.8.28, W&B can save the code from your main training file where you call wandb.init().
Save library code
When you enable code saving, W&B saves the code from the file that called wandb.init(). To save additional library code, you have three options:
Call wandb.run.log_code(".") after calling wandb.init()
import wandb
wandb.init()
wandb.run.log_code(".")
Pass a settings object to wandb.init with code_dir set
This captures all python source code files in the current directory and all subdirectories as an artifact. For more control over the types and locations of source code files that are saved, see the reference docs.
Set code saving in the UI
In addition to setting code saving programmatically, you can also toggle this feature in your W&B account Settings. Note that this will enable code saving for all teams associated with your account.
By default, W&B disables code saving for all teams.
Log in to your W&B account.
Go to Settings > Privacy.
Under Project and content security, toggle Disable default code saving on.
Code comparer
Compare code used in different W&B runs:
Select the Add panels button in the top right corner of the page.
Expand TEXT AND CODE dropdown and select Code.
Jupyter session history
W&B saves the history of code executed in your Jupyter notebook session. When you call wandb.init() inside of Jupyter, W&B adds a hook to automatically save a Jupyter notebook containing the history of code executed in your current session.
Navigate to your project workspaces that contains your code.
Select the Artifacts tab in the left navigation bar.
Expand the code artifact.
Select the Files tab.
This displays the cells that were run in your session along with any outputs created by calling iPython’s display method. This enables you to see exactly what code was run within Jupyter in a given run. When possible W&B also saves the most recent version of the notebook which you would find in the code directory as well.
4.1.6 - Parameter importance
Visualize the relationships between your model’s hyperparameters and output metrics
Discover which of your hyperparameters were the best predictors of, and highly correlated to desirable values of your metrics.
Correlation is the linear correlation between the hyperparameter and the chosen metric (in this case val_loss). So a high correlation means that when the hyperparameter has a higher value, the metric also has higher values and vice versa. Correlation is a great metric to look at but it can’t capture second order interactions between inputs and it can get messy to compare inputs with wildly different ranges.
Therefore W&B also calculates an importance metric. W&B trains a random forest with the hyperparameters as inputs and the metric as the target output and report the feature importance values for the random forest.
The idea for this technique was inspired by a conversation with Jeremy Howard who has pioneered the use of random forest feature importances to explore hyperparameter spaces at Fast.ai. W&B highly recommends you check out this lecture (and these notes) to learn more about the motivation behind this analysis.
Hyperparameter importance panel untangles the complicated interactions between highly correlated hyperparameters. In doing so, it helps you fine tune your hyperparameter searches by showing you which of your hyperparameters matter the most in terms of predicting model performance.
Creating a hyperparameter importance panel
Navigate to your W&B project.
Select Add panels buton.
Expand the CHARTS dropdown, choose Parallel coordinates from the dropdown.
If an empty panel appears, make sure that your runs are ungrouped
With the parameter manager, we can manually set the visible and hidden parameters.
Interpreting a hyperparameter importance panel
This panel shows you all the parameters passed to the wandb.config object in your training script. Next, it shows the feature importances and correlations of these config parameters with respect to the model metric you select (val_loss in this case).
Importance
The importance column shows you the degree to which each hyperparameter was useful in predicting the chosen metric. Imagine a scenario were you start tuning a plethora of hyperparameters and using this plot to hone in on which ones merit further exploration. The subsequent sweeps can then be limited to the most important hyperparameters, thereby finding a better model faster and cheaper.
W&B calculate importances using a tree based model rather than a linear model as the former are more tolerant of both categorical data and data that’s not normalized.
In the preceding image, you can see that epochs, learning_rate, batch_size and weight_decay were fairly important.
Correlations
Correlations capture linear relationships between individual hyperparameters and metric values. They answer the question of whether there a significant relationship between using a hyperparameter, such as the SGD optimizer, and the val_loss (the answer in this case is yes). Correlation values range from -1 to 1, where positive values represent positive linear correlation, negative values represent negative linear correlation and a value of 0 represents no correlation. Generally a value greater than 0.7 in either direction represents strong correlation.
You might use this graph to further explore the values that are have a higher correlation to our metric (in this case you might pick stochastic gradient descent or adam over rmsprop or nadam) or train for more epochs.
correlations show evidence of association, not necessarily causation.
correlations are sensitive to outliers, which might turn a strong relationship to a moderate one, specially if the sample size of hyperparameters tried is small.
and finally, correlations only capture linear relationships between hyperparameters and metrics. If there is a strong polynomial relationship, it won’t be captured by correlations.
The disparities between importance and correlations result from the fact that importance accounts for interactions between hyperparameters, whereas correlation only measures the affects of individual hyperparameters on metric values. Secondly, correlations capture only the linear relationships, whereas importances can capture more complex ones.
As you can see both importance and correlations are powerful tools for understanding how your hyperparameters influence model performance.
4.1.7 - Compare run metrics
Compare metrics across multiple runs
Use the Run Comparer to see what metrics are different across your runs.
Select the Add panels button in the top right corner of the page.
From the left panel that appears, expand the Evaluation dropdown.
Select Run comparer
Toggle the diff only option to hide rows where the values are the same across runs.
4.1.8 - Query panels
Some features on this page are in beta, hidden behind a feature flag. Add weave-plot to your bio on your profile page to unlock all related features.
Looking for W&B Weave? W&B’s suite of tools for Generative AI application building? Find the docs for weave here: wandb.me/weave.
Use query panels to query and interactively visualize your data.
Create a query panel
Add a query to your workspace or within a report.
Navigate to your project’s workspace.
In the upper right hand corner, click Add panel.
From the dropdown, select Query panel.
Type and select /Query panel.
Alternatively, you can associate a query with a set of runs:
Within your report, type and select /Panel grid.
Click the Add panel button.
From the dropdown, select Query panel.
Query components
Expressions
Use query expressions to query your data stored in W&B such as runs, artifacts, models, tables, and more.
Example: Query a table
Suppose you want to query a W&B Table. In your training code you log a table called "cifar10_sample_table":
Within the query panel you can query your table with:
runs.summary["cifar10_sample_table"]
Breaking this down:
runs is a variable automatically injected in Query Panel Expressions when the Query Panel is in a Workspace. Its “value” is the list of runs which are visible for that particular Workspace. Read about the different attributes available within a run here.
summary is an op which returns the Summary object for a Run. Ops are mapped, meaning this op is applied to each Run in the list, resulting in a list of Summary objects.
["cifar10_sample_table"] is a Pick op (denoted with brackets), with a parameter of predictions. Since Summary objects act like dictionaries or maps, this operation picks the predictions field off of each Summary object.
To learn how to write your own queries interactively, see this report.
Configurations
Select the gear icon on the upper left corner of the panel to expand the query configuration. This allows the user to configure the type of panel and the parameters for the result panel.
Result panels
Finally, the query result panel renders the result of the query expression, using the selected query panel, configured by the configuration to display the data in an interactive form. The following images shows a Table and a Plot of the same data.
Basic operations
The following common operations you can make within your query panels.
Sort
Sort from the column options:
Filter
You can either filter directly in the query or using the filter button in the top left corner (second image)
Map
Map operations iterate over lists and apply a function to each element in the data. You can do this directly with a panel query or by inserting a new column from the column options.
Groupby
You can groupby using a query or from the column options.
Concat
The concat operation allows you to concatenate 2 tables and concatenate or join from the panel settings
Join
It is also possible to join tables directly in the query. Consider the following query expression:
(row) => row["Label"] are selectors for each table, determining which column to join on
"Table1" and "Table2" are the names of each table when joined
true and false are for left and right inner/outer join settings
Runs object
Use query panels to access the runs object. Run objects store records of your experiments. You can find more details about it in this section of the report but, as quick overview, runs object has available:
summary: A dictionary of information that summarizes the run’s results. This can be scalars like accuracy and loss, or large files. By default, wandb.log() sets the summary to the final value of a logged time series. You can set the contents of the summary directly. Think of the summary as the run’s outputs.
history: A list of dictionaries meant to store values that change while the model is training such as loss. The command wandb.log() appends to this object.
config: A dictionary of the run’s configuration information, such as the hyperparameters for a training run or the preprocessing methods for a run that creates a dataset Artifact. Think of these as the run’s “inputs”
Access Artifacts
Artifacts are a core concept in W&B. They are a versioned, named collection of files and directories. Use Artifacts to track model weights, datasets, and any other file or directory. Artifacts are stored in W&B and can be downloaded or used in other runs. You can find more details and examples in this section of the report. Artifacts are normally accessed from the project object:
project.artifactVersion(): returns the specific artifact version for a given name and version within a project
project.artifact(""): returns the artifact for a given name within a project. You can then use .versions to get a list of all versions of this artifact
project.artifactType(): returns the artifactType for a given name within a project. You can then use .artifacts to get a list of all artifacts with this type
project.artifactTypes: returns a list of all artifact types under the project
4.1.8.1 - Embed objects
W&B’s Embedding Projector allows users to plot multi-dimensional embeddings on a 2D plane using common dimension reduction algorithms like PCA, UMAP, and t-SNE.
Embeddings are used to represent objects (people, images, posts, words, etc…) with a list of numbers - sometimes referred to as a vector. In machine learning and data science use cases, embeddings can be generated using a variety of approaches across a range of applications. This page assumes the reader is familiar with embeddings and is interested in visually analyzing them inside of W&B.
After running the above code, the W&B dashboard will have a new Table containing your data. You can select 2D Projection from the upper right panel selector to plot the embeddings in 2 dimensions. Smart default will be automatically selected, which can be easily overridden in the configuration menu accessed by clicking the gear icon. In this example, we automatically use all 5 available numeric dimensions.
Digits MNIST
While the above example shows the basic mechanics of logging embeddings, typically you are working with many more dimensions and samples. Let’s consider the MNIST Digits dataset (UCI ML hand-written digits datasets) made available via SciKit-Learn. This dataset has 1797 records, each with 64 dimensions. The problem is a 10 class classification use case. We can convert the input data to an image for visualization as well.
After running the above code, again we are presented with a Table in the UI. By selecting 2D Projection we can configure the definition of the embedding, coloring, algorithm (PCA, UMAP, t-SNE), algorithm parameters, and even overlay (in this case we show the image when hovering over a point). In this particular case, these are all “smart defaults” and you should see something very similar with a single click on 2D Projection. (Click here to interact with this example).
Logging Options
You can log embeddings in a number of different formats:
Single Embedding Column: Often your data is already in a “matrix”-like format. In this case, you can create a single embedding column - where the data type of the cell values can be list[int], list[float], or np.ndarray.
Multiple Numeric Columns: In the above two examples, we use this approach and create a column for each dimension. We currently accept python int or float for the cells.
Furthermore, just like all tables, you have many options regarding how to construct the table:
Directly from a dataframe using wandb.Table(dataframe=df)
Directly from a list of data using wandb.Table(data=[...], columns=[...])
Build the table incrementally row-by-row (great if you have a loop in your code). Add rows to your table using table.add_data(...)
Add an embedding column to your table (great if you have a list of predictions in the form of embeddings): table.add_col("col_name", ...)
Add a computed column (great if you have a function or model you want to map over your table): table.add_computed_columns(lambda row, ndx: {"embedding": model.predict(row)})
Plotting Options
After selecting 2D Projection, you can click the gear icon to edit the rendering settings. In addition to selecting the intended columns (see above), you can select an algorithm of interest (along with the desired parameters). Below you can see the parameters for UMAP and t-SNE respectively.
Note: we currently downsample to a random subset of 1000 rows and 50 dimensions for all three algorithms.
4.2 - Custom charts
Create custom charts in your W&B project. Log arbitrary tables of data and visualize them exactly how you want. Control details of fonts, colors, and tooltips with the power of Vega.
Log data: From your script, log config and summary data.
Customize the chart: Pull in logged data with a GraphQL query. Visualize the results of your query with Vega, a powerful visualization grammar.
Log the chart: Call your own preset from your script with wandb.plot_table().
If you do not see the expected data, the column you are looking for might not be logged in the selected runs. Save your chart, go back out to the runs table, and verify selected runs using the eye icon.
Log charts from a script
Builtin presets
W&B has a number of builtin chart presets that you can log directly from your script. These include line plots, scatter plots, bar charts, histograms, PR curves, and ROC curves.
wandb.plot.line()
Log a custom line plot—a list of connected and ordered points (x,y) on arbitrary axes x and y.
data = [[x, y] for (x, y) in zip(x_values, y_values)]
table = wandb.Table(data=data, columns=["x", "y"])
wandb.log(
{
"my_custom_plot_id": wandb.plot.line(
table, "x", "y", title="Custom Y vs X Line Plot" )
}
)
A line plot logs curves on any two dimensions. If you plot two lists of values against each other, the number of values in the lists must match exactly (for example, each point must have an x and a y).
Log a custom scatter plot—a list of points (x, y) on a pair of arbitrary axes x and y.
data = [[x, y] for (x, y) in zip(class_x_prediction_scores, class_y_prediction_scores)]
table = wandb.Table(data=data, columns=["class_x", "class_y"])
wandb.log({"my_custom_id": wandb.plot.scatter(table, "class_x", "class_y")})
You can use this to log scatter points on any two dimensions. Note that if you’re plotting two lists of values against each other, the number of values in the lists must match exactly (for example, each point must have an x and a y).
Log a custom bar chart—a list of labeled values as bars—natively in a few lines:
data = [[label, val] for (label, val) in zip(labels, values)]
table = wandb.Table(data=data, columns=["label", "value"])
wandb.log(
{
"my_bar_chart_id": wandb.plot.bar(
table, "label", "value", title="Custom Bar Chart" )
}
)
You can use this to log arbitrary bar charts. Note that the number of labels and values in the lists must match exactly (for example, each data point must have both).
Log a custom histogram—sort list of values into bins by count/frequency of occurrence—natively in a few lines. Let’s say I have a list of prediction confidence scores (scores) and want to visualize their distribution:
data = [[s] for s in scores]
table = wandb.Table(data=data, columns=["scores"])
wandb.log({"my_histogram": wandb.plot.histogram(table, "scores", title=None)})
You can use this to log arbitrary histograms. Note that data is a list of lists, intended to support a 2D array of rows and columns.
Tweak a builtin preset, or create a new preset, then save the chart. Use the chart ID to log data to that custom preset directly from your script. Try an example Google Colab notebook.
# Create a table with the columns to plottable = wandb.Table(data=data, columns=["step", "height"])
# Map from the table's columns to the chart's fieldsfields = {"x": "step", "value": "height"}
# Use the table to populate the new custom chart preset# To use your own saved chart preset, change the vega_spec_namemy_custom_chart = wandb.plot_table(
vega_spec_name="carey/new_chart",
data_table=table,
fields=fields,
)
Log data
You can log the following data types from your script and use them in a custom chart:
Config: Initial settings of your experiment (your independent variables). This includes any named fields you’ve logged as keys to wandb.config at the start of your training. For example: wandb.config.learning_rate = 0.0001
Summary: Single values logged during training (your results or dependent variables). For example, wandb.log({"val_acc" : 0.8}). If you write to this key multiple times during training via wandb.log(), the summary is set to the final value of that key.
History: The full time series of the logged scalar is available to the query via the history field
summaryTable: If you need to log a list of multiple values, use a wandb.Table() to save that data, then query it in your custom panel.
historyTable: If you need to see the history data, then query historyTable in your custom chart panel. Each time you call wandb.Table() or log a custom chart, you’re creating a new table in history for that step.
How to log a custom table
Use wandb.Table() to log your data as a 2D array. Typically each row of this table represents one data point, and each column denotes the relevant fields/dimensions for each data point which you’d like to plot. As you configure a custom panel, the whole table will be accessible via the named key passed to wandb.log()(custom_data_table below), and the individual fields will be accessible via the column names (x, y, and z). You can log tables at multiple time steps throughout your experiment. The maximum size of each table is 10,000 rows. Try an example a Google Colab.
Add a new custom chart to get started, then edit the query to select data from your visible runs. The query uses GraphQL to fetch data from the config, summary, and history fields in your runs.
Custom visualizations
Select a Chart in the upper right corner to start with a default preset. Next, select Chart fields to map the data you’re pulling in from the query to the corresponding fields in your chart.
The following image shows an example on how to select a metric then mapping that into the bar chart fields below.
How to edit Vega
Click Edit at the top of the panel to go into Vega edit mode. Here you can define a Vega specification that creates an interactive chart in the UI. You can change any aspect of the chart. For example, you can change the title, pick a different color scheme, show curves as a series of points instead of as connected lines. You can also make changes to the data itself, such as using a Vega transform to bin an array of values into a histogram. The panel preview will update interactively, so you can see the effect of your changes as you edit the Vega spec or query. Refer to the Vega documentation and tutorials .
Field references
To pull data into your chart from W&B, add template strings of the form "${field:<field-name>}" anywhere in your Vega spec. This will create a dropdown in the Chart Fields area on the right side, which users can use to select a query result column to map into Vega.
To set a default value for a field, use this syntax: "${field:<field-name>:<placeholder text>}"
Saving chart presets
Apply any changes to a specific visualization panel with the button at the bottom of the modal. Alternatively, you can save the Vega spec to use elsewhere in your project. To save the reusable chart definition, click Save as at the top of the Vega editor and give your preset a name.
Show model validation metrics which require custom x-y coordinates (like precision-recall curves)
Overlay data distributions from two different models/experiments as histograms
Show changes in a metric via snapshots at multiple points during training
Create a unique visualization not yet available in W&B (and hopefully share it with the world)
4.2.1 - Tutorial: Use custom charts
Tutorial of using the custom charts feature in the W&B UI
Use custom charts to control the data you’re loading in to a panel and its visualization.
1. Log data to W&B
First, log data in your script. Use wandb.config for single points set at the beginning of training, like hyperparameters. Use wandb.log() for multiple points over time, and log custom 2D arrays with wandb.Table(). We recommend logging up to 10,000 data points per logged key.
Try a quick example notebook to log the data tables, and in the next step we’ll set up custom charts. See what the resulting charts look like in the live report.
2. Create a query
Once you’ve logged data to visualize, go to your project page and click the + button to add a new panel, then select Custom Chart. You can follow along in this workspace.
Add a query
Click summary and select historyTable to set up a new query pulling data from the run history.
Type in the key where you logged the wandb.Table(). In the code snippet above, it was my_custom_table . In the example notebook, the keys are pr_curve and roc_curve.
Set Vega fields
Now that the query is loading in these columns, they’re available as options to select in the Vega fields dropdown menus:
x-axis: runSets_historyTable_r (recall)
y-axis: runSets_historyTable_p (precision)
color: runSets_historyTable_c (class label)
3. Customize the chart
Now that looks pretty good, but I’d like to switch from a scatter plot to a line plot. Click Edit to change the Vega spec for this built in chart. Follow along in this workspace.
I updated the Vega spec to customize the visualization:
add titles for the plot, legend, x-axis, and y-axis (set “title” for each field)
change the value of “mark” from “point” to “line”
remove the unused “size” field
To save this as a preset that you can use elsewhere in this project, click Save as at the top of the page. Here’s what the result looks like, along with an ROC curve:
Bonus: Composite Histograms
Histograms can visualize numerical distributions to help us understand larger datasets. Composite histograms show multiple distributions across the same bins, letting us compare two or more metrics across different models or across different classes within our model. For a semantic segmentation model detecting objects in driving scenes, we might compare the effectiveness of optimizing for accuracy versus intersection over union (IOU), or we might want to know how well different models detect cars (large, common regions in the data) versus traffic signs (much smaller, less common regions). In the demo Colab, you can compare the confidence scores for two of the ten classes of living things.
To create your own version of the custom composite histogram panel:
Create a new Custom Chart panel in your Workspace or Report (by adding a “Custom Chart” visualization). Hit the “Edit” button in the top right to modify the Vega spec starting from any built-in panel type.
Replace that built-in Vega spec with my MVP code for a composite histogram in Vega. You can modify the main title, axis titles, input domain, and any other details directly in this Vega spec using Vega syntax (you could change the colors or even add a third histogram :)
Modify the query in the right hand side to load the correct data from your wandb logs. Add the field summaryTable and set the corresponding tableKey to class_scores to fetch the wandb.Table logged by your run. This will let you populate the two histogram bin sets (red_bins and blue_bins) via the dropdown menus with the columns of the wandb.Table logged as class_scores. For my example, I chose the animal class prediction scores for the red bins and plant for the blue bins.
You can keep making changes to the Vega spec and query until you’re happy with the plot you see in the preview rendering. Once you’re done, click Save as in the top and give your custom plot a name so you can reuse it. Then click Apply from panel library to finish your plot.
Here’s what my results look like from a very brief experiment: training on only 1000 examples for one epoch yields a model that’s very confident that most images are not plants and very uncertain about which images might be animals.
4.3 - Manage workspace, section, and panel settings
Within a given workspace page there are three different setting levels: workspaces, sections, and panels. Workspace settings apply to the entire workspace. Section settings apply to all panels within a section. Panel settings apply to individual panels.
Workspace settings
Workspace settings apply to all sections and all panels within those sections. You can edit two types of workspace settings: Workspace layout and Line plots. Workspace layouts determine the structure of the workspace, while Line plots settings control the default settings for line plots in the workspace.
To edit settings that apply to the overall structure of this workspace:
Navigate to your project workspace.
Click the gear icon next to the New report button to view the workspace settings.
Choose Workspace layout to change the workspace’s layout, or choose Line plots to configure default settings for line plots in the workspace.
Workspace layout options
Configure a workspaces layout to define the overall structure of the workspace. This includes sectioning logic and panel organization.
The workspace layout options page shows whether the workspace generates panels automatically or manually. To adjust a workspace’s panel generation mode, refer to Panels.
This table describes each workspace layout option.
Workspace setting
Description
Hide empty sections during search
Hide sections that do not contain any panels when searching for a panel.
Sort panels alphabetically
Sort panels in your workspaces alphabetically.
Section organization
Remove all existing sections and panels and repopulate them with new section names. Groups the newly populated sections either by first or last prefix.
W&B suggests that you organize sections by grouping the first prefix rather than grouping by the last prefix. Grouping by the first prefix can result in fewer sections and better performance.
Line plots options
Set global defaults and custom rules for line plots in a workspace by modifying the Line plots workspace settings.
You can edit two main settings within Line plots settings: Data and Display preferences. The Data tab contains the following settings:
Line plot setting
Description
X axis
The scale of the x-axis in line plots. The x-axis is set to Step by default. See the proceeding table for the list of x-axis options.
Range
Minimum and maximum settings to display for x axis.
Smoothing
Change the smoothing on the line plot. For more information about smoothing, see Smooth line plots.
Outliers
Rescale to exclude outliers from the default plot min and max scale.
Point aggregation method
Improve data visualization accuracy and performance. See Point aggregation for more information.
Max number of runs or groups
Limit the number of runs or groups displayed on the line plot.
In addition to Step, there are other options for the x-axis:
X axis option
Description
Relative Time (Wall)
Timestamp since the process starts. For example, suppose start a run and resume that run the next day. If you then log something, the recorded point is 24 hours.
Relative Time (Process)
Timestamp inside the running process. For example, suppose you start a run and let it continue for 10 seconds. The next day you resume that run. The point is recorded as 10 seconds.
Wall Time
Minutes elapsed since the start of the first run on the graph.
Step
Increments each time you call wandb.log().
For information on how to edit an individual line plot, see Edit line panel settings in Line plots.
Within the Display preferences tab, you can toggle the proceeding settings:
Display preference
Description
Remove legends from all panels
Remove the panel’s legend
Display colored run names in tooltips
Show the runs as colored text within the tooltip
Only show highlighted run in companion chart tooltip
Display only highlighted runs in chart tooltip
Number of runs shown in tooltips
Display the number of runs in the tooltip
Display full run names on the primary chart tooltip
Display the full name of the run in the chart tooltip
Section settings
Section settings apply to all panels within that section. Within a workspace section you can sort panels, rearrange panels, and rename the section name.
Modify section settings by selecting the three horizontal dots (…) in the upper right corner of a section.
From the dropdown, you can edit the following settings that apply to the entire section:
Section setting
Description
Rename a section
Rename the name of the section
Sort panels A-Z
Sort panels within a section alphabetically
Rearrange panels
Select and drag a panel within a section to manually order your panels
The proceeding animation demonstrates how to rearrange panels within a section:
In addition to the settings described in the preceding table, you can also edit how sections appear in your workspaces such as Add section below, Add section above, Delete section, and Add section to report.
Panel settings
Customize an individual panel’s settings to compare multiple lines on the same plot, calculate custom axes, rename labels, and more. To edit a panel’s settings:
Hover your mouse over the panel you want to edit.
Select the pencil icon that appears.
Within the modal that appears, you can edit settings related to the panel’s data, display preferences, and more.
Use the Weights and Biases Settings Page to customize your individual user profile or team settings.
Within your individual user account you can edit: your profile picture, display name, geography location, biography information, emails associated to your account, and manage alerts for runs. You can also use the settings page to link your GitHub repository and delete your account. For more information, see User settings.
Use the team settings page to invite or remove new members to a team, manage alerts for team runs, change privacy settings, and view and manage storage usage. For more information about team settings, see Team settings.
4.4.1 - Manage user settings
Manage your profile information, account defaults, alerts, participation in beta products, GitHub integration, storage usage, account activation, and create teams in your user settings.
Navigate to your user profile page and select your user icon on the top right corner. From the dropdown, choose Settings.
Profile
Within the Profile section you can manage and modify your account name and institution. You can optionally add a biography, location, link to a personal or your institution’s website, and upload a profile image.
Edit your intro
To edit your intro, click Edit at the top of your profile. The WYSIWYG editor that opens supports Markdown.
To edit a line, click it. To save time, you can type / and choose Markdown from the list.
Use an item’s drag handles to move it.
To delete a block, click the drag handle, then click Delete.
To save your changes, click Save.
Add social badges
To add a follow badge for the @weights_biases account on X, you could add a Markdown-style link with an HTML <img> tag that points to the badge image:
In an <img> tag, you can specify width, height, or both. If you specify only one of them, the image’s proportions are maintained.
Teams
Create a new team in the Team section. To create a new team, select the New team button and provide the following:
Team name - the name of your team. The team mane must be unique. Team names can not be changed.
Team type - Select either the Work or Academic button.
Company/Organization - Provide the name of the team’s company or organization. Choose the dropdown menu to select a company or organization. You can optionally provide a new organization.
Only administrative accounts can create a team.
Beta features
Within the Beta Features section you can optionally enable fun add-ons and sneak previews of new products in development. Select the toggle switch next to the beta feature you want to enable.
Alerts
Get notified when your runs crash, finish, or set custom alerts with wandb.alert(). Receive notifications either through Email or Slack. Toggle the switch next to the event type you want to receive alerts from.
Runs finished: whether a Weights and Biases run successfully finished.
Run crashed: notification if a run has failed to finish.
Connect a personal Github account. To connect a Github account:
Select the Connect Github button. This will redirect you to an open authorization (OAuth) page.
Select the organization to grant access in the Organization access section.
Select Authorizewandb.
Delete your account
Select the Delete Account button to delete your account.
Account deletion can not be reversed.
Storage
The Storage section describes the total memory usage the your account has consumed on the Weights and Biases servers. The default storage plan is 100GB. For more information about storage and pricing, see the Pricing page.
4.4.2 - Manage billing settings
Manage your organization’s billing settings
Navigate to your user profile page and select your user icon on the top right corner. From the dropdown, choose Billing, or choose Settings and then select the Billing tab.
Plan details
The Plan details section summarizes your organization’s current plan, charges, limits, and usage.
For details and a list of users, click Manage users.
For details about usage, click View usage.
Amount of storage your organization uses, both free and paid. From here, you can purchase additional storage and manage storage that is currently in use. Learn more about storage settings.
From here, you can compare plans or talk to Sales.
Plan usage
This section visually summarizes current usage and displays upcoming usage charges. For detailed insights into usage by month, click View usage on an individual tile. To export usage by calendar month, team, or project, click Export CSV.
For organizations on paid plans, admins receive alerts via email once per billing period when certain thresholds are met, along with details about how to increase your organization’s limits if you are a billing admin and how to contact a billing admin otherwise. On the Pro plan, only the billing admin receives usage alerts.
These alerts are not configurable, and are sent when:
Your organization is approaching a monthly limit of a category of usage (85% of hours used) and when it reaches 100% of the limit, according to your plan.
Your organization’s accumulated average charges for a billing period exceed these thresholds: $200, $450, $700, and $1000. These overage charges are incurred when your organization accumulates more usage than your plan includes for tracked hours, storage, or Weave data ingestion.
For questions about usage or billing, contact your account team or Support.
Payment methods
This section shows the payment methods on file for your organization. If you have not added a payment method, you will be prompted to do so when you upgrade your plan or add paid storage.
Billing admin
This section shows the current billing admin. The billing admin is an organization admin, receives all billing-related emails, and can view and manage payment methods.
In W&B Dedicated Cloud, multiple users can be billing admins. In W&B Multi-tenant Cloud, only one user at a time can be the billing admin.
To change the billing admin or assign the role to additional users:
Click Manage roles.
Search for a user.
Click the Billing admin field in that user’s row.
Read the summary, then click Change billing user.
Invoices
If you pay using a credit card, this section allows you to view monthly invoices.
For Enterprise accounts that pay via wire transfer, this section is blank. For questions, contact your account team.
If your organization incurs no charges, no invoice is generated.
4.4.3 - Manage team settings
Manage a team’s members, avatar, alerts, and privacy settings with the Team Settings page.
Team settings
Change your team’s settings, including members, avatar, alerts, privacy, and usage. Organization admins and team admins can view and edit a team’s settings.
Only Administration account types can change team settings or remove a member from a team.
Members
The Members section shows a list of all pending invitations and the members that have either accepted the invitation to join the team. Each member listed displays a member’s name, username, email, team role, as well as their access privileges to Models and Weave, which is inherited by from the Organization. You can choose from the standard team roles Admin, Member, and View-only. If your organization has created custom roles, you can assign a custom role instead.
See Add and Manage teams for information on how to create a team, manage teams, and manage team membership and roles. To configure who can invite new members and configure other privacy settings for the team, refer to Privacy.
Avatar
Set an avatar by navigating to the Avatar section and uploading an image.
Select the Update Avatar to prompt a file dialog to appear.
From the file dialog, choose the image you want to use.
Alerts
Notify your team when runs crash, finish, or set custom alerts. Your team can receive alerts either through email or Slack.
Toggle the switch next to the event type you want to receive alerts from. Weights and Biases provides the following event type options be default:
Runs finished: whether a Weights and Biases run successfully finished.
Navigate to the Privacy section to change privacy settings. Only organization admins can modify privacy setting.
Turn off the ability to make future projects public or to share reports publicly.
Allow any team member to invite other members, rather than only team admins.
Manage whether code saving is turned on by default.
Usage
The Usage section describes the total memory usage the team has consumed on the Weights and Biases servers. The default storage plan is 100GB. For more information about storage and pricing, see the Pricing page.
Storage
The Storage section describes the cloud storage bucket configuration that is being used for the team’s data. For more information, see Secure Storage Connector or check out our W&B Server docs if you are self-hosting.
4.4.4 - Manage email settings
Manage emails from the Settings page.
Add, delete, manage email types and primary email addresses in your W&B Profile Settings page. Select your profile icon in the upper right corner of the W&B dashboard. From the dropdown, select Settings. Within the Settings page, scroll down to the Emails dashboard:
Manage primary email
The primary email is marked with a 😎 emoji. The primary email is automatically defined with the email you provided when you created a W&B account.
Select the kebab dropdown to change the primary email associated with your Weights And Biases account:
Only verified emails can be set as primary
Add emails
Select + Add Email to add an email. This will take you to an Auth0 page. You can enter in the credentials for the new email or connect using single sign-on (SSO).
Delete emails
Select the kebab dropdown and choose Delete Emails to delete an email that is registered to your W&B account
Primary emails cannot be deleted. You need to set a different email as a primary email before deleting.
Log in methods
The Log in Methods column displays the log in methods that are associated with your account.
A verification email is sent to your email account when you create a W&B account. Your email account is considered unverified until you verify your email address. Unverified emails are displayed in red.
Attempt to log in with your email address again to retrieve a second verification email if you no longer have the original verification email that was sent to your email account.
Note: Only the admin of an organization can create a new team.
Create a team profile
You can customize your team’s profile page to show an introduction and showcase reports and projects that are visible to the public or team members. Present reports, projects, and external links.
Highlight your best research to visitors by showcasing your best public reports
Showcase the most active projects to make it easier for teammates to find them
Find collaborators by adding external links to your company or research lab’s website and any papers you’ve published
Remove team members
Team admins can open the team settings page and click the delete button next to the departing member’s name. Any runs logged to the team remain after a user leaves.
Manage team roles and permissions
Select a team role when you invite colleagues to join a team. There are following team role options:
Admin: Team admins can add and remove other admins or team members. They have permissions to modify all projects and full deletion permissions. This includes, but is not limited to, deleting runs, projects, artifacts, and sweeps.
Member: A regular member of the team. By default, only an admin can invite a team member. To change this behavior, refer to Manage team settings.
A team member can delete only runs they created. Suppose you have two members A and B. Member B moves a run from team B’s project to a different project owned by Member A. Member A cannot delete the run Member B moved to Member A’s project. An admin can manage runs and sweep runs created by any team member.
View-Only (Enterprise-only feature): View-Only members can view assets within the team such as runs, reports, and workspaces. They can follow and comment on reports, but they can not create, edit, or delete project overview, reports, or runs.
Custom roles (Enterprise-only feature): Custom roles allow organization admins to compose new roles based on either of the View-Only or Member roles, together with additional permissions to achieve fine-grained access control. Team admins can then assign any of those custom roles to users in their respective teams. Refer to Introducing Custom Roles for W&B Teams for details.
W&B recommends to have more than one admin in a team. It is a best practice to ensure that admin operations can continue when the primary admin is not available.
Team settings
Team settings allow you to manage the settings for your team and its members. With these privileges, you can effectively oversee and organize your team within W&B.
Permissions
View-Only
Team Member
Team Admin
Add team members
X
Remove team members
X
Manage team settings
X
Model Registry
The proceeding table lists permissions that apply to all projects across a given team.
Permissions
View-Only
Team Member
Model Registry Admin
Team Admin
Add aliases
X
X
X
Add models to the registry
X
X
X
View models in the registry
X
X
X
X
Download models
X
X
X
X
Add/Remove Registry Admins
X
X
Add/Remove Protected Aliases
X
See the Model Registry chapter for more information about protected aliases.
Reports
Report permissions grant access to create, view, and edit reports. The proceeding table lists permissions that apply to all reports across a given team.
Permissions
View-Only
Team Member
Team Admin
View reports
X
X
X
Create reports
X
X
Edit reports
X (team members can only edit their own reports)
X
Delete reports
X (team members can only edit their own reports)
X
Experiments
The proceeding table lists permissions that apply to all experiments across a given team.
Permissions
View-Only
Team Member
Team Admin
View experiment metadata (includes history metrics, system metrics, files, and logs)
X
X
X
Edit experiment panels and workspaces
X
X
Log experiments
X
X
Delete experiments
X (team members can only delete experiments they created)
X
Stop experiments
X (team members can only stop experiments they created)
X
Artifacts
The proceeding table lists permissions that apply to all artifacts across a given team.
Permissions
View-Only
Team Member
Team Admin
View artifacts
X
X
X
Create artifacts
X
X
Delete artifacts
X
X
Edit metadata
X
X
Edit aliases
X
X
Delete aliases
X
X
Download artifact
X
X
System settings (W&B Server only)
Use system permissions to create and manage teams and their members and to adjust system settings. These privileges enable you to effectively administer and maintain the W&B instance.
Permissions
View-Only
Team Member
Team Admin
System Admin
Configure system settings
X
Create/delete teams
X
Team service account behavior
When you configure a team in your training environment, you can use a service account from that team to log runs in either of private or public projects within that team. Additionally, you can attribute those runs to a user if WANDB_USERNAME or WANDB_USER_EMAIL variable exists in your environment and the referenced user is part of that team.
When you do not configure a team in your training environment and use a service account, the runs log to the named project within that service account’s parent team. In this case as well, you can attribute the runs to a user if WANDB_USERNAME or WANDB_USER_EMAIL variable exists in your environment and the referenced user is part of the service account’s parent team.
A service account can not log runs to a private project in a team different from its parent team. A service account can log to runs to project only if the project is set to Open project visibility.
Team trials
See the pricing page for more information on W&B plans. You can download all your data at any time, either using the dashboard UI or the Export API.
Privacy settings
You can see the privacy settings of all team projects on the team settings page:
app.wandb.ai/teams/your-team-name
Advanced configuration
Secure storage connector
The team-level secure storage connector allows teams to use their own cloud storage bucket with W&B. This provides greater data access control and data isolation for teams with highly sensitive data or strict compliance requirements. Refer to Secure Storage Connector for more information.
4.4.6 - Manage storage
Ways to manage W&B data storage.
If you are approaching or exceeding your storage limit, there are multiple paths forward to manage your data. The path that’s best for you will depend on your account type and your current project setup.
Manage storage consumption
W&B offers different methods of optimizing your storage consumption:
Use reference artifacts to track files saved outside the W&B system, instead of uploading them to W&B storage.
You can also choose to delete data to remain under your storage limit. There are several ways to do this:
Delete data interactively with the app UI.
Set a TTL policy on Artifacts so they are automatically deleted.
4.4.7 - System metrics
Metrics automatically logged by W&B.
This page provides detailed information about the system metrics that are tracked by the W&B SDK.
wandb automatically logs system metrics every 15 seconds.
CPU
Process CPU Percent (CPU)
Percentage of CPU usage by the process, normalized by the number of available CPUs.
W&B assigns a cpu tag to this metric.
Process CPU Threads
The number of threads utilized by the process.
W&B assigns a proc.cpu.threads tag to this metric.
Disk
By default, the usage metrics are collected for the / path. To configure the paths to be monitored, use the following setting:
run = wandb.init(
settings=wandb.Settings(
x_stats_disk_paths=("/System/Volumes/Data", "/home", "/mnt/data"),
),
)
Disk Usage Percent
Represents the total system disk usage in percentage for specified paths.
W&B assigns a disk.{path}.usagePercent tag to this metric.
Disk Usage
Represents the total system disk usage in gigabytes (GB) for specified paths.
The paths that are accessible are sampled, and the disk usage (in GB) for each path is appended to the samples.
W&B assigns a disk.{path}.usageGB tag to this metric.
Disk In
Indicates the total system disk read in megabytes (MB).
The initial disk read bytes are recorded when the first sample is taken. Subsequent samples calculate the difference between the current read bytes and the initial value.
W&B assigns a disk.in tag to this metric.
Disk Out
Represents the total system disk write in megabytes (MB).
Similar to Disk In, the initial disk write bytes are recorded when the first sample is taken. Subsequent samples calculate the difference between the current write bytes and the initial value.
W&B assigns a disk.out tag to this metric.
Memory
Process Memory RSS
Represents the Memory Resident Set Size (RSS) in megabytes (MB) for the process. RSS is the portion of memory occupied by a process that is held in main memory (RAM).
W&B assigns a proc.memory.rssMB tag to this metric.
Process Memory Percent
Indicates the memory usage of the process as a percentage of the total available memory.
W&B assigns a proc.memory.percent tag to this metric.
Memory Percent
Represents the total system memory usage as a percentage of the total available memory.
W&B assigns a memory_percent tag to this metric.
Memory Available
Indicates the total available system memory in megabytes (MB).
W&B assigns a proc.memory.availableMB tag to this metric.
Network
Network Sent
Represents the total bytes sent over the network.
The initial bytes sent are recorded when the metric is first initialized. Subsequent samples calculate the difference between the current bytes sent and the initial value.
W&B assigns a network.sent tag to this metric.
Network Received
Indicates the total bytes received over the network.
Similar to Network Sent, the initial bytes received are recorded when the metric is first initialized. Subsequent samples calculate the difference between the current bytes received and the initial value.
W&B assigns a network.recv tag to this metric.
NVIDIA GPU
In addition to the metrics described below, if the process and/or its descendants use a particular GPU, W&B captures the corresponding metrics as gpu.process.{gpu_index}.{metric_name}
GPU Memory Utilization
Represents the GPU memory utilization in percent for each GPU.
W&B assigns a gpu.{gpu_index}.memory tag to this metric.
GPU Memory Allocated
Indicates the GPU memory allocated as a percentage of the total available memory for each GPU.
W&B assigns a gpu.{gpu_index}.memoryAllocated tag to this metric.
GPU Memory Allocated Bytes
Specifies the GPU memory allocated in bytes for each GPU.
W&B assigns a gpu.{gpu_index}.memoryAllocatedBytes tag to this metric.
GPU Utilization
Reflects the GPU utilization in percent for each GPU.
W&B assigns a gpu.{gpu_index}.gpu tag to this metric.
GPU Temperature
The GPU temperature in Celsius for each GPU.
W&B assigns a gpu.{gpu_index}.temp tag to this metric.
GPU Power Usage Watts
Indicates the GPU power usage in Watts for each GPU.
W&B assigns a gpu.{gpu_index}.powerWatts tag to this metric.
GPU Power Usage Percent
Reflects the GPU power usage as a percentage of its power capacity for each GPU.
W&B assigns a gpu.{gpu_index}.powerPercent tag to this metric.
GPU SM Clock Speed
Represents the clock speed of the Streaming Multiprocessor (SM) on the GPU in MHz. This metric is indicative of the processing speed within the GPU cores responsible for computation tasks.
W&B assigns a gpu.{gpu_index}.smClock tag to this metric.
GPU Memory Clock Speed
Represents the clock speed of the GPU memory in MHz, which influences the rate of data transfer between the GPU memory and processing cores.
W&B assigns a gpu.{gpu_index}.memoryClock tag to this metric.
GPU Graphics Clock Speed
Represents the base clock speed for graphics rendering operations on the GPU, expressed in MHz. This metric often reflects performance during visualization or rendering tasks.
W&B assigns a gpu.{gpu_index}.graphicsClock tag to this metric.
GPU Corrected Memory Errors
Tracks the count of memory errors on the GPU that W&B automatically corrects by error-checking protocols, indicating recoverable hardware issues.
W&B assigns a gpu.{gpu_index}.correctedMemoryErrors tag to this metric.
GPU Uncorrected Memory Errors
Tracks the count of memory errors on the GPU that W&B uncorrected, indicating non-recoverable errors which can impact processing reliability.
W&B assigns a gpu.{gpu_index}.unCorrectedMemoryErrors tag to this metric.
GPU Encoder Utilization
Represents the percentage utilization of the GPU’s video encoder, indicating its load when encoding tasks (for example, video rendering) are running.
W&B assigns a gpu.{gpu_index}.encoderUtilization tag to this metric.
AMD GPU
W&B extracts metrics from the output of the rocm-smi tool supplied by AMD (rocm-smi -a --json).
ROCm 6.x (latest) and 5.x formats are supported. Learn more about ROCm formats in the AMD ROCm documentation. The newer format includes more details.
AMD GPU Utilization
Represents the GPU utilization in percent for each AMD GPU device.
W&B assigns a gpu.{gpu_index}.gpu tag to this metric.
AMD GPU Memory Allocated
Indicates the GPU memory allocated as a percentage of the total available memory for each AMD GPU device.
W&B assigns a gpu.{gpu_index}.memoryAllocated tag to this metric.
AMD GPU Temperature
The GPU temperature in Celsius for each AMD GPU device.
W&B assigns a gpu.{gpu_index}.temp tag to this metric.
AMD GPU Power Usage Watts
The GPU power usage in Watts for each AMD GPU device.
W&B assigns a gpu.{gpu_index}.powerWatts tag to this metric.
AMD GPU Power Usage Percent
Reflects the GPU power usage as a percentage of its power capacity for each AMD GPU device.
W&B assigns a gpu.{gpu_index}.powerPercent to this metric.
Apple ARM Mac GPU
Apple GPU Utilization
Indicates the GPU utilization in percent for Apple GPU devices, specifically on ARM Macs.
W&B assigns a gpu.0.gpu tag to this metric.
Apple GPU Memory Allocated
The GPU memory allocated as a percentage of the total available memory for Apple GPU devices on ARM Macs.
W&B assigns a gpu.0.memoryAllocated tag to this metric.
Apple GPU Temperature
The GPU temperature in Celsius for Apple GPU devices on ARM Macs.
W&B assigns a gpu.0.temp tag to this metric.
Apple GPU Power Usage Watts
The GPU power usage in Watts for Apple GPU devices on ARM Macs.
W&B assigns a gpu.0.powerWatts tag to this metric.
Apple GPU Power Usage Percent
The GPU power usage as a percentage of its power capacity for Apple GPU devices on ARM Macs.
W&B assigns a gpu.0.powerPercent tag to this metric.
Graphcore IPU
Graphcore IPUs (Intelligence Processing Units) are unique hardware accelerators designed specifically for machine intelligence tasks.
IPU Device Metrics
These metrics represent various statistics for a specific IPU device. Each metric has a device ID (device_id) and a metric key (metric_key) to identify it. W&B assigns a ipu.{device_id}.{metric_key} tag to this metric.
Metrics are extracted using the proprietary gcipuinfo library, which interacts with Graphcore’s gcipuinfo binary. The sample method fetches these metrics for each IPU device associated with the process ID (pid). Only the metrics that change over time, or the first time a device’s metrics are fetched, are logged to avoid logging redundant data.
For each metric, the method parse_metric is used to extract the metric’s value from its raw string representation. The metrics are then aggregated across multiple samples using the aggregate method.
The following lists available metrics and their units:
Average Board Temperature (average board temp (C)): Temperature of the IPU board in Celsius.
Average Die Temperature (average die temp (C)): Temperature of the IPU die in Celsius.
Clock Speed (clock (MHz)): The clock speed of the IPU in MHz.
IPU Power (ipu power (W)): Power consumption of the IPU in Watts.
IPU Utilization (ipu utilisation (%)): Percentage of IPU utilization.
IPU Session Utilization (ipu utilisation (session) (%)): IPU utilization percentage specific to the current session.
Data Link Speed (speed (GT/s)): Speed of data transmission in Giga-transfers per second.
Google Cloud TPU
Tensor Processing Units (TPUs) are Google’s custom-developed ASICs (Application Specific Integrated Circuits) used to accelerate machine learning workloads.
TPU Memory usage
The current High Bandwidth Memory usage in bytes per TPU core.
W&B assigns a tpu.{tpu_index}.memoryUsageBytes tag to this metric.
TPU Memory usage percentage
The current High Bandwidth Memory usage in percent per TPU core.
W&B assigns a tpu.{tpu_index}.memoryUsageBytes tag to this metric.
TPU Duty cycle
TensorCore duty cycle percentage per TPU device. Tracks the percentage of time over the sample period during which the accelerator TensorCore was actively processing. A larger value means better TensorCore utilization.
W&B assigns a tpu.{tpu_index}.dutyCycle tag to this metric.
AWS Trainium
AWS Trainium is a specialized hardware platform offered by AWS that focuses on accelerating machine learning workloads. The neuron-monitor tool from AWS is used to capture the AWS Trainium metrics.
Trainium Neuron Core Utilization
The utilization percentage of each NeuronCore, reported on a per-core basis.
W&B assigns a trn.{core_index}.neuroncore_utilization tag to this metric.
Trainium Host Memory Usage, Total
The total memory consumption on the host in bytes.
W&B assigns a trn.host_total_memory_usage tag to this metric.
Trainium Neuron Device Total Memory Usage
The total memory usage on the Neuron device in bytes.
W&B assigns a trn.neuron_device_total_memory_usage) tag to this metric.
Trainium Host Memory Usage Breakdown:
The following is a breakdown of memory usage on the host:
Application Memory (trn.host_total_memory_usage.application_memory): Memory used by the application.
Constants (trn.host_total_memory_usage.constants): Memory used for constants.
DMA Buffers (trn.host_total_memory_usage.dma_buffers): Memory used for Direct Memory Access buffers.
Tensors (trn.host_total_memory_usage.tensors): Memory used for tensors.
Trainium Neuron Core Memory Usage Breakdown
Detailed memory usage information for each NeuronCore:
Capture and log metrics from external endpoints that expose OpenMetrics / Prometheus-compatible data with support for custom regex-based metric filters to be applied to the consumed endpoints.
Refer to this report for a detailed example of how to use this feature in a particular case of monitoring GPU cluster performance with the NVIDIA DCGM-Exporter.
4.4.8 - Anonymous mode
Log and visualize data without a W&B account
Are you publishing code that you want anyone to be able to run easily? Use anonymous mode to let someone run your code, see a W&B dashboard, and visualize results without needing to create a W&B account first.
Allow results to be logged in anonymous mode with:
import wandb
wandb.init(anonymous="allow")
For example, the proceeding code snippet shows how to create and log an artifact with W&B: