MCPcopy Create free account
hub / github.com/PaddlePaddle/Paddle / load

Function load

python/paddle/static/io.py:1640–1860  ·  view source on GitHub ↗

:api_attr: Static Graph This function get parameters and optimizer information from program, and then get corresponding value from file. An exception will throw if shape or dtype of the parameters is not match. This function can also load model file saved with [ save_params, save_

(
    program: Program,
    model_path: str,
    executor: Executor | None = None,
    var_list: Sequence[Tensor] | None = None,
)

Source from the content-addressed store, hash-verified

1638
1639@static_only
1640def load(
1641 program: Program,
1642 model_path: str,
1643 executor: Executor | None = None,
1644 var_list: Sequence[Tensor] | None = None,
1645) -> None:
1646 """
1647 :api_attr: Static Graph
1648
1649 This function get parameters and optimizer information from program, and then get corresponding value from file.
1650 An exception will throw if shape or dtype of the parameters is not match.
1651
1652 This function can also load model file saved with [ save_params, save_persistables, save_vars ].
1653 var_list can not be None when load single model file
1654 ( filename is not None When save_params, save_persistables or save_vars is called ).
1655
1656 Args:
1657 program(Program): The program will be loaded
1658 model_path(str): The file prefix store the program
1659 executor(Executor, optional): The executor used for initialize the parameter
1660 When startup program is not run.
1661 var_list(list|tuple, optional): The Tensor list/tuple to load single model file saved with
1662 [ save_params, save_persistables, save_vars ].
1663 Default: None
1664
1665 Returns:
1666 None
1667
1668 Examples:
1669 .. code-block:: pycon
1670
1671 >>> import paddle
1672 >>> import paddle.static as static
1673
1674 >>> paddle.enable_static()
1675
1676 >>> x = static.data(name="x", shape=[10, 10], dtype='float32')
1677 >>> linear1 = paddle.nn.Linear(10, 10)
1678 >>> linear2 = paddle.nn.Linear(10, 10)
1679 >>> y = linear1(x)
1680 >>> z = linear2(y)
1681
1682 >>> place = paddle.CPUPlace()
1683 >>> exe = static.Executor(place)
1684 >>> exe.run(static.default_startup_program())
1685 >>> prog = static.default_main_program()
1686
1687 >>> static.save(prog, "./temp")
1688 >>> static.load(prog, "./temp")
1689 """
1690 assert executor is None or isinstance(executor, Executor)
1691
1692 model_prefix = model_path
1693 if model_prefix.endswith(".pdparams"):
1694 model_prefix = model_prefix[:-9]
1695 elif model_prefix.endswith(".pdopt"):
1696 model_prefix = model_prefix[:-6]
1697 elif model_prefix.endswith(".pdmodel"):

Callers

nothing calls this directly

Calls 15

in_pir_modeFunction · 0.90
global_scopeFunction · 0.90
_pickle_loads_macFunction · 0.90
_pack_loaded_dictFunction · 0.90
load_pirFunction · 0.85
ValueErrorClass · 0.85
setClass · 0.85
listFunction · 0.85
load_varsFunction · 0.85
RuntimeErrorClass · 0.85
filterFunction · 0.85
_safe_load_pickleFunction · 0.85

Tested by

no test coverage detected