diff --git a/python/paddle/fluid/optimizer.py b/python/paddle/fluid/optimizer.py index 29a6644f7446bdcf76cfb10c2bda8b5d037766cf..f3af2c741925b2d4d1c3d9568287454051436695 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) '''