IterationTimer#

class IterationTimer(warmup_iter=1)[source]#

Bases: HookBase

Measure data/batch latency and append timing and ETA to iteration logs.

Times each training iteration and feeds the results into trainer.storage and the per-iteration log string. In before_step it records data_time (time spent waiting for the batch); in after_step it records batch_time (full iteration), decrements the remaining- iteration counter, and appends Data, Batch, and Remain (ETA, computed from the running average batch time) to comm_info["iter_info"]. The remaining-iteration budget is initialized in before_train and the per-iteration timer is reset in before_epoch. Registered as IterationTimer.

Parameters:

warmup_iter (int) – Number of initial iterations whose timing is reset (excluded from the running averages) so startup/compile overhead does not skew ETA. Defaults to 1.

Example

Add to cfg.hooks; it times each iteration and feeds the timing into trainer.storage and the per-step log line:

hooks = [dict(type="IterationTimer", warmup_iter=2)]
# → puts scalars "data_time" (before_step) and "batch_time" (after_step)
#   into trainer.storage and appends "Data … Batch … Remain HH:MM:SS"
#   (ETA) to comm_info["iter_info"]; the first 2 iters reset the averages
after_step()[source]#

Record batch time and append timing fields to iter_info.

before_epoch()[source]#

Reset the per-iteration timer at the start of each epoch.

before_step()[source]#

Record data loading time before the model consumes the batch.

before_train()[source]#

Initialize remaining-iteration accounting at train start.