File tree Expand file tree Collapse file tree 1 file changed +3
-1
lines changed Expand file tree Collapse file tree 1 file changed +3
-1
lines changed Original file line number Diff line number Diff line change @@ -89,6 +89,8 @@ def clone_module(module: nn.Module) -> nn.Module:
8989 """
9090 Handy utility to clone an nn.Module. PyTorch doesn't always support copy.deepcopy(), so it is
9191 just easier to serialize the model to a BytesIO and read it from there.
92+ When ``weights_only=False``, ``torch.load()`` uses "pickle" module implicity, which is known to be insecure.
93+ Only load the model you trust.
9294
9395 Args:
9496 module: The module to clone
@@ -99,7 +101,7 @@ def clone_module(module: nn.Module) -> nn.Module:
99101 with io .BytesIO () as bytesio :
100102 torch .save (module , bytesio )
101103 bytesio .seek (0 )
102- module_copy = torch .load (bytesio )
104+ module_copy = torch .load (bytesio , weights_only = False )
103105 next_param = next (
104106 module .parameters (), None
105107 ) # Eg, InstanceNorm with affine=False has no params
You can’t perform that action at this time.
0 commit comments