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¶
Parameters:
- options Checkpoint directory, retention, and async settings.
Create the checkpoint directory if needed and load metadata for existing checkpoints.
function ~CheckpointManager¶
Wait for any in-flight asynchronous saves before destruction.
function CheckpointManager¶
function operator=¶
function CheckpointManager¶
Parameters:
- other Manager to move from.
Move-construct a manager, leaving other without pending work.
function operator=¶
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¶
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¶
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¶
Return:
- State dict of the most recent checkpoint.
- Named tensors loaded from the checkpoint.
Load the state dictionary of the latest checkpoint.
function 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¶
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¶
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¶
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¶
Return:
- true when at least one checkpoint exists.
- true when at least one checkpoint exists.
Whether any checkpoint is recorded.
function LatestStep¶
Return:
- Step of the most recent checkpoint, or 0.
- Latest step.
Step of the most recent checkpoint, throwing when none exist.
function BestStep¶
Return:
- Step of the best-metric checkpoint, or 0.
- Best step.
Step of the best-metric checkpoint, throwing when none is recorded.
function AllSteps¶
Return:
- Steps of all retained checkpoints.
- Sorted step list.
Steps of all known checkpoints, ascending.
function WaitUntilIdle¶
Block until all pending asynchronous saves complete.
Block until every in-flight background save completes.
function Options¶
Return: Const reference to the manager configuration.