You can integrate fastai with W&B using theDocumentation Index
Fetch the complete documentation index at: https://wb-21fd5541-style-guide-models-integrations-20260527-015516.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
WandbCallback class to track experiments, log metrics, and visualize model performance during training. This page shows how to set up authentication, add the callback to your training loop, and configure logging for both single-process and distributed training. Check out these interactive docs with examples for more details.
Sign up and create an API key
An API key authenticates your machine to W&B. You can generate an API key from your user profile.For a more streamlined approach, create an API key by going directly to User Settings. Copy the newly created API key immediately 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.
Install the wandb library and log in
To install the wandb library locally and log in:
- Command Line
- Python
- Python notebook
-
Set the
WANDB_API_KEYenvironment variable to your API key. -
Install the
wandblibrary and log in.
Add the WandbCallback to the learner or fit method
To start logging your fastai training runs to W&B, attach the WandbCallback to either a single fit call or the learner itself.
If you use version 1 of fastai, refer to the fastai v1 docs.
WandbCallback arguments
Use the following arguments to control whatWandbCallback logs during training:
| Args | Description |
|---|---|
log | Whether to log the model’s: gradients, parameters, all, or None (default). Losses and metrics are always logged. |
log_preds | Whether to log prediction samples (default to True). |
log_preds_every_epoch | Whether to log predictions every epoch or at the end (default to False). |
log_model | Whether to log the model (default to False). This also requires SaveModelCallback. |
model_name | The name of the file to save, overrides SaveModelCallback. |
log_dataset |
Note: subfolder “models” is always ignored. |
dataset_name | Name of the logged dataset (default to folder name). |
valid_dl | DataLoaders containing items used for prediction samples (default to random items from learn.dls.valid). |
n_preds | Number of logged predictions (default to 36). |
seed | Used for defining random samples. |
log_dataset(path, name=None, metadata={})log_model(path, name=None, metadata={})
Distributed training
fastai supports distributed training by using the context manager distrib_ctx. W&B supports this automatically and enables you to track your multi-GPU experiments without additional configuration. The following sections describe how to integrate W&B with distributed training and how to limit logging to the main process.
Review this minimal example:
- Script
- Python notebook
Log only on the main process
In the preceding examples,wandb launches one run per process. At the end of the training, you have two runs. This can sometimes be confusing, and you may want to log only on the main process. To do so, you must manually detect which process you are in and avoid creating runs (calling wandb.init() in all other processes).
- Script
- Python notebook
Examples
For end-to-end demonstrations of the fastai integration, see the following references:- Visualize, track, and compare fastai models: A documented walkthrough.
- Image segmentation on CamVid: A sample use case of the integration.