InformationWriter#

class InformationWriter(log_frequency=1, step_offset=0)[source]#

Bases: HookBase

Assemble per-step console logs and write scalar train metrics.

The primary training logger. In before_step it seeds the shared comm_info["iter_info"] string with the epoch/iteration position. In after_step it filters the model output dict down to scalar-like entries (dropping large tensors such as logits/masks and match_* keys, and mapping total_loss to loss), records them in trainer.storage, appends them plus the current learning rate to the iteration log, emits that line to the logger every log_frequency global steps (and always on the last iteration of an epoch), and mirrors each scalar to the writer under train_batch/* (with params/lr). In after_epoch it logs the epoch-average of each tracked key under train/*. Registered as InformationWriter.

Parameters:
  • log_frequency (int) – Emit the assembled console line every this many global steps (coerced to at least 1). Writer scalars are logged every step regardless. Defaults to 1.

  • step_offset (int) – Constant added to the computed global step, e.g. to continue a warm-started run’s W&B x-axis from where the parent checkpoint left off. Defaults to 0.

Note

Writer scalars are only emitted when trainer.writer is not None. The global step is computed to match the other logging/diagnostic hooks so all curves share an x-axis.

Example

Add to cfg.hooks; it is the main per-step logger — it records the scalar model outputs and learning rate and mirrors them to the writer:

hooks = [dict(type="InformationWriter", log_frequency=20)]
# → every step writes "train_batch/<key>" for each scalar loss/metric
#   and "params/lr" to the writer; emits the assembled console log line
#   every 20 steps; in after_epoch writes the "train/<key>" epoch averages
after_epoch()[source]#

Write epoch-average training metrics for keys seen this epoch.

after_step()[source]#

Filter scalar-like model outputs and write train metrics.

before_step()[source]#

Append epoch and batch position to the current iteration summary.

before_train()[source]#

Initialize the shared iteration-info string used by logging hooks.