Asynchronous checkpoint staging
Separate immutable capture from background persistence, and bound source lifetimes, staging memory, and outstanding work.
On this page
The question for today
What you’ll understand
- Distinguish staging completion from save completion.
- Identify the next mutation that an asynchronous copy must precede.
- Budget multiple staged snapshots and diagnose an overloaded persistence path.
Asynchronous checkpointing removes some storage work from the training critical path, but it does not remove the need to capture one stable version. A background task that reads live tensors during the next optimizer mutation can save a mixture. The central design is a pair of lifetime contracts: source state stays unchanged until capture is complete, and captured storage stays unchanged until the writer no longer needs it.
Staging and persistence have different completion points
Staging creates an independent representation that the storage writer can read while training continues. It may copy device tensors into host memory, clone CPU objects, or use another explicitly supported mechanism. A state dictionary can contain references to live tensor storage rather than frozen values, so merely building the dictionary is not necessarily staging. Mutating a nested Python object can also race serialization. Determine which parts are copied synchronously, which are asynchronous, and which still alias application-owned memory under the selected implementation.
PyTorch 2.14 documents separate staging and upload completion futures in its asynchronous checkpoint interface. The staging completion protects the next mutation of source state; upload completion indicates the checkpoint save has finished under that writer’s contract. Neither a host enqueue return nor local staging alone establishes a recoverable stored generation. Older interfaces and different stagers can expose different future behavior, so code against the deployed version. Propagate asynchronous exceptions and drain outstanding work before orderly shutdown rather than allowing the process to exit with a merely scheduled checkpoint.
Overlap only the work whose dependencies permit it
A lazy capture can overlap with a forward or backward pass if the copied state remains immutable throughout that window. DataStates-LLM studies this opportunity for its training design. Do not generalize the condition to every framework buffer or optimizer: running statistics, counters, custom hooks, or offloaded states may mutate earlier. A defensible schedule places the wait immediately before the first relevant mutation while preserving all other categories at the same cut. Delaying a wait is an optimization only after those dependencies are proven.
Pinned staging memory can enable efficient transfers but consumes a limited host resource and can stay allocated between checkpoints. Include co-resident input prefetch, optimizer offload, temporary serialization, and other processes in the memory budget. Concurrent snapshots multiply retained state unless the implementation safely reuses or deduplicates it. A common simple policy allows one outstanding save, waits for its completion before another staging request, and records the resulting delay. More concurrency is useful only if measured throughput improves without violating memory or recovery requirements.
Bound the backlog instead of hiding it behind futures
If new checkpoint bytes arrive faster than the persistence path can drain them, asynchronous work accumulates; it has not become free. Choose an explicit admission rule: wait, coalesce a request, skip a scheduled snapshot while retaining the last committed one, or abort under the recovery policy. Log both the requested cut and the eventual committed cut so a fast training loop cannot overstate its recoverable progress. Measure staging delay, save completion, bytes, peak retained memory, and interference with training separately.
The fluid queue instrument gives a controlled backlog analogy. Reset, set both λ=2 and μ=3, predict its initial four units drain at t=4, then Play or Step. Separately Reset, set both λ=4 and μ=3, predict growth at one unit per second from four, then Play or Step. Parameter edits retain time, which is why each comparison starts afresh. This model has no tensor copies, byte sizes, storage failures, or staging futures. It illustrates rate imbalance only and cannot certify a checkpoint schedule or memory budget.
Work it through
Account for retained snapshots and write pressure
Each staged snapshot retains 12 GiB. The writer takes thirty seconds to persist one snapshot, while training requests a snapshot every twenty seconds. Assume a single fixed-rate writer and no compression or overlap between its requests.
One snapshot occupies 12 GiB of staging payload. Retaining two independent in-flight snapshots requires at least 24 GiB, before metadata, temporary copies, pinned allocator overhead, or the rest of the application.
The offered persistence rate is 12/20=0.6 GiB/s, but writer capacity is 12/30=0.4 GiB/s. Requests arrive faster than this stipulated writer can finish them.
An unlimited queue would grow by an average 0.2 GiB/s while those rates persist. A bounded policy must reduce admission or wait; adding staging slots changes temporary tolerance, not the fixed writer’s sustained capacity.
Asynchrony can reduce exposed delay only within valid lifetimes and resource budgets. It does not repair a persistent service-rate deficit.
The living notebook
Explore the model
Interactive lab · queue
Background work still needs a stable service rate
Reset, set both λ=2 and μ=3, predict drainage of the initial four units at t=4, then Play or Step. Separately Reset, set both λ=4 and μ=3, predict growth at one unit/s from four, then Play or Step. This fluid model illustrates rate imbalance, not checkpoint bytes, staging lifetimes, or real storage performance.
- Fluid backlog
- 4
- Net rate · λ − μ
- −1 /s
- M/M/1 mean residence
- 1 s
Fluid backlog starts at 4 and follows max(0, 4 + (λ − μ)t). The separate M/M/1 residence-time formula assumes Poisson arrivals, exponential service and λ < μ. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.
Look forBound outstanding work and distinguish capture completion from durable save completion.
Pause & reason
Check your understanding
Your turn
Try it yourself
A 6 GiB snapshot has been copied into a reusable host buffer. The next checkpoint overwrites that buffer while the first writer is halfway through reading it. Does the first snapshot remain safe because its device-to-host copy finished?
Take a moment to make a prediction or work it out on paper. Open a hint when you need one.
Give me a hint
Follow the writer’s retained reference to host storage.
Compare with the solution
No. Capture completion released the original device source, but the host buffer remains an input to the first writer. Reuse must wait for that read lifetime to end, or a distinct immutable buffer must be used. Otherwise one stored checkpoint can contain pieces of two generations despite both device copies individually completing.
Keep the idea
Take it with you
- Separate source capture, background writing, and complete-generation publication.
- Wait before the first mutation of any still-referenced source or staged buffer.
- Bound retained memory and checkpoint admission when storage falls behind.
Read further
Original sources and deeper explanations to follow at your own pace.
Optional progress, saved in this browser when available. Revisit any lesson at any time.
Lesson not marked complete.