diff --git a/python/paddle/fluid/optimizer.py b/python/paddle/fluid/optimizer.py index afb9cc4c49d56bfa05dd70107b97462015a3a373..52574575c34019cdb132afb2c72af6d1e2049879 100644 --- a/python/paddle/fluid/optimizer.py +++ b/python/paddle/fluid/optimizer.py @@ -123,8 +123,12 @@ class Optimizer(object): .. code-block:: python import paddle.fluid as fluid - adam = fluid.optimizer.Adam(0.001) - state_dict = adam.state_dict() + + with fluid.dygraph.guard(): + emb = fluid.dygraph.Embedding([10, 10]) + + adam = fluid.optimizer.Adam(0.001, parameter_list=emb.parameters()) + state_dict = adam.state_dict() ''' state_dict = {} @@ -160,19 +164,19 @@ class Optimizer(object): .. code-block:: python with fluid.dygraph.guard(): - emb = fluid.dygraph.Embedding( "emb", [10, 10]) + emb = fluid.dygraph.Embedding([10, 10]) state_dict = emb.state_dict() - fluid.save_dygraph( state_dict, "paddle_dy") + fluid.save_dygraph(state_dict, "paddle_dy") - adam = fluid.optimizer.Adam( learning_rate = fluid.layers.noam_decay( 100, 10000), - parameter_list = emb.parameters() ) + adam = fluid.optimizer.Adam(learning_rate=fluid.layers.noam_decay( 100, 10000), + parameter_list=emb.parameters()) state_dict = adam.state_dict() - fluid.save_dygraph( state_dict, "padle_dy") + fluid.save_dygraph(state_dict, "paddle_dy") para_state_dict, opti_state_dict = fluid.load_dygraph( "paddle_dy") - adam.set_dict( opti_state_dict ) + adam.set_dict(opti_state_dict) '''