AIAIAI.FYI
LIVE

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.

Illustrative photo: blurred lines of code on a dark screen
Illustrative photo: blurred lines of code on a dark screen Photo by Bernd 馃摲 Dittrich on Unsplash

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

  1. Load with safe modetorch.load with weights_only=True raises pickle.UnpicklingError on legacy checkpoints
  2. Load once, unsafe modeTrusted files only: load with weights_only=False
  3. Save it againRe-save the checkpoint with torch.save
Source: pytorch Releases 路 Per PyTorch pull request #204437

What it means for you

If you build software

Re-save any trusted legacy checkpoints with torch.save after loading them with weights_only=False, and update tests that load old fixtures.

If you run a business

Teams with archived model files from before PyTorch 1.6 may hit load errors and need a one-time migration step.

Get stories like this every morning