kempnerforge.checkpoint.async_save¶
Async checkpointing for non-blocking saves.
Uses dcp.async_save() to snapshot state to CPU and write to disk
in the background, returning control to the training loop once the snapshot is taken.
- Modes:
disabled: Synchronous save (the default; simple, for debugging).
async: Standard async via dcp.async_save(); the snapshot goes to pageable CPU memory.
async_with_pinned_mem: async, with the snapshot copied into pinned CPU memory by a
DefaultStagerthat serves every save on torch 2.13 and later (torch 2.12 gets a new one per save). The first save pins a copy of the rank’s state; later saves refill the copy of every tensor whose storage is unchanged (parameters and optimizer state updated in place), so they stall less. The stager keeps a copy while its source storage lives, untilclose()or until the checkpointer is collected; a save still being written keeps its snapshot until the write ends. Without a CUDA device the mode saves as async.
Classes
Non-blocking checkpoint saver. |
- class kempnerforge.checkpoint.async_save.AsyncCheckpointer[source]¶
Bases:
objectNon-blocking checkpoint saver.
Wraps
dcp.async_save()and manages the background save future. Each new save waits for the previous async save to complete first. Not thread-safe: call it from one thread, as the training loop does.- Parameters:
mode – Checkpoint mode (disabled/async/async_with_pinned_mem). The pinned mode stages through pinned memory only where a CUDA device is available, and saves as async elsewhere, with one warning.
- __init__(mode=AsyncCheckpointMode.disabled)[source]¶
- Parameters:
mode (AsyncCheckpointMode)
- Return type:
None
- save(state_dict, checkpoint_id, process_group=None, planner=None)[source]¶
Save distributed state, potentially asynchronously.
- Parameters:
state_dict (dict) – DCP-compatible state dict (model + optimizer).
checkpoint_id (str) – Checkpoint directory path.
process_group – Process group for DCP. Required for PP where each stage has a different state dict — pass a group scoped to ranks within the same PP stage. None uses the default global group.
planner (SavePlanner | None) – DCP save planner. None calls DCP as before, with its default planner.
- Return type:
None