Skip to content

CheckpointPolicy ​

python
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]) -> None

Narrow 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), or None for 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, or None if none was performed.
  • notify_tester_of_update (Callable[[], None]) – Pushes the learner's latest weights to the tester.

Raises:

  • ValueError – If checkpoint_frequency is not positive.

Source

Methods ​

after_update ​

python
after_update(step: int) -> None

Run the post-update rollback protocol: feed the monitored metric, then roll back if due.

Parameters:

  • step (int) – The current environment step.

Source

feed_rollback_metric ​

python
feed_rollback_metric(step: int) -> None

Feed 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.

Source

finish ​

python
finish(step: int) -> None

Save the final checkpoint when training stops, unless the current step is already checkpointed.

Parameters:

  • step (int) – The environment step training stopped at.

Source

is_periodic_checkpoint_due ​

python
is_periodic_checkpoint_due(step: int) -> bool

Return whether a new periodic checkpoint should be saved at the given step.

Parameters:

  • step (int) – The current environment step.

Returns:

  • bool – True when a new periodic checkpoint should be written.

Source

maybe_checkpoint ​

python
maybe_checkpoint(step: int) -> None

Save a periodic checkpoint when one is due at the given step.

Parameters:

  • step (int) – The current environment step.

Source

notify_tester_of_update ​

python
notify_tester_of_update() -> None

Push the learner's latest weights to the tester.

Source

perform_rollback ​

python
perform_rollback() -> int | None

Perform an automatic rollback and record the restored step as the new checkpointed-at step.

Returns:

  • int | None – The restored environment step, or None if no rollback was performed.

Source

save_checkpoint ​

python
save_checkpoint(step: int) -> None

Save a periodic checkpoint and record the step it was saved at.

Parameters:

  • step (int) – The environment step the checkpoint is saved at.

Source

save_final_checkpoint ​

python
save_final_checkpoint(step: int) -> None

Save 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.

Source

should_rollback ​

python
should_rollback() -> bool

Return whether an automatic rollback is currently due.

Source

should_save_final_checkpoint ​

python
should_save_final_checkpoint(step: int) -> bool

Return whether stopping should emit a final checkpoint.

Parameters:

  • step (int) – The current environment step.

Returns:

  • bool – True when the stop path should save a checkpoint.

Source