Skip to main content
Try in Colab PyTorch is one of the most popular frameworks for deep learning in Python, especially among researchers. W&B provides first class support for PyTorch, from logging gradients to profiling your code on the CPU and GPU. You can also see our example repo for scripts, including one on hyperparameter optimization using Hyperband on Fashion MNIST, plus the W&B Dashboard it generates.

Log gradients with run.watch

To automatically log gradients, you can call wandb.Run.watch() and pass in your PyTorch model.
If you need to track multiple models in the same script, you can call wandb.Run.watch() on each model separately.
Gradients, metrics, and the graph won’t be logged until wandb.Run.log() is called after a forward and backward pass.

Log images and media

You can pass PyTorch Tensors with image data into wandb.Image and utilities from torchvision will be used to convert them to images automatically:
For more on logging rich media to W&B in PyTorch and other frameworks, check out our media logging guide. If you also want to include information alongside media, like your model’s predictions or derived metrics, use a wandb.Table.
PyTorch model results
For more on logging and visualizing datasets and models, check out our guide to W&B Tables.

Profile PyTorch code

PyTorch execution traces
W&B integrates directly with PyTorch Kineto’s Tensorboard plugin to provide tools for profiling PyTorch code, inspecting the details of CPU and GPU communication, and identifying bottlenecks and optimizations.
See and run working example code in this Colab.
The interactive trace viewing tool is based on the Chrome Trace Viewer, which works best with the Chrome browser.