PyTorch
2 minute read
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.
Try our integration out in a Colab notebook.
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 wandb.watch
To automatically log gradients, you can call wandb.watch
and pass in your PyTorch model.
If you need to track multiple models in the same script, you can call wandb.watch
on each model separately. Reference documentation for this function is here.
wandb.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
.

For more on logging and visualizing datasets and models, check out our guide to W&B Tables.
Profile PyTorch code

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.
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.