Skip to content

Fix from_pretrained on torch 2.7: require torch>=2.8 for distributed checkpointing - #49652

Merged
vasqu merged 6 commits into
huggingface:mainfrom
naveecode:fix/49651-dcp-torch-2.8-guard
Oct 16, 2026
Merged

vasqu merged 6 commits into
huggingface:mainfrom
naveecode:fix/49651-dcp-torch-2.8-guard

Conversation

@naveecode

@naveecode naveecode commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

🤗 Transformers CI

What does this PR do?

Fixes #49651

_check_distributed_checkpointing_available() returned True on torch>=2.7, but torch.distributed.checkpoint.hf_storage (which transformers/distributed/checkpoint.py imports at module level under that guard) only ships from torch 2.8. Because modeling_utils imports distributed.checkpoint unconditionally, every from_pretrained failed on torch 2.7.x with ModuleNotFoundError: No module named 'torch.distributed.checkpoint.hf_storage'.

Changes:

  • Raise the guard to is_torch_greater_or_equal("2.8").
  • Update the matching torch>=2.7 error messages and the FSDP2 checks (whose comment says they depend on DCP + HuggingFaceStorageWriter) to 2.8, so the stated requirement matches the real one.
  • Add tests/utils/test_distributed_checkpoint_guard.py: asserts that whenever the guard is True, hf_storage is importable; that the guard is False for a simulated torch 2.7; and that transformers.modeling_utils imports cleanly.

Not touched: the setup.py floor (torch>=2.6) and the Shard._local_shard_size_and_offset (2.8+) usage in sharding_utils.py the issue also mentions. Happy to follow up on either if you'd rather bump the minimum torch version instead.

Before submitting

Who can review?

@michaelbenayoun @ArthurZucker (tagged in the issue)

@github-actions

Copy link
Copy Markdown
Contributor

Thank you for your contribution 🤗!

CI Security Gate — waiting for maintainer approval

CI is approved automatically only for authors who already have a contribution merged in this repository. A maintainer will review this PR and approve CI to run on it.

@ArthurZucker ArthurZucker left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Ty, needs patching

@ArthurZucker ArthurZucker added the for patch Tag issues / labels that should be included in the next patch label Oct 16, 2026
@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@naveecode

Copy link
Copy Markdown
Contributor Author

Thanks for the review! For context on the red CI: the two failing shards look unrelated to this change. tests_tokenization [shard 4/8] was killed by the runner (exit code 137), and tests_processors [shard 4/8] failed in tests/models/muse_spark/test_processing_muse_spark.py (audio chat-template tests). This PR only touches the distributed-checkpointing torch version guard and its new test. Happy to rebase or adjust anything for the patch release.

@ducanhnguyen223 ducanhnguyen223 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

On head 8e76de6, I cannot find the regression test described in the PR body. GitHub lists only the three production files (checkpoint.py, mixin.py, and utils.py) in the diff, and tests/utils/test_distributed_checkpoint_guard.py is absent from both the base and head. Could you add the guard/import regression or update the PR description if it was dropped? This torch-version boundary caused a broad import regression, so a committed test would help prevent it recurring.

@vasqu
vasqu disabled auto-merge October 16, 2026 11:27
@vasqu
vasqu merged commit f74cb53 into huggingface:main Oct 16, 2026
114 of 116 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

CI recap

Dashboard: View test results in Grafana
Latest run: 38892318718:2
Result: failure | Jobs: 15 | Tests: 202,218 | Failures: 0 | Duration: 13h 51m

vasqu added a commit that referenced this pull request Oct 16, 2026
…checkpointing (#49652)

* Require torch>=2.8 for distributed checkpointing (hf_storage)

* Update distributed checkpoint error messages to torch>=2.8

* Update FSDP2/DCP torch floor in mixin to 2.8

* Add regression test for #49651

* Delete tests/utils/test_distributed_checkpoint_guard.py

Overkill!

---------

Co-authored-by: Arthur <[email protected]>
Co-authored-by: Anton Vlasjuk <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

for patch Tag issues / labels that should be included in the next patch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

torch 2.7: every from_pretrained fails in 5.20.0 (hf_storage import behind a torch>=2.7 guard)

5 participants