Logger

The logger hierarchy consumes MetricsReport snapshots and writes them to various backends. A training run typically uses several loggers at once, e.g. [StdOutLogger, WandbLogger].

Base Class

class agilerl.logger.Logger

Base class for all training loggers.

Subclasses must implement write() and close().

abstract close() None

Release any resources held by the logger.

static on_main_process(accelerator: Accelerator | None) Generator[bool, None, None]

Synchronize distributed processes, yielding whether this is the main one.

Parameters:

accelerator (Accelerator | None) – HuggingFace Accelerator, or None.

Yields:

True if the current process is the main process (or if accelerator is None), False otherwise.

abstract write(report: MetricsReport) None

Persist one snapshot of population metrics.

Parameters:

report – The metrics report to log.

Console

class agilerl.logger.StdOutLogger(pbar: tqdm | None = None, accelerator: Accelerator | None = None)

Writes the tabular MetricsReport to the console via a tqdm progress bar if provided, else just writes the report to the console.

Parameters:

pbar (tqdm | None) – tqdm progress bar instance used for pbar.write().

close() None

Release any resources held by the logger.

write(report: MetricsReport) None

Write the metrics report to the console.

Only the main process emits output; non-main ranks return without printing so distributed runs (where report_metrics is called on every rank to keep collectives symmetric) don’t duplicate the table.

Parameters:

report (MetricsReport) – The metrics report to write.

Weights & Biases

class agilerl.logger.WandbLogger(accelerator: Accelerator | None = None, project: str = 'AgileRL')

Logs a flat metrics dict to Weights & Biases.

If wandb.init() has not been called before the first write(), this logger will call it automatically with project="AgileRL". For more control over the run configuration, call wandb.init() (or agilerl.utils.utils.init_wandb()) before creating this logger.

Handles distributed-training synchronisation when an Accelerator is provided.

Parameters:

accelerator (Accelerator | None) – HuggingFace Accelerator, or None.

close() None

Mark a run as finished on W&B, and finish uploading all data.

write(report: MetricsReport) None

Write the metrics report to W&B.

Parameters:

report (MetricsReport) – The metrics report to write.

CSV

class agilerl.logger.CSVLogger(path: str | Path)

Appends one row per write() call to a CSV file.

Parameters:

path (str | Path) – Filesystem path for the CSV file.

close() None

Close the CSV file.

write(report: MetricsReport) None

Write the metrics report to the CSV file.

Parameters:

report (MetricsReport) – The metrics report to write.

TensorBoard

class agilerl.logger.TensorboardLogger(log_dir: str | Path | None = None, experiment_name: str | None = None, accelerator: Accelerator | None = None)

Logs scalar metrics to TensorBoard via torch.utils.tensorboard.SummaryWriter.

Each key in MetricsReport.to_dict() is written as a scalar at the train/global_step value.

Parameters:
  • log_dir (str | Path | None) – Directory for TensorBoard event files, defaults to None, which will use the default TensorBoard log directory tensorboard_logs.

  • experiment_name (str | None) – Name of the experiment, defaults to None.

  • accelerator (Accelerator | None) – HuggingFace Accelerator, or None.

close() None

Close the TensorBoard writer.

write(report: MetricsReport) None

Write the metrics report to TensorBoard.

Parameters:

report (MetricsReport) – The metrics report to write.