Skip to content

Fix predictor checkpoint loading on PyTorch >= 2.6 (weights_only) - #80

Merged
h-munakata merged 1 commit into
line:mainfrom
Kingpython123:fix/torch-load-weights-only
Nov 1, 2026
Merged

h-munakata merged 1 commit into
line:mainfrom
Kingpython123:fix/torch-load-weights-only

Conversation

@Kingpython123

Copy link
Copy Markdown
Contributor

Fixes #79

Problem

On PyTorch >= 2.6, torch.load defaults to weights_only=True. The released checkpoints store their config as an easydict.EasyDict under ckpt['opt'], which the weights-only unpickler rejects. BasePredictor.__init__ did not pass weights_only, so every predictor failed to load every released checkpoint:

_pickle.UnpicklingError: Weights only load failed. ...
WeightsUnpickler error: Unsupported global: GLOBAL easydict.EasyDict was not an allowed global by default.

CI pins torch==2.1.0, so it did not catch this.

Fix

Pass weights_only=False in BasePredictor.__init__, the same as training/train.py and training/evaluate.py already do since d0be10b. A short comment notes that only trusted checkpoints should be loaded. The keyword exists since torch 1.13, so this also works on the torch 2.1 used in CI. torch.serialization.add_safe_globals([EasyDict]) would keep weights-only loading, but it only exists from torch 2.4, so it would break the pinned CI version.

Test

Added test_load_checkpoint_with_easydict_opt to tests/test_models.py, the file CI runs. It saves a tiny Moment-DETR checkpoint with an EasyDict opt, loads it with MomentDETRPredictor on CPU, and checks that torch.load received weights_only=False. The check on the keyword keeps the test meaningful on torch < 2.6 as well. It needs no downloaded weights or videos.

Verification (torch 2.15.0+cpu, Python 3.11, CPU)

  • The new test passes with this change. With the change reverted it fails with the UnpicklingError above.
  • These released checkpoints now load: CG-DETR, QD-DETR and Moment-DETR qvhighlight/clip from the README results.zip, and clip_cg_detr_qvhighlight.ckpt from Zenodo.
  • ruff check and mypy pass on the changed files.

torch>=2.6 defaults torch.load to weights_only=True, which cannot
unpickle the EasyDict config stored under ckpt['opt'], so every
predictor failed to load the released checkpoints. Match
training/train.py and training/evaluate.py, and add a regression test.

Fixes line#79
@awkrail

awkrail commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

LGTM
@h-munakata could you merge it?

@h-munakata
h-munakata merged commit 9b04316 into line:main Nov 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Predictors fail to load pre-trained checkpoints on PyTorch >= 2.6 (UnpicklingError: weights_only)

3 participants