Skip to main content
This page shows how to use the W&B handler with PyTorch Ignite to automatically log training and validation metrics, model and optimizer parameters, gradients, and model checkpoints during your experiments. Ignite supports a W&B handler to log metrics, model and optimizer parameters, and gradients during training and validation. You can also use it to log model checkpoints to the W&B cloud. This class wraps the W&B Python SDK (wandb), so you can call any wandb function using this wrapper. See examples on how to save model parameters and gradients. For additional context, see the following resources:

Basic setup

The following example defines a simple convolutional model and data loaders for MNIST. The logging examples that follow use these pieces.
Using WandBLogger in Ignite is a modular process. First, create a WandBLogger object. Next, attach it to a trainer or evaluator to automatically log the metrics. This example shows:
  • Logs training loss, attached to the trainer object.
  • Logs validation loss, attached to the evaluator.
  • Logs optional parameters, such as learning rate.
  • Watches the model.
With the logger attached, Ignite streams training and validation metrics, optimizer parameters, and model gradients to your W&B project automatically. You can optionally use Ignite EVENTS to log the metrics directly to the terminal.
This code generates these visualizations:
PyTorch Ignite training dashboard
PyTorch Ignite performance
PyTorch Ignite hyperparameter tuning results
PyTorch Ignite model comparison dashboard
Refer to the Ignite Docs for more details.