Skip to content

Fix TorchFT checkpoint step alignment - #4686

Merged
tianyu-l merged 3 commits into
pytorch:mainfrom
Serendipity-matong:fix/torchft-checkpoint-step-alignment
Sep 21, 2026
Merged

tianyu-l merged 3 commits into
pytorch:mainfrom
Serendipity-matong:fix/torchft-checkpoint-step-alignment

Conversation

@Serendipity-matong

Copy link
Copy Markdown
Contributor

Summary

Fix TorchFT dataloader checkpoint loading to stay aligned with the selected
main training checkpoint.

Root Cause

TorchFTCheckpointManager.load() independently selected the latest checkpoint
from the per-replica dataloader checkpoint directory before the base checkpoint
manager resolved the main checkpoint step.

For example, if the main checkpoint directory contained step-500 while the
TorchFT dataloader directory already contained step-501, recovery loaded
model state from step-500 but dataloader state from step-501. This could skip
data and break exact recovery.

Changes

  • Expose the base checkpoint manager's resolved training step for subclasses.
  • Restrict TorchFT dataloader checkpoint discovery to steps no later than the
    selected main checkpoint.
  • Preserve the existing checkpoint loading order: FT dataloader state is loaded
    before the main checkpoint state.
  • Add a regression test covering automatic recovery when a newer FT dataloader
    checkpoint exists than the selected main checkpoint.

Testing

  • python -m pytest torchtitan/experiments/torchft/tests/test_torchft_checkpoint.py -q
    (7 passed)
  • flake8 on changed files
  • pre-commit run ufmt
  • pre-commit run pydoclint
  • pre-commit run codespell
  • python -m compileall ...
  • git diff --check

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Sep 15, 2026
@tianyu-l
tianyu-l requested a review from ivy-zhou September 15, 2026 01:42
)
return True

def _resolve_load_step(self, step: int, has_checkpoint_folder: bool) -> int:

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.

I don't think you need to extract this out, I think you can just call find_load_step directly.

def load(self, step: int = -1) -> bool:
if self.enable and self.enable_ft_dataloader_checkpoints:
self._ft_load()
has_checkpoint_folder = self._storage.isdir(self.folder)

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.

If you run the super().load(step) ahead of trying to load the DL folder and try to look at the checkpoint ID from it, does this code get any cleaner?

@pytorch-bot pytorch-bot Bot added the ciflow/fake-pg Run 1-GPU Fake PG integration tests label Sep 17, 2026
@pytorch-bot

pytorch-bot Bot commented Sep 17, 2026 •

Copy link
Copy Markdown

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

@tianyu-l
tianyu-l requested a review from ivy-zhou September 17, 2026 17:40

@ivy-zhou ivy-zhou left a comment

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.

LGTM!

@tianyu-l
tianyu-l merged commit 0fd69d0 into pytorch:main Sep 21, 2026
18 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/fake-pg Run 1-GPU Fake PG integration tests ciflow/rl 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