Skip to content

Conversation

@CodeVishal-17
Copy link

@CodeVishal-17 CodeVishal-17 commented Jan 5, 2026

What does this PR do?

Exposes the weights_only argument in Fabric.load() and forwards it to the underlying strategy checkpoint loading call.

This restores compatibility with mixed-object checkpoints after the PyTorch 2.6 change where torch.load defaults to weights_only=True.

Motivation and context

With PyTorch 2.6, torch.load defaults to weights_only=True, which prevents loading checkpoints that contain non-tensor objects (such as optimizers, schedulers, or metadata).

While strategy.load_checkpoint(..., weights_only=False) already supports this use case, Fabric.load() did not expose the argument, making it impossible for users to opt out of the new default behavior when using Fabric.

This PR adds a keyword-only weights_only argument to Fabric.load() without changing the existing default behavior.

Fixes #21459

Before submitting
  • Was this discussed/agreed via a GitHub issue? ✔️ (see Fabric.load is missing the weights_only argument #21459)
  • Did you read the contributor guideline, Pull Request section?
  • Did you make sure your PR does only one thing, instead of bundling different changes together?
  • Did you make sure to update the documentation with your changes? (if necessary)
  • Did you write any new necessary tests? (not for typos and docs)
  • Did you verify new and existing tests pass locally with your changes?
  • Did you list all the breaking changes introduced by this pull request?
  • Did you update the CHANGELOG? (not for typos, docs, test updates, or minor internal changes/refactors)

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

📚 Documentation preview 📚: https://pytorch-lightning--21470.org.readthedocs.build/en/21470/

@github-actions github-actions bot added the fabric lightning.fabric.Fabric label Jan 5, 2026
Comment on lines 877 to 882
"""Load a checkpoint from a file and restore the state of objects (modules, optimizers, etc.) How and which
processes load gets determined by the `strategy`.
How and which processes load gets determined by the `strategy`.
This method must be called on all processes!
Args:
path: A path to where the file is located.
state: A dictionary of objects whose state will be restored in-place from the checkpoint path.
If no state is given, then the checkpoint will be returned in full.
strict: Whether to enforce that the keys in `state` match the keys in the checkpoint.
Returns:
The remaining items that were not restored into the given state dictionary. If no state dictionary is
given, the full checkpoint will be returned.
Example::
# Load full checkpoint
checkpoint = fabric.load("checkpoint.pth")
# Load into existing objects
state = {"model": model, "optimizer": optimizer}
remainder = fabric.load("checkpoint.pth", state)
epoch = remainder.get("epoch", 0)
"""
Copy link
Contributor

Choose a reason for hiding this comment

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

The original docstring should be extended with the additional kwarg weight_only instead of removed.

Copy link
Author

Choose a reason for hiding this comment

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

I’ve updated the docstring to preserve the original content and extended it with the weights_only argument, including fixing the example formatting. Thanks for the review!

Copy link
Contributor

Choose a reason for hiding this comment

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

I think there was something wrong with the commits? I could see you reverse back the docstring in debde18, but then immediately revert the reverse commit in 6143e65, causing the resulting docstring still missing.

Comment on lines 905 to 906
# We need to unwrap objects (see above) but this creates a new dictionary. In-place updates
# (for user metadata) wouldn't show up in the original dict, so we need to copy the data back.
Copy link
Contributor

Choose a reason for hiding this comment

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

The comments here should still be preserved.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for the review 👍
I’ve resolved the merge conflict in Fabric.load, preserved all existing comments and examples, and kept the
weights_only change purely additive. Please let me know if everything looks good now.

@codecov
Copy link

codecov bot commented Jan 8, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87%. Comparing base (027455b) to head (fad0964).
⚠️ Report is 10 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #21470   +/-   ##
=======================================
- Coverage      87%      87%   -0%     
=======================================
  Files         270      270           
  Lines       24059    24059           
=======================================
- Hits        20862    20859    -3     
- Misses       3197     3200    +3     

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

Labels

fabric lightning.fabric.Fabric

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fabric.load is missing the weights_only argument

3 participants