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()andclose().- 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:
Trueif the current process is the main process (or if accelerator isNone),Falseotherwise.
- 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
MetricsReportto the console via a tqdm progress bar if provided, else just writes the report to the console.- Parameters:
pbar (tqdm | None) –
tqdmprogress bar instance used forpbar.write().
- 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_metricsis 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 firstwrite(), this logger will call it automatically withproject="AgileRL". For more control over the run configuration, callwandb.init()(oragilerl.utils.utils.init_wandb()) before creating this logger.Handles distributed-training synchronisation when an
Acceleratoris provided.- Parameters:
accelerator (Accelerator | None) – HuggingFace Accelerator, or
None.
- 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.
- 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 thetrain/global_stepvalue.- Parameters:
- write(report: MetricsReport) None¶
Write the metrics report to TensorBoard.
- Parameters:
report (MetricsReport) – The metrics report to write.