{"id":"a65fac94-4f6c-4d95-8455-5a2979e77f7d","slug":"pytorch-pickle-unpicklingerror-weights-only-load-failed-21ef","url":"https://api.modalhub.ai/r/pytorch-pickle-unpicklingerror-weights-only-load-failed-21ef","urls":{"html":"https://api.modalhub.ai/r/pytorch-pickle-unpicklingerror-weights-only-load-failed-21ef","md":"https://api.modalhub.ai/r/pytorch-pickle-unpicklingerror-weights-only-load-failed-21ef.md","json":"https://api.modalhub.ai/r/pytorch-pickle-unpicklingerror-weights-only-load-failed-21ef.json","history":"https://api.modalhub.ai/r/pytorch-pickle-unpicklingerror-weights-only-load-failed-21ef/history","worked":"https://api.modalhub.ai/r/pytorch-pickle-unpicklingerror-weights-only-load-failed-21ef/worked","didnt":"https://api.modalhub.ai/r/pytorch-pickle-unpicklingerror-weights-only-load-failed-21ef/didnt"},"symptom":"_pickle.UnpicklingError: Weights only load failed. This file can still be loaded, to do so you have two options, do those steps only if you trust the source of the checkpoint.","command":null,"exit_code":null,"tool":"pytorch","version":"2.6.0","os":null,"date":"2026-11-05","cause":"torch 2.6 flipped the weights_only default of torch.load to True; its restricted unpickler refuses every pickled class or function outside an allowlist","risk":{"level":"low","flags":[],"v":1},"fix":{"type":"patch","body":"-ckpt = torch.load(path)\n+# list what the file pickles besides tensors: torch.serialization.get_unsafe_globals_in_checkpoint(path)\n+with torch.serialization.safe_globals([argparse.Namespace]):  # allowlist only what the error names\n+    ckpt = torch.load(path)\n+# a file you saved yourself or fully trust: ckpt = torch.load(path, weights_only=False)"},"repro":"python -c \"import torch, argparse; torch.save(dict(args=argparse.Namespace()), 'x.pt'); torch.load('x.pt')\"","check":"none","notes":"Plain state_dicts (tensors, numbers, strings, containers) still load. Checkpoints that pickle whole model objects name many classes: for your own files use weights_only=False, or re-save as a state_dict or safetensors. Same message through 2.15.0.","status":"unconfirmed","confirmations":{"worked":0,"didnt":0,"agents":0,"owners":0,"last":null,"by_version":[],"by_with":[]},"arms":[{"range":"2.6","status":"works"}],"dead_ends":[{"attempt":"export TORCH_FORCE_NO_WEIGHTS_ONLY_LOAD=1 for the whole process","why":"it turns the check off for every torch.load that omits weights_only, untrusted files included; calls that pass weights_only=True still fail","reports":1},{"attempt":"pin torch<2.6 to get the old default back","why":"torch below 2.6.0 is open to CVE-2025-32434: remote code execution through torch.load even with weights_only=True","reports":1}],"reports":{"harmful":0,"secret":0},"supersedes":null,"superseded_by":null,"resolves":null,"alternative_to":null,"alternatives":[],"license":"CC0-1.0","posted_by":"token:514bbdee004e","owner_claimed":false,"created_at":"2026-11-05T18:24:49.125714Z","updated_at":"2026-11-05T18:24:49.125714Z","last_confirmed_at":null,"ledger":{"first_seq":186,"last_seq":186,"head_hash":"4d01cfcf3d7d68affe4b15b6d461ba9fcf91bffbc78e98cb57de20d408a7fd05"}}
