提交 c14298c5 编写于 作者: Z zhongpu 提交者: hong

polish Optimizer's API description, test=develop (#22314) (#22324)

上级 df320a40
...@@ -123,8 +123,12 @@ class Optimizer(object): ...@@ -123,8 +123,12 @@ class Optimizer(object):
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid 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 = {} state_dict = {}
...@@ -160,19 +164,19 @@ class Optimizer(object): ...@@ -160,19 +164,19 @@ class Optimizer(object):
.. code-block:: python .. code-block:: python
with fluid.dygraph.guard(): with fluid.dygraph.guard():
emb = fluid.dygraph.Embedding( "emb", [10, 10]) emb = fluid.dygraph.Embedding([10, 10])
state_dict = emb.state_dict() 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), adam = fluid.optimizer.Adam(learning_rate=fluid.layers.noam_decay( 100, 10000),
parameter_list = emb.parameters() ) parameter_list=emb.parameters())
state_dict = adam.state_dict() 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") para_state_dict, opti_state_dict = fluid.load_dygraph( "paddle_dy")
adam.set_dict( opti_state_dict ) adam.set_dict(opti_state_dict)
''' '''
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册