PyTorch now blocks torch.load with weights_only=True on legacy pre-1.6 checkpoints (#204437)
Old non-zipfile checkpoints now raise pickle.UnpicklingError under the default safe mode. Trusted files must be loaded once with weights_only=False and re-saved.
What happened
PyTorch is a popular toolkit for building AI models. It can save a trained model to a file called a checkpoint. A change merged into its main branch now refuses to open very old checkpoint files in the safe loading mode.
Why it matters to you
Anyone who keeps old model files may see an error when loading them. The change closes a gap that gave a false sense of safety when opening files from unknown sources.
The takeaway
If an old model file fails to load, open it once in the unsafe mode if you trust it, then save it again.
Step by step
How to load a legacy PyTorch checkpoint after the change
- Load with safe modetorch.load with weights_only=True raises pickle.UnpicklingError on legacy checkpoints
- Load once, unsafe modeTrusted files only: load with weights_only=False
- Save it againRe-save the checkpoint with torch.save
What it means for you
Re-save any trusted legacy checkpoints with torch.save after loading them with weights_only=False, and update tests that load old fixtures.
Teams with archived model files from before PyTorch 1.6 may hit load errors and need a one-time migration step.