Skip to content

[checkpoint] Wait for async saves during close - #4270

Merged
tianyu-l merged 1 commit into
pytorch:mainfrom
taking-lying-flat:fix/checkpointer-close-await-save
Sep 1, 2026
Merged

tianyu-l merged 1 commit into
pytorch:mainfrom
taking-lying-flat:fix/checkpointer-close-await-save

Conversation

@taking-lying-flat

@taking-lying-flat taking-lying-flat commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Wait for in-flight asynchronous checkpoint staging and saving before CheckpointManager releases its background resources.

Root cause

CheckpointManager tracks asynchronous work in staging_future and save_future. Normal checkpoint cycles wait for the previous save before starting the next one, but _close() only stopped the purge thread and closed the stager.

Shutdown paths do not necessarily start another save. In particular, dataloader exhaustion breaks out of training before the final-step save, while exceptions and explicit close calls also proceed directly to teardown. The last asynchronous upload could therefore still be running when close returned and the process group or process was torn down.

DefaultStager.close() drains its staging executor, but it does not await the checkpoint upload future or explicitly surface completion through the tracked futures. The close path now drains staging_future and save_future before releasing the purge and staging resources.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Aug 21, 2026
@taking-lying-flat
taking-lying-flat marked this pull request as ready for review August 21, 2026 19:18
@tianyu-l
tianyu-l requested a review from ivy-zhou August 21, 2026 19:36
self.close()

def _close(self):
self.maybe_wait_for_staging()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to but would you mind moving this into the base class in base.py instead? This looks like common functionality. Thank you!

@tianyu-l

tianyu-l commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

may need to rebase

@taking-lying-flat
taking-lying-flat force-pushed the fix/checkpointer-close-await-save branch from 6c90147 to 4a4a97c Compare August 31, 2026 23:14
@tianyu-l
tianyu-l merged commit 80b1e66 into pytorch:main Sep 1, 2026
17 checks passed
saforem2 added a commit to saforem2/torchtitan that referenced this pull request Sep 6, 2026
Surveyed, not merged -- two 80B captures are mid-flight and folding in 64
commits would make any new failure ambiguous. This records the analysis so the
merge is cheap later.

Diverged at 6ee6d5d (2026-08-30), upstream tip 966befc.

ZERO upstream commits touch experiments/ezpz, so there are no conflicts in our
own code. The risk is entirely in core files we import from. Of those,
components/loss.py matters most: we import BaseLoss, CrossEntropyLoss,
ChunkedLossWrapper and IGNORE_INDEX, all four still present, with one method
renamed (typecheck_forward -> spmd_typecheck). zloss.py overrides only
__init__ and __call__, so it does not inherit that rename -- checked rather
than assumed, since a preserved name with a changed contract is the dangerous
case, not a deleted one.

Corrects my earlier risk ranking. I called pytorch#4328 (refactor max_context_length)
the highest risk; that was wrong. max_context_length is UNCHANGED upstream --
same field, same default, plus a validation guard. The PR changes seq_len in
model specs and registries, not the --training.max-context-length flag we
pass. The single seam is agpt/config_registry.py:291, where our own
agpt(seq_len=...) assigns cfg.training.max_context_length.

The real risks, ordered: pytorch#4398 (valid-token counts move into collation --
that is the gradient-accumulation path), then the checkpoint cluster
(pytorch#4187/pytorch#4188/pytorch#4197/pytorch#4270/pytorch#4474, which we subclass and where pinned clones have
already broken on optim-statedict changes), then pytorch#4382 (Adam first-step state).

Includes a merge order: smoke at 2N, then a resume from a real checkpoint, a
seeded loss/grad_norm comparison, and config_registry.py:291 by inspection.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants