Skip to content

Commit 55c30da

Browse files
committed
use _safe_pickle_load in source code
Signed-off-by: chensuyue <suyue.chen@intel.com>
1 parent 7ec1618 commit 55c30da

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

neural_compressor/data/datasets/dataset.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
from PIL import Image
2323

24-
from neural_compressor.utils.utility import LazyImport, singleton
24+
from neural_compressor.utils.utility import LazyImport, singleton, _safe_pickle_load
2525

2626
torch = LazyImport("torch")
2727
torchvision = LazyImport("torchvision")
@@ -415,7 +415,7 @@ def __init__(self, root, train=False, transform=None, filter=None, download=True
415415
for file_name, checksum in downloaded_list:
416416
file_path = os.path.join(self.root, file_name)
417417
with open(file_path, "rb") as f:
418-
entry = pickle.load(f, encoding="latin1")
418+
entry = _safe_pickle_load(f, encoding="latin1")
419419
self.data.append(entry["data"])
420420
if "labels" in entry:
421421
self.targets.extend(entry["labels"])
@@ -435,7 +435,7 @@ def load_meta(self): # pragma: no cover
435435
"Dataset metadata file not found or corrupted." + " You can use download=True to download it"
436436
)
437437
with open(path, "rb") as infile:
438-
data = pickle.load(infile, encoding="latin1")
438+
data = _safe_pickle_load(infile, encoding="latin1")
439439
self.classes = data[self.meta["key"]]
440440
self.class_to_idx = {_class: i for i, _class in enumerate(self.classes)}
441441

neural_compressor/mix_precision.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from .model import Model
3030
from .strategy import STRATEGIES
3131
from .utils import alias_param, logger
32-
from .utils.utility import CpuInfo, secure_check_eval_func, time_limit
32+
from .utils.utility import CpuInfo, secure_check_eval_func, time_limit, _safe_pickle_load
3333

3434

3535
@alias_param("conf", param_alias="config")
@@ -142,7 +142,7 @@ def fit(model, conf, eval_func=None, eval_dataloader=None, eval_metric=None, **k
142142
if resume_file:
143143
assert os.path.exists(resume_file), "The specified resume file {} doesn't exist!".format(resume_file)
144144
with open(resume_file, "rb") as f:
145-
_resume = pickle.load(f).__dict__
145+
_resume = _safe_pickle_load(f).__dict__
146146

147147
strategy = STRATEGIES["automixedprecision"](
148148
model=wrapped_model,

neural_compressor/training.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
from .metric import register_customer_metric
3333
from .model.model import Model
3434
from .utils import logger
35-
from .utils.utility import time_limit
35+
from .utils.utility import time_limit, _safe_pickle_load
3636

3737

3838
class CompressionManager:
@@ -312,7 +312,7 @@ def eval_func(model):
312312
if resume_file:
313313
assert os.path.exists(resume_file), "The specified resume file {} doesn't exist!".format(resume_file)
314314
with open(resume_file, "rb") as f:
315-
_resume = pickle.load(f).__dict__
315+
_resume = _safe_pickle_load(f).__dict__
316316

317317
if eval_func is None and eval_dataloader is None: # pragma: no cover
318318
logger.info("Quantize model without tuning!")

0 commit comments

Comments
 (0)