CheckpointSaverIteration#

class CheckpointSaverIteration(save_freq=None, save_iter_checkpoints=False, backend=None)[source]#

Bases: HookBase

Save iteration-oriented checkpoints on a pure global-step cadence.

Like CheckpointSaver, but the save decision depends only on the global step: in after_step it saves whenever step_count % save_freq == 0. When cfg.evaluate is set and an evaluator has published current_metric_value in trainer.comm_info, an improving metric also updates trainer.best_metric_value and writes model_best. A final checkpoint is written in after_train. Save logic is delegated to CheckpointManager. Registered as CheckpointSaverIteration.

Parameters:
  • save_freq (int, optional) – Save every this many global steps. None disables periodic saving. Defaults to None.

  • save_iter_checkpoints (bool) – If True, keep a distinct per-step checkpoint copy at each save instead of only rolling the latest. Defaults to False.

  • backend (str, optional) – Deprecated selector for the on-disk format, superseded by the top-level checkpoint_format config key. "dcp" maps to the standard (hybrid) format and "torch" to the legacy format; None resolves to standard. Defaults to None.

Note

Called on all ranks because a standard-format save is collective; because the cadence is purely step-based it is identical across ranks. Place any evaluator hook before this saver so the metric is available for the model_best decision.

Example

Add to cfg.hooks; in after_step it saves on a pure global-step cadence:

hooks = [dict(type="CheckpointSaverIteration", save_freq=5000)]
# → writes a rolling checkpoint every 5000 global steps (and a final
#   one in after_train); with cfg.evaluate set and an evaluator's
#   comm_info["current_metric_value"], an improving metric also updates
#   trainer.best_metric_value and writes model_best
after_epoch()[source]#

Save a last-step checkpoint after epoch-end metrics are logged.

after_step()[source]#

Save whenever the configured global-step cadence is reached.

after_train()[source]#

Persist a final checkpoint after the last training step.

before_train()[source]#

Seed internal step count from resumed trainer progress.