load_dygraph¶
- paddle.fluid.dygraph.checkpoint. load_dygraph ( model_path, **configs ) [source]
-
- Api_attr
-
imperative
Load parameter state dict from disk.
Note
Due to some historical reasons, if you load
state_dict
from the saved result of paddle.static.save_inference_model, the structured variable name will cannot be restored. You need to set the argument use_structured_name=False when using Layer.set_state_dict later.- Parameters
-
model_path (str) – The file prefix store the state_dict. (The path should Not contain suffix ‘.pdparams’)
**configs (dict, optional) – Other load configuration options for compatibility. We do not recommend using these configurations, if not necessary, DO NOT use them. Default None. The following options are currently supported: (1) model_filename (str): The inference model file name of the paddle 1.x
save_inference_model
save format. Default file name is__model__
. (2) params_filename (str): The persistable variables file name of the paddle 1.xsave_inference_model
save format. No default file name, save variables separately by default.
- Returns
-
the dict store the state_dict
- Return type
-
state_dict(dict)
Examples
import paddle import paddle.fluid as fluid paddle.disable_static() emb = paddle.nn.Embedding(10, 10) state_dict = emb.state_dict() fluid.save_dygraph(state_dict, "paddle_dy") scheduler = paddle.optimizer.lr.NoamDecay( d_model=0.01, warmup_steps=100, verbose=True) adam = paddle.optimizer.Adam( learning_rate=scheduler, parameters=emb.parameters()) state_dict = adam.state_dict() fluid.save_dygraph(state_dict, "paddle_dy") para_state_dict, opti_state_dict = fluid.load_dygraph("paddle_dy")