From 6fb646065cab1a3df1701d62d9ff3b76dfa17af5 Mon Sep 17 00:00:00 2001 From: WeiXin Date: Tue, 1 Jun 2021 11:19:15 +0800 Subject: [PATCH] [Cherry-Pick]Set the default value of protocol to 4. (#32904) #33009 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit paddle.save paddle.static.save protocol的默认值改为4(原默认值为2)。 pickle protocol=4相交于protocol=2: protocol=4时保存/加载大于4G的单个numpy.ndarray 等。 protocol=4时保存/加载的速度有明显提升。 Python2 不支持protocol=4(paddle2.1主要支持Python3,不再考虑Python2)。 兼容问题:pickle版本(protocol)会写到文件里面,pickle load的时候会自动识别到protocol,paddle2.1(paddle.save pickle默认版本为2)可以加载paddle2.1.1的模型(paddle.save pickle默认版本为4)。 原始PR:#32904 --- python/paddle/fluid/io.py | 4 ++-- python/paddle/framework/io.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/python/paddle/fluid/io.py b/python/paddle/fluid/io.py index 30baa2aa26..30a0b4053e 100644 --- a/python/paddle/fluid/io.py +++ b/python/paddle/fluid/io.py @@ -1788,7 +1788,7 @@ def _legacy_save(param_dict, model_path, protocol=2): @static_only -def save(program, model_path, protocol=2, **configs): +def save(program, model_path, protocol=4, **configs): """ :api_attr: Static Graph @@ -1802,7 +1802,7 @@ def save(program, model_path, protocol=2, **configs): program(Program) : The program to saved. model_path(str): the file prefix to save the program. The format is "dirname/file_prefix". If file_prefix is empty str. A exception will be raised protocol(int, optional): The protocol version of pickle module must be greater than 1 and less than 5. - Default: 2 + Default: 4 configs(dict, optional) : optional keyword arguments. Returns: diff --git a/python/paddle/framework/io.py b/python/paddle/framework/io.py index de2116cd43..1705db50d3 100644 --- a/python/paddle/framework/io.py +++ b/python/paddle/framework/io.py @@ -491,7 +491,7 @@ def _save_binary_var(obj, path): format(type(obj))) -def save(obj, path, protocol=2, **configs): +def save(obj, path, protocol=4, **configs): ''' Save an object to the specified path. @@ -512,7 +512,7 @@ def save(obj, path, protocol=2, **configs): path(str) : The path of the object to be saved. If saved in the current directory, the input path string will be used as the file name. protocol(int, optional): The protocol version of pickle module must be greater than 1 and less than 5. - Default: 2 + Default: 4 **configs(dict, optional): optional keyword arguments. The following options are currently supported: use_binary_format(bool): When the saved object is static graph variable, you can specify ``use_binary_for_var``. If True, save the file in the c++ binary format when saving a single static graph variable; otherwise, save it in pickle format. -- GitLab