From cbfb005f7cce79974795b148e265f594f59477c8 Mon Sep 17 00:00:00 2001 From: Ivan Komarov Date: Mon, 1 Sep 2025 19:57:15 +0000 Subject: [PATCH] Fix type checking for persistent loads in the weights-only unpickler (#161661) The error message here implies that we can only call `self.persistent_load(...)` for ints or tuples, but due to the second part of the type check being inverted, weights-only unpickler will throw an exception iff `pid` is an int. Pull Request resolved: https://github.com/pytorch/pytorch/pull/161661 Approved by: https://github.com/Skylion007 --- torch/_weights_only_unpickler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/torch/_weights_only_unpickler.py b/torch/_weights_only_unpickler.py index 745cdd315a63..9382a5500e0e 100644 --- a/torch/_weights_only_unpickler.py +++ b/torch/_weights_only_unpickler.py @@ -520,7 +520,7 @@ class Unpickler: elif key[0] == BINPERSID[0]: pid = self.stack.pop() # Only allow persistent load of storage - if type(pid) is not tuple and not type(pid) is not int: + if type(pid) is not tuple and type(pid) is not int: raise UnpicklingError( f"persistent_load id must be tuple or int, but got {type(pid)}" )