CheckpointPolicy
CheckpointPolicy(*, checkpoint_frequency: int, initial_checkpointed_step: int | None, rollback_controller: ExperimentRollbackController, metrics_tracker: MetricsTracker, save_checkpoint: Callable[[], None], save_final_checkpoint: Callable[[], None], perform_rollback: Callable[[], int | None], notify_tester_of_update: Callable[[], None]) -> NoneNarrow seam giving a learner's run loop access to Experiment-owned checkpoint/rollback machinery, without the learner needing to import CheckpointManager/ExperimentRollbackController/ Tester types directly. Owns the "step last checkpointed at" state itself, so a learner's run loop doesn't need to track it externally.
Initialize the checkpoint policy.
Parameters:
checkpoint_frequency(int) – The number of environment steps between periodic checkpoints.initial_checkpointed_step(int | None) – The step the run resumed from (already checkpointed), orNonefor a fresh run with no checkpoint saved yet.rollback_controller(ExperimentRollbackController) – The experiment's automatic rollback controller.metrics_tracker(MetricsTracker) – The experiment's metrics tracker, for reading the rollback monitor's metric.save_checkpoint(Callable[[], None]) – Saves a periodic checkpoint.save_final_checkpoint(Callable[[], None]) – Saves the checkpoint written when training stops.perform_rollback(Callable[[], int | None]) – Performs an automatic rollback, returning the restored step, orNoneif none was performed.notify_tester_of_update(Callable[[], None]) – Pushes the learner's latest weights to the tester.
Raises:
ValueError– Ifcheckpoint_frequencyis not positive.
Methods
after_update
after_update(step: int) -> NoneRun the post-update rollback protocol: feed the monitored metric, then roll back if due.
Parameters:
step(int) – The current environment step.
feed_rollback_metric
feed_rollback_metric(step: int) -> NoneFeed the automatic rollback monitor's metric average into the rollback controller, if enabled.
Warns once if the monitored metric has no data after many learner iterations, since that usually means the configured metric tag doesn't match what's actually logged.
Parameters:
step(int) – The current environment step.
finish
finish(step: int) -> NoneSave the final checkpoint when training stops, unless the current step is already checkpointed.
Parameters:
step(int) – The environment step training stopped at.
is_periodic_checkpoint_due
is_periodic_checkpoint_due(step: int) -> boolReturn whether a new periodic checkpoint should be saved at the given step.
Parameters:
step(int) – The current environment step.
Returns:
bool–Truewhen a new periodic checkpoint should be written.
maybe_checkpoint
maybe_checkpoint(step: int) -> NoneSave a periodic checkpoint when one is due at the given step.
Parameters:
step(int) – The current environment step.
notify_tester_of_update
notify_tester_of_update() -> NonePush the learner's latest weights to the tester.
perform_rollback
perform_rollback() -> int | NonePerform an automatic rollback and record the restored step as the new checkpointed-at step.
Returns:
int | None– The restored environment step, orNoneif no rollback was performed.
save_checkpoint
save_checkpoint(step: int) -> NoneSave a periodic checkpoint and record the step it was saved at.
Parameters:
step(int) – The environment step the checkpoint is saved at.
save_final_checkpoint
save_final_checkpoint(step: int) -> NoneSave the final checkpoint written when training stops, and record the step it was saved at.
Parameters:
step(int) – The environment step the checkpoint is saved at.
should_rollback
should_rollback() -> boolReturn whether an automatic rollback is currently due.
should_save_final_checkpoint
should_save_final_checkpoint(step: int) -> boolReturn whether stopping should emit a final checkpoint.
Parameters:
step(int) – The current environment step.
Returns:
bool–Truewhen the stop path should save a checkpoint.