Skip to content

Commit 002c6d7

Browse files
authored
Merge branch 'main' into main
2 parents 888e435 + 4dbe5ef commit 002c6d7

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

opacus/utils/module_utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)