Skip to content

tenzr::checkpoint::CheckpointManager

Saves and restores named state with retention and best-metric tracking.

#include <checkpoint_manager.h>

Public Functions

Name
CheckpointManager(CheckpointOptions options ={})
~CheckpointManager()
Wait for any in-flight asynchronous saves before destruction.
CheckpointManager(const CheckpointManager & ) =delete
CheckpointManager & operator=(const CheckpointManager & ) =delete
CheckpointManager(CheckpointManager && other)
CheckpointManager & operator=(CheckpointManager && other)
void Save(uint64_t step, const std::unordered_map< std::string, Tensor > & state, std::optional< double > metric =std::nullopt)
void Save(uint64_t step, nn::Module & module, std::optional< double > metric =std::nullopt)
std::unordered_map< std::string, Tensor > Restore(uint64_t step)
std::unordered_map< std::string, Tensor > RestoreLatest()
std::unordered_map< std::string, Tensor > RestoreBest()
void Restore(uint64_t step, nn::Module & module)
void RestoreLatest(nn::Module & module)
void RestoreBest(nn::Module & module)
bool HasCheckpoints() const
uint64_t LatestStep() const
uint64_t BestStep() const
std::vector< uint64_t > AllSteps() const
void WaitUntilIdle()
Block until all pending asynchronous saves complete.
const CheckpointOptions & Options() const

Public Functions Documentation

function CheckpointManager

explicit CheckpointManager(
    CheckpointOptions options ={}
)

Parameters:

  • options Checkpoint directory, retention, and async settings.

Create the checkpoint directory if needed and load metadata for existing checkpoints.

function ~CheckpointManager

~CheckpointManager()

Wait for any in-flight asynchronous saves before destruction.

function CheckpointManager

CheckpointManager(
    const CheckpointManager & 
) =delete

function operator=

CheckpointManager & operator=(
    const CheckpointManager & 
) =delete

function CheckpointManager

CheckpointManager(
    CheckpointManager && other
)

Parameters:

  • other Manager to move from.

Move-construct a manager, leaving other without pending work.

function operator=

CheckpointManager & operator=(
    CheckpointManager && other
)

function Save

void Save(
    uint64_t step,
    const std::unordered_map< std::string, Tensor > & state,
    std::optional< double > metric =std::nullopt
)

Parameters:

  • step Training step.
  • state State tensors keyed by name.
  • metric Optional metric used for best-checkpoint selection.
  • step Training step associated with the checkpoint.
  • state Named tensors to persist.
  • metric Optional metric used to select the best checkpoint.

Save a raw state dict. Save a state dictionary, either inline or on a background thread when async is enabled.

function Save

void Save(
    uint64_t step,
    nn::Module & module,
    std::optional< double > metric =std::nullopt
)

Parameters:

  • step Training step.
  • module Module whose parameters are saved.
  • metric Optional metric used for best-checkpoint selection.
  • step Training step associated with the checkpoint.
  • module Module whose state_dict() is persisted.
  • metric Optional metric used to select the best checkpoint.

Save a module's state dict. Save a module's state dictionary.

function Restore

std::unordered_map< std::string, Tensor > Restore(
    uint64_t step
)

Parameters:

  • step Training step to restore.
  • step Checkpoint step to restore.

Return:

  • Restored state tensors keyed by name.
  • Named tensors loaded from the checkpoint.

Restore the state dict saved at step. Load the state dictionary for a specific step.

function RestoreLatest

std::unordered_map< std::string, Tensor > RestoreLatest()

Return:

  • State dict of the most recent checkpoint.
  • Named tensors loaded from the checkpoint.

Load the state dictionary of the latest checkpoint.

function RestoreBest

std::unordered_map< std::string, Tensor > RestoreBest()

Return:

  • State dict of the best-metric checkpoint.
  • Named tensors loaded from the checkpoint.

Load the state dictionary of the best-metric checkpoint.

function Restore

void Restore(
    uint64_t step,
    nn::Module & module
)

Parameters:

  • step Training step to restore.
  • module Module whose parameters are overwritten.
  • step Checkpoint step to restore.
  • module Module receiving the loaded state.

Load the checkpoint at step into module. Restore a specific step into module.

function RestoreLatest

void RestoreLatest(
    nn::Module & module
)

Parameters:

  • module Module whose parameters are overwritten.
  • module Module receiving the loaded state.

Load the most recent checkpoint into module. Restore the latest checkpoint into module.

function RestoreBest

void RestoreBest(
    nn::Module & module
)

Parameters:

  • module Module whose parameters are overwritten.
  • module Module receiving the loaded state.

Load the best-metric checkpoint into module. Restore the best-metric checkpoint into module.

function HasCheckpoints

bool HasCheckpoints() const

Return:

  • true when at least one checkpoint exists.
  • true when at least one checkpoint exists.

Whether any checkpoint is recorded.

function LatestStep

uint64_t LatestStep() const

Return:

  • Step of the most recent checkpoint, or 0.
  • Latest step.

Step of the most recent checkpoint, throwing when none exist.

function BestStep

uint64_t BestStep() const

Return:

  • Step of the best-metric checkpoint, or 0.
  • Best step.

Step of the best-metric checkpoint, throwing when none is recorded.

function AllSteps

std::vector< uint64_t > AllSteps() const

Return:

  • Steps of all retained checkpoints.
  • Sorted step list.

Steps of all known checkpoints, ascending.

function WaitUntilIdle

void WaitUntilIdle()

Block until all pending asynchronous saves complete.

Block until every in-flight background save completes.

function Options

inline const CheckpointOptions & Options() const

Return: Const reference to the manager configuration.