Skip to main content
Composer is a library for training neural networks better, faster, and cheaper. It includes methods for accelerating training and improving generalization. Composer also has an optional Trainer API for composing many different enhancements. Use W&B with Composer to track, visualize, and compare your training runs. Composer includes built-in W&B logging through WandBLogger.

Start logging to W&B

To start logging your Composer training runs to W&B, pass a composer.loggers.WandBLogger instance to the composer.Trainer:
from composer import Trainer
from composer.loggers import WandBLogger

trainer = Trainer(..., logger=WandBLogger())
Interactive dashboards

Use Composer’s WandBLogger

The following sections describe how the WandBLogger integrates with Composer’s Trainer. The Composer library uses the WandBLogger class in the Trainer to log metrics to W&B. Instantiate the logger and pass it to the Trainer:
wandb_logger = WandBLogger(project="gpt-5", log_artifacts=True)
trainer = Trainer(logger=wandb_logger)

Logger arguments

For the parameters you can use to customize how WandBLogger records your runs, see the Composer documentation. The following example shows a typical usage that passes run notes and a config dictionary through init_kwargs:
init_kwargs = {"notes":"Testing higher learning rate in this experiment", 
               "config":{"arch":"Llama",
                         "use_mixed_precision":True
                         }
               }

wandb_logger = WandBLogger(log_artifacts=True, init_kwargs=init_kwargs)

Log prediction samples

In addition to scalar metrics, you can log rich media such as model predictions to W&B for qualitative review. You can use Composer’s Callbacks system to control when you log to W&B with WandBLogger. The following example logs a sample of the validation images and predictions:
import wandb
from composer import Callback, State, Logger

class LogPredictions(Callback):
    def __init__(self, num_samples=100, seed=1234):
        super().__init__()
        self.num_samples = num_samples
        self.data = []
        
    def eval_batch_end(self, state: State, logger: Logger):
        """Compute predictions per batch and stores them on self.data"""
        
        if state.timer.epoch == state.max_duration: #on last val epoch
            if len(self.data) < self.num_samples:
                n = self.num_samples
                x, y = state.batch_pair
                outputs = state.outputs.argmax(-1)
                data = [[wandb.Image(x_i), y_i, y_pred] for x_i, y_i, y_pred in list(zip(x[:n], y[:n], outputs[:n]))]
                self.data += data
            
    def eval_end(self, state: State, logger: Logger):
        with wandb.init() as run:
            "Create a wandb.Table and logs it"
            columns = ['image', 'ground truth', 'prediction']
            table = wandb.Table(columns=columns, data=self.data[:self.num_samples])
            run.log({'sample_table':table}, step=int(state.timer.batch))         
...

trainer = Trainer(
    ...
    loggers=[WandBLogger()],
    callbacks=[LogPredictions()]
)