CheckpointSaverIteration#
- class CheckpointSaverIteration(save_freq=None, save_iter_checkpoints=False, backend=None)[source]#
Bases:
HookBaseSave iteration-oriented checkpoints on a pure global-step cadence.
Like
CheckpointSaver, but the save decision depends only on the global step: inafter_stepit saves wheneverstep_count % save_freq == 0. Whencfg.evaluateis set and an evaluator has publishedcurrent_metric_valueintrainer.comm_info, an improving metric also updatestrainer.best_metric_valueand writesmodel_best. A final checkpoint is written inafter_train. Save logic is delegated toCheckpointManager. Registered asCheckpointSaverIteration.- Parameters:
save_freq (int, optional) – Save every this many global steps.
Nonedisables periodic saving. Defaults toNone.save_iter_checkpoints (bool) – If
True, keep a distinct per-step checkpoint copy at each save instead of only rolling the latest. Defaults toFalse.backend (str, optional) – Deprecated selector for the on-disk format, superseded by the top-level
checkpoint_formatconfig key."dcp"maps to the standard (hybrid) format and"torch"to the legacy format;Noneresolves to standard. Defaults toNone.
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_bestdecision.Example
Add to
cfg.hooks; inafter_stepit 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