未验证 提交 6fb64606 编写于 作者: W WeiXin 提交者: GitHub

[Cherry-Pick]Set the default value of protocol to 4. (#32904) #33009



    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
上级 ca0cc8ab
......@@ -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:
......
......@@ -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.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册