espnet3.components.callbacks.default_callbacks.TrainBatchMetricsLogger
espnet3.components.callbacks.default_callbacks.TrainBatchMetricsLogger
class espnet3.components.callbacks.default_callbacks.TrainBatchMetricsLogger(log_every_n_steps: int = 500)
Bases: Callback
Log averaged training metrics every N steps as a single line.
This callback aggregates numeric metrics reported via Lightning’s trainer.callback_metrics during training and emits a compact, human-friendly log line at a fixed interval (log_every_n_steps). Metrics are averaged over the interval and the internal buffer is cleared after logging.
The log line is ordered as: : - Time metrics: iter_time, forward_time, backward_time, optim_step_time, train_time (when available)
- User metrics (stats from the model,
train/prefix removed) - Learning rates (
optim{idx}_lr{group})
Example
>>> cb = TrainBatchMetricsLogger(log_every_n_steps=200)
>>> trainer = Trainer(callbacks=[cb, ...])Example log output: : 20epoch🚋4201-4400batch: iter_time=6.212e-05, forward_time=0.145, backward_time=0.159, optim_step_time=0.015, train_time=0.562, loss_ctc=69.86, loss_att=32.128, acc=0.868, loss=46.669, optim0_lr0=2.458e-06
Initialize the logger with a reporting interval.
on_after_backward(trainer, pl_module)
Record backward time.
on_after_optimizer_step(trainer, pl_module)
Record optimizer step time.
on_before_backward(trainer, pl_module, loss)
Mark the end of forward pass and start backward timing.
on_before_optimizer_step(trainer, pl_module, optimizer)
Start optimizer step timing.
on_train_batch_end(trainer, pl_module, outputs, batch, batch_idx)
Aggregate metrics and emit a summary line when due.
on_train_batch_start(trainer, pl_module, batch, batch_idx)
Start timers for a training batch.
on_train_epoch_end(trainer, pl_module)
Reset buffers at the end of each training epoch.
