Skip to content

[Checkpoint] clarify initial load and resume behavior - #3732

Merged
tianyu-l merged 3 commits into
pytorch:mainfrom
hit-wdy:checkpoint-explicit-resume
Jul 21, 2026
Merged

tianyu-l merged 3 commits into
pytorch:mainfrom
hit-wdy:checkpoint-explicit-resume

Conversation

@hit-wdy

@hit-wdy hit-wdy commented Jun 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Take the initial-load branch when checkpoint.folder has no valid
    checkpoint (load_step == -1), not only when the folder is missing.
  • Raise FileNotFoundError for an explicit --checkpoint.load_step when
    the folder does not exist.
  • Log an info message on fresh start instead of returning silently.
  • Resume behavior is unchanged: initial_* options are ignored by design
    for fault tolerance. Per review, the warnings there were removed and
    replaced with a comment.

Motivation

load() chose between initial load and resume solely by whether
checkpoint.folder exists, causing two silent failures:

  1. Folder exists but has no valid checkpoint (e.g. crash before the first
    save): initial_load_path / HF initial load was silently skipped and
    training started from scratch.
  2. An explicit --checkpoint.load_step=N with a missing folder was
    silently ignored.

@meta-cla

meta-cla Bot commented Jun 22, 2026

Copy link
Copy Markdown

Hi @hit-wdy!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

@pytorch-bot

pytorch-bot Bot commented Jun 22, 2026 •

Copy link
Copy Markdown

Workflows were awaiting approval. CI has now been triggered for the ciflow labels on this PR.

@hit-wdy hit-wdy changed the title Checkpoint explicit resume [Checkpoint] Make training resume explicit via checkpoint.resume instead of auto-resuming when the folder exists Jun 22, 2026
@hit-wdy hit-wdy changed the title [Checkpoint] Make training resume explicit via checkpoint.resume instead of auto-resuming when the folder exists [WIP][Checkpoint] Make training resume explicit via checkpoint.resume instead of auto-resuming when the folder exists Jun 22, 2026
@hit-wdy hit-wdy changed the title [WIP][Checkpoint] Make training resume explicit via checkpoint.resume instead of auto-resuming when the folder exists [WIP][Checkpoint] Drive checkpoint loading from initial_load_path; make folder save-only (drop implicit auto-resume) Jun 22, 2026
@fegin

fegin commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

I haven't look into the code yet but just read the proposal. TorchTitan checkpointer was developed to be used in the scenario first and later being evolved to support more options.

  1. The intermedia checkpoints are served as the fault-tolerance purpose.
  2. Only the last step checkpoint is served as publishing purpose.

Because of 1, you will mostly have to make the saving and loading path to share the same parent folder (without step suffix), defeating the purpose of this design, repurpose the initial_load_path for loading.

initial_load_path was designed to make the load explicit. It explicitly gives the TorchTitan's checkpointer the message that "reading the model checkopint from this path, not from the default folder". The implicit load you refer to is the fault-tolerance load and it is the default.

I agree the design may sound confusing, which we can discuss how to improve it. However, this design doesn't seem to consider the goal 1 (fault-tolerance checkpoints) as the native feature, but an opt-in feature.

@hit-wdy

hit-wdy commented Jun 23, 2026

Copy link
Copy Markdown
Contributor Author

I haven't look into the code yet but just read the proposal. TorchTitan checkpointer was developed to be used in the scenario first and later being evolved to support more options.

  1. The intermedia checkpoints are served as the fault-tolerance purpose.
  2. Only the last step checkpoint is served as publishing purpose.

Because of 1, you will mostly have to make the saving and loading path to share the same parent folder (without step suffix), defeating the purpose of this design, repurpose the initial_load_path for loading.

initial_load_path was designed to make the load explicit. It explicitly gives the TorchTitan's checkpointer the message that "reading the model checkopint from this path, not from the default folder". The implicit load you refer to is the fault-tolerance load and it is the default.

I agree the design may sound confusing, which we can discuss how to improve it. However, this design doesn't seem to consider the goal 1 (fault-tolerance checkpoints) as the native feature, but an opt-in feature.

Two questions before I rework the PR:

  1. HF/model-only saves in the resume folder.
    If a run saves an HF / model-only checkpoint to folder/step-N, the next auto-resume picks it and a full-state resume fails — despite _save_last_step claiming model-only end-saves "won't affect resume." Should resume guard against this (resume only from DCP full-state, skip HF/model-only)? Or do you assume users keep HF saves out of the resume folder so this never happens?
  2. An auto_resume: bool = True knob. Would you accept naming the implicit resume and making it disable-able, default on — keeping fault-tolerance zero-config while giving an explicit off-switch?

For reference, I've summarized the current checkpoint loading flow.

load(step=-1):
  if not self.enable: return False

  ── if NOT os.path.exists(self.folder):   # "initial load" (fresh start)
  │     model_only      = self.initial_load_model_only
  │     from_hf         = self.initial_load_in_hf
  │     from_quantized  = self.initial_load_in_hf_quantized
  │     (assert: from_hf ⇒ model_only;  from_quantized ⇒ from_hf)
  │
  │     if self.initial_load_path:     checkpoint_id = initial_load_path
  │     elif from_hf:                  checkpoint_id = sd_adapter.hf_assets_path
  │     else:                          return False          # nothing to load → random init
  │
  └─ else:                                 # folder EXISTS → "resume" (fault-tolerance)
        if self.initial_load_path:   warn "folder exists, will use folder"   # explicit path ignored
        if self.initial_load_in_hf:  warn "folder exists, won't load HF"
        step = self._find_load_step() if step == -1 else step   # latest step in folder
        if step == -1: return False                              # folder exists but empty
        model_only = (step == 0)                                 # seed-checkpoint convention
        checkpoint_id = self._create_checkpoint_id(step)         # {folder}/step-N, DCP (from_hf=False)

@hit-wdy
hit-wdy force-pushed the checkpoint-explicit-resume branch from 9a41403 to 0592bcc Compare June 23, 2026 13:21
@fegin

fegin commented Jun 24, 2026 •

Copy link
Copy Markdown
Contributor

HF/model-only saves in the resume folder.
If a run saves an HF / model-only checkpoint to folder/step-N, the next auto-resume picks it and a full-state resume fails — despite _save_last_step claiming model-only end-saves "won't affect resume." Should resume guard against this (resume only from DCP full-state, skip HF/model-only)? Or do you assume users keep HF saves out of the resume folder so this never happens?

model-only save is only enabled for the last step. The reason be what I mentioned, the checkpoint serves two purposes, fault-tolerance and model publishing. The current design the intermediate-steps checkpoints are always full because they are used for fault-tolerance purpose, only the last step do we consider model-only save. It's nothing to do with HF or not. HF format is only used when we load in the first step, after that we will always load/recover from the intermediate-steps checkpoints, which are NOT HF format.

An auto_resume: bool = True knob. Would you accept naming the implicit resume and making it disable-able, default on — keeping fault-tolerance zero-config while giving an explicit off-switch?

So, for checkpointing, the original design is to have two simple cases, on and off. For a real production run, it doesn't make sense to not have fault-tolerance or model publishing, so checkpointing is on and it serves for both purposes. For an experimental run, neither are required, so checkpointing is off.

What's the use case of the third one, which we save the model but drop the fault-tolerance purpose?

I think we should focus optimizing the first-step load configurations and flows. That loading is the model loading in your case. And all the intermediate loads, step > 1, should be treated as fault-tolerance loading. Let me know if this makes sense to you.

@hit-wdy

hit-wdy commented Jun 25, 2026

Copy link
Copy Markdown
Contributor Author

model-only save is only enabled for the last step. The reason be what I mentioned, the checkpoint serves two purposes, fault-tolerance and model publishing. The current design the intermediate-steps checkpoints are always full because they are used for fault-tolerance purpose, only the last step do we consider model-only save. It's nothing to do with HF or not. HF format is only used when we load in the first step, after that we will always load/recover from the intermediate-steps checkpoints, which are NOT HF format.
So, for checkpointing, the original design is to have two simple cases, on and off. For a real production run, it doesn't make sense to not have fault-tolerance or model publishing, so checkpointing is on and it serves for both purposes. For an experimental run, neither are required, so checkpointing is off.

What's the use case of the third one, which we save the model but drop the fault-tolerance purpose?

I think we should focus optimizing the first-step load configurations and flows. That loading is the model loading in your case. And all the intermediate loads, step > 1, should be treated as fault-tolerance loading. Let me know if this makes sense to you.

I fully understand your point. Here's how I read the current load() flow, split by the two cases the os.path.exists(folder) gate creates:
Case 1 — folder does not exist (treated as a fresh start / first-step model load):
(a) initial_load_path unset → random init.
(b) initial_load_path set, HF checkpoint → training starts from step 0.
(c1) initial_load_path set, DCP model-only → training starts from step 0.
(c2) initial_load_path set, DCP full-state → such a checkpoint belongs in folder and should go through the resume path.
Case 2 — folder exists (treated as fault-tolerance):
(a) initial_load_path unset, DCP checkpoint → full-state resume. OK.
(b) initial_load_path unset, HF checkpoint → would break . In practice this shouldn't happens.
(c) initial_load_path set → silently ignored (warning only).

My confusion is mainly around case (2c). If I want to start training from the first step and set initial_load_path, but folder happens to exist, how should that be handled? Shouldn't we go through initial_load_path init when the user has explicitly set it, even if folder exists?

@fegin

fegin commented Jun 29, 2026 •

Copy link
Copy Markdown
Contributor

@hit-wdy

That's a good catch. For 2(c), the correct way should be 1) if the step is 1 then error outs, this is an ambiguous case, 2) if the step is > 2, this is correct, the existing folder is used for the fault tolerance purpose, we already load from the initial_load_path, so no hard errors nor warnings should happen.

Would this resolve your concern?

@hit-wdy

hit-wdy commented Jul 2, 2026

Copy link
Copy Markdown
Contributor Author

@hit-wdy

That's a good catch. For 2(c), the correct way should be 1) if the step is 1 then error outs, this is an ambiguous case, 2) if the step is > 2, this is correct, the existing folder is used for the fault tolerance purpose, we already load from the initial_load_path, so no hard errors nor warnings should happen.

Would this resolve your concern?

Thanks for the clarification.

My understanding is slightly different here: when I explicitly set initial_load_path, I would naturally expect the run to initialize from that path and start training from step 1. In this case, I would not set load_step manually.

So I am not sure whether we need to add the extra check based on whether the step is 1 or >2. From the user's perspective, initial_load_path is an explicit signal that this should be treated as an initialization path, not a fault-tolerance resume path. Therefore, even if folder already exists, I think we should still initialize from initial_load_path when it is explicitly provided.

I believe this does not break the original design where folder is used for fault tolerance. Intermediate checkpoints in folder can still serve the resume/fault-tolerance purpose, but initial_load_path should take precedence when the user explicitly wants to start a new run from a given model checkpoint.

Does this interpretation make sense?

@fegin

fegin commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

My understanding is slightly different here: when I explicitly set initial_load_path, I would naturally expect the run to initialize from that path and start training from step 1. In this case, I would not set load_step manually.

load_step is not set by users it is read from the trainer state. If you set initial_load_path and train 5 steps, then the cluster crashes, you will still need to load the trainer step as 5 and continue the training otherwise you lose the 5 steps GPUs resource. This is the case where load_step is not 1 and we should ignore initial_load_path completely.

Why do we design like this? It is not efficient that a user needs to change the command line arguments every time a trainer crashes. So in such a case, it is common that a resume-from-fault run and a fresh run share the same arguments. The way to distinguish the resume-from-fault run and a fresh run is through the training state. So in the 5-step fails case, the trainer should ignore initial_load_path since this is NOT a fresh run anymore and should load from the intermediate checkpoint even if initial_load_path

So for your 2.c case, initial_load_path is set and intermedia checkpoint exist, the the load step must be > 1. This is by design, no ambiguity. So we should error out (my previous comment).

@hit-wdy

hit-wdy commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

My understanding is slightly different here: when I explicitly set initial_load_path, I would naturally expect the run to initialize from that path and start training from step 1. In this case, I would not set load_step manually.

load_step is not set by users it is read from the trainer state. If you set initial_load_path and train 5 steps, then the cluster crashes, you will still need to load the trainer step as 5 and continue the training otherwise you lose the 5 steps GPUs resource. This is the case where load_step is not 1 and we should ignore initial_load_path completely.

Why do we design like this? It is not efficient that a user needs to change the command line arguments every time a trainer crashes. So in such a case, it is common that a resume-from-fault run and a fresh run share the same arguments. The way to distinguish the resume-from-fault run and a fresh run is through the training state. So in the 5-step fails case, the trainer should ignore initial_load_path since this is NOT a fresh run anymore and should load from the intermediate checkpoint even if initial_load_path

So for your 2.c case, initial_load_path is set and intermedia checkpoint exist, the the load step must be > 1. This is by design, no ambiguity. So we should error out (my previous comment).

Got it. Thank you for the patient explanation!

I understand the intended design now. I will update this PR.

@hit-wdy hit-wdy changed the title [WIP][Checkpoint] Drive checkpoint loading from initial_load_path; make folder save-only (drop implicit auto-resume) [Checkpoint] Drive checkpoint loading from initial_load_path; make folder save-only (drop implicit auto-resume) Jul 8, 2026
@hit-wdy
hit-wdy force-pushed the checkpoint-explicit-resume branch from 0592bcc to 6f1e846 Compare July 8, 2026 07:28
@hit-wdy hit-wdy changed the title [Checkpoint] Drive checkpoint loading from initial_load_path; make folder save-only (drop implicit auto-resume) [Checkpoint] clarify initial load and resume behavior Jul 8, 2026
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jul 8, 2026
@meta-cla

meta-cla Bot commented Jul 8, 2026

Copy link
Copy Markdown

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

Comment thread torchtitan/components/checkpoint.py Resolved
Comment thread torchtitan/components/checkpoint.py Resolved
Comment thread torchtitan/components/checkpoint.py Resolved
Comment thread torchtitan/components/checkpoint.py Resolved
1Fire4 added 3 commits July 21, 2026 22:28
- Revert initial_load_path config docstring to original wording
- Simplify load branch condition to load_step == -1, which subsumes
  the missing-folder case since load_step stays -1 when the folder
  does not exist
- Remove the ValueError/warnings when initial_* options are set while
  checkpoint.folder has valid checkpoints; this resume path is the
  fault-tolerance branch and must silently ignore initial_* options so
  a job can keep the same arguments across automatic restarts. Document
  this design with a comment instead.
@hit-wdy
hit-wdy force-pushed the checkpoint-explicit-resume branch from 61a6d91 to f19a781 Compare July 21, 2026 13:32
@tianyu-l
tianyu-l merged commit 7463c16 into pytorch:main Jul 21, 2026
17 of 21 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in TorchTitan Development Jul 21, 2026
mreso added a commit to mreso/torchtitan that referenced this pull request Jul 21, 2026
Absorbs 4 upstream commits (checkpoint load/resume clarify pytorch#3732, override kwargs
from CLI+config pytorch#3894, [spmd_types] VarlenAttention un-hardcode pytorch#3937, VLLMGenerator
readline hang patch pytorch#3950). No conflicts; spmd_types regression verified -- GQA MoE
TP+EP+typecheck (12.48->6.82) and DSA GLM-5 TP=2 (12.53->6.82) both clean.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/8gpu CLA Signed This label is managed by the Meta Open Source bot. module: checkpoint

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants