Skip to content

Commit af341ae

Browse files
committed
Harden POET checkpoint loading
Update POET model loading to use `torch.serialization.safe_globals([argparse.Namespace])` and `weights_only=True` when calling `torch.load`. This reduces unsafe pickle deserialization risk while still allowing legacy checkpoint metadata needed by the model state load.
1 parent ce90dd6 commit af341ae

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

‎dlclivegui/services/inference/models/poet/poet_processor.py‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from __future__ import annotations
44

5+
import argparse
56
import importlib
67
import logging
78
from pathlib import Path
@@ -182,11 +183,13 @@ def _build_model(
182183
aux_loss=False,
183184
)
184185

185-
checkpoint = torch.load(
186-
self._checkpoint_path,
187-
map_location="cpu",
188-
weights_only=False,
189-
)
186+
with torch.serialization.safe_globals([argparse.Namespace]):
187+
checkpoint = torch.load(
188+
self._checkpoint_path,
189+
map_location="cpu",
190+
# weights_only=False,
191+
weights_only=True,
192+
)
190193
model.load_state_dict(
191194
checkpoint["model"],
192195
strict=True,

0 commit comments

Comments
 (0)