Skip to content

CheckpointManager ​

python
CheckpointManager(output_directory: str | PathLike, configuration: CheckpointConfiguration, file_types: Iterable[CheckpointFileRegistration] = ()) -> None

Initialize the checkpoint manager.

Parameters:

  • output_directory (str | PathLike) – The experiment's output directory (checkpoints live in a checkpoints subdirectory).
  • configuration (CheckpointConfiguration) – The checkpoint retention configuration.
  • file_types (Iterable[CheckpointFileRegistration]) – The checkpoint file types this manager can decode.

Source

Properties ​

checkpoints_directory ​

python
checkpoints_directory: Path

Source

latest_checkpoint_number ​

python
latest_checkpoint_number: int | None

Get the number of the latest checkpoint, or None if no checkpoints exist.

Returns:

  • int | None – The latest checkpoint number or None.

Source

Methods ​

load_latest ​

python
load_latest() -> Checkpoint

Source

move_checkpoints_to_rollback_directory ​

python
move_checkpoints_to_rollback_directory(numbers: list[int]) -> Path | None

Move checkpoint directories into a new rollback_N directory.

Creates a rollback_1 directory (or rollback_2, and similar values if it already exists) inside the checkpoints directory and moves each listed checkpoint into it. The checkpoint directories are not renamed; they keep their original names.

Parameters:

  • numbers (list[int]) – The checkpoint numbers to move.

Returns:

  • Path | None – The rollback directory path, or None if no checkpoints were moved.

Source

register ​

python
register(name: str, file_type: type[CheckpointFile]) -> None

Register a checkpoint file type this manager can decode.

The type is registered under every extension it declares via file_type.extensions().

Parameters:

  • name (str) – The checkpoint file's base name; must not contain '.'.
  • file_type (type[CheckpointFile]) – The concrete CheckpointFile subclass to decode files with this name into.

Raises:

  • ValueError – If name contains '.'.
  • TypeError – If file_type is not a concrete CheckpointFile subclass.

Source

reserve_latest ​

python
reserve_latest(checkpoint: Checkpoint) -> Path

Assign the next checkpoint number to checkpoint and create its directory without writing any files.

Reserving synchronously lets callers hand the (slow) file writes to a background thread while the checkpoint number is immediately visible via latest_checkpoint_number.

Parameters:

  • checkpoint (Checkpoint) – The checkpoint to reserve.

Returns:

  • Path – The reserved checkpoint directory.

Source

save_latest ​

python
save_latest(checkpoint: Checkpoint) -> Path

Source

try_load_checkpoint ​

python
try_load_checkpoint(number: int) -> Checkpoint | None

Source

try_load_checkpoint_file ​

python
try_load_checkpoint_file(number: int, name: str) -> CheckpointFile | None

Load a single checkpoint file from a checkpoint directory.

Parameters:

  • number (int) – The checkpoint number.
  • name (str) – The registered checkpoint file base name.

Returns:

  • CheckpointFile | None – The loaded checkpoint file, or None when not present.

Source

try_load_latest ​

python
try_load_latest() -> Checkpoint | None

Source

write_reserved ​

python
write_reserved(checkpoint: Checkpoint) -> Path

Write the files of a checkpoint previously reserved with reserve_latest.

Parameters:

  • checkpoint (Checkpoint) – The reserved checkpoint to write.

Returns:

  • Path – The checkpoint directory.

Source