Repository navigation
Fix predictor checkpoint loading on PyTorch >= 2.6 (weights_only) - #80
Merged
Merged
Conversation
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
Contributor
|
LGTM |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #79
Problem
On PyTorch >= 2.6,
torch.loaddefaults toweights_only=True. The released checkpoints store their config as aneasydict.EasyDictunderckpt['opt'], which the weights-only unpickler rejects.BasePredictor.__init__did not passweights_only, so every predictor failed to load every released checkpoint:CI pins
torch==2.1.0, so it did not catch this.Fix
Pass
weights_only=FalseinBasePredictor.__init__, the same astraining/train.pyandtraining/evaluate.pyalready 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_opttotests/test_models.py, the file CI runs. It saves a tiny Moment-DETR checkpoint with anEasyDictopt, loads it withMomentDETRPredictoron CPU, and checks thattorch.loadreceivedweights_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)
UnpicklingErrorabove.qvhighlight/clipfrom the READMEresults.zip, andclip_cg_detr_qvhighlight.ckptfrom Zenodo.ruff checkandmypypass on the changed files.