Skip to content

Honor strict=False when loading sharded (distributed) checkpoints - #22028

Open
deep1blue wants to merge 1 commit into
Lightning-AI:masterfrom
deep1blue:fix-20274-fsdp-distributed-load-strict
Open

deep1blue wants to merge 1 commit into
Lightning-AI:masterfrom
deep1blue:fix-20274-fsdp-distributed-load-strict

Conversation

@deep1blue

@deep1blue deep1blue commented Oct 19, 2026 •

Copy link
Copy Markdown

What does this PR do?

Fixes #20274

FSDPStrategy.load_checkpoint(..., strict=False) (in both Fabric and Trainer) and Fabric's ModelParallelStrategy.load_checkpoint(..., strict=False) previously only forwarded strict to module.load_state_dict. However, for sharded (distributed) checkpoints, _distributed_checkpoint_load invoked torch.distributed.checkpoint.load(module_state, checkpoint_id=path) with the default DefaultLoadPlanner(allow_partial_load=False), which raised CheckpointException (RuntimeError: Missing key in checkpoint state_dict) before module.load_state_dict(..., strict=False) was ever reached.

Changes

  • Add strict: bool = True to _distributed_checkpoint_load and pass planner=DefaultLoadPlanner(allow_partial_load=not strict) to torch.distributed.checkpoint.load.
  • Forward strict=strict from Fabric FSDPStrategy.load_checkpoint and ModelParallelStrategy.load_checkpoint, and strict=self.lightning_module.strict_loading from Trainer FSDPStrategy.load_checkpoint when loading module state.
  • Add test_distributed_checkpoint_load_strict in tests/tests_fabric/strategies/test_fsdp.py and update existing _distributed_checkpoint_load mocks in tests/tests_fabric/strategies/test_model_parallel.py.

PR review

Anyone in the community is welcome to review the PR.
Before you start reviewing, make sure you have read the review guidelines. In short, see the following bullet-list:

Reviewer checklist
  • Is this pull request ready for review? (if not, please submit in draft mode)
  • Check that all items from Before submitting are resolved
  • Make sure the title is self-explanatory and the description concisely explains the PR
  • Add labels and milestones (and optionally projects) to the PR so it can be classified

Credits & Acknowledgments

`FSDPStrategy.load_checkpoint(..., strict=False)` (Fabric and Trainer) and the Fabric ModelParallel strategy only forwarded `strict` to `module.load_state_dict`, after `torch.distributed.checkpoint.load` had already raised `Missing key in checkpoint state_dict` for any model key absent from the sharded checkpoint.

Pass a `DefaultLoadPlanner(allow_partial_load=not strict)` to the distributed checkpoint load so that missing keys are tolerated when `strict=False`, while `strict=True` keeps raising. Optimizer state loading is unchanged.

Fixes Lightning-AI#20274

Signed-off-by: Parth Vadera <parthvadera@gmail.com>

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

strict = False does not work when the checkpoint is distributed

1 participant