Back Home

GitHub Repo

Transformers 5.20.1 Fixes Model Loading Failure on PyTorch 2.7, Adjusts Distributed Checkpoint Version Check

Hugging Face released Transformers 5.20.1 on October 16, fixing a regression in 5.20.0 that affected model loading with PyTorch 2.7. The update raises the version threshold for distributed checkpoint features to PyTorch 2.8, preventing a missing-module error from disrupting ordinary loading workflows.

Andrew Wippler from Lancaster, USA · CC BY 2.0 · Image source
zh-Hant

Hugging Face released Transformers 5.20.1 on October 16, fixing a model-loading issue in older versions of PyTorch. The change deployment teams should note is that the distributed checkpoint dependency check in 5.20.0 could block ordinary model loading. The official release notes confirm the regression and list the corresponding fix. Release notes

A community report provided reproduction steps in a Windows, Python 3.12.2, and PyTorch 2.7.1 CPU environment: calling AutoModelForCausalLM.from_pretrained() to load a tiny GPT-2 test model produced an error saying the model class could not be imported. Importing transformers.modeling_utils directly revealed the root cause: the torch.distributed.checkpoint.hf_storage module was missing. The reporter was not using a distributed configuration, and the same environment worked normally with Transformers 5.19.0. Issue report

The cause was that the feature check treated PyTorch 2.7 as supporting the relevant checkpoint integration, even though the required hf_storage module is only available starting in 2.8. Because the modeling utilities module unconditionally imports the distributed checkpoint module, the error propagated through the import chain. The fix raises the threshold to 2.8 and also updates related error messages and the FSDP2 check; it does not raise the package-wide minimum PyTorch version requirement. Patch

This version boundary is also supported by upstream information: the official PyTorch 2.8 announcement lists DCP support for saving, loading, and resharding SafeTensors as a new feature, noting at the time that the API was not yet stable. For engineering teams, package installability and the availability of a specific integration must be verified separately. PyTorch technical announcement

Teams still pinned to PyTorch 2.7 can first verify the basic loading workflow in 5.20.1, then test the parallelism and checkpoint paths they actually use. The release notes also list tensor sharding fixes for PyTorch 2.6 and 2.7, so successful model loading alone does not establish compatibility across all distributed features. Public information does not yet cover every hardware combination; the dedicated regression test initially proposed for this fix was also removed during review. Release notes, review record

Sources

  1. Transformers v5.20.1 發布說明
  2. Issue #49651:PyTorch 2.7 的 from_pretrained 載入失敗
  3. PR #49652:調整分散式檢查點的 PyTorch 版本檢查
  4. PyTorch 2.8 Release Blog