From c14298c5ac88e7e20c46764ec51da373a81773cf Mon Sep 17 00:00:00 2001 From: zhongpu <2013000149@qq.com> Date: Fri, 17 Jan 2020 14:21:45 +0800 Subject: [PATCH] polish Optimizer's API description, test=develop (#22314) (#22324) --- python/paddle/fluid/optimizer.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/python/paddle/fluid/optimizer.py b/python/paddle/fluid/optimizer.py index 29a6644f744..f3af2c74192 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) ''' -- GitLab