From b768708e5d55af67fa2225c4d40cb6b8f536471c Mon Sep 17 00:00:00 2001 From: songyouwei Date: Sun, 16 Feb 2020 14:53:20 +0800 Subject: [PATCH] fix pickle load encoding between python 2 and 3 (#22621) test=develop --- python/paddle/fluid/dygraph/checkpoint.py | 4 ++-- python/paddle/fluid/io.py | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/python/paddle/fluid/dygraph/checkpoint.py b/python/paddle/fluid/dygraph/checkpoint.py index 6bda099669..a51c431c51 100644 --- a/python/paddle/fluid/dygraph/checkpoint.py +++ b/python/paddle/fluid/dygraph/checkpoint.py @@ -132,7 +132,7 @@ def load_dygraph(model_path, keep_name_table=False): with open(params_file_path, 'rb') as f: para_dict = pickle.load(f) if six.PY2 else pickle.load( - f, encoding='bytes') + f, encoding='latin1') if not keep_name_table and "StructuredToParameterName@@" in para_dict: del para_dict["StructuredToParameterName@@"] @@ -141,6 +141,6 @@ def load_dygraph(model_path, keep_name_table=False): if os.path.exists(opti_file_path): with open(opti_file_path, 'rb') as f: opti_dict = pickle.load(f) if six.PY2 else pickle.load( - f, encoding='bytes') + f, encoding='latin1') return para_dict, opti_dict diff --git a/python/paddle/fluid/io.py b/python/paddle/fluid/io.py index 7e65060829..792d0f7bf5 100644 --- a/python/paddle/fluid/io.py +++ b/python/paddle/fluid/io.py @@ -1696,7 +1696,7 @@ def load(program, model_path, executor=None, var_list=None): executor._default_executor) with open(parameter_file_name, 'rb') as f: load_dict = pickle.load(f) if six.PY2 else pickle.load( - f, encoding='bytes') + f, encoding='latin1') for v in parameter_list: assert v.name in load_dict, \ "Can not find [{}] in model file [{}]".format( @@ -1717,7 +1717,7 @@ def load(program, model_path, executor=None, var_list=None): with open(opt_file_name, 'rb') as f: load_dict = pickle.load(f) if six.PY2 else pickle.load( - f, encoding='bytes') + f, encoding='latin1') for v in optimizer_var_list: assert v.name in load_dict, \ "Can not find [{}] in model file [{}]".format( @@ -1842,13 +1842,13 @@ def load_program_state(model_path, var_list=None): with open(parameter_file_name, 'rb') as f: para_dict = pickle.load(f) if six.PY2 else pickle.load( - f, encoding='bytes') + f, encoding='latin1') opt_file_name = model_prefix + ".pdopt" if os.path.exists(opt_file_name): with open(opt_file_name, 'rb') as f: opti_dict = pickle.load(f) if six.PY2 else pickle.load( - f, encoding='bytes') + f, encoding='latin1') para_dict.update(opti_dict) -- GitLab