From 222c9fe57e6a4ca3ae486203950061d13d36a1be Mon Sep 17 00:00:00 2001 From: wopeizl Date: Thu, 20 Jun 2019 19:56:10 +0800 Subject: [PATCH] fix doc for LarsMomentumOptimizer test=develop (#18208) --- python/paddle/fluid/optimizer.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/python/paddle/fluid/optimizer.py b/python/paddle/fluid/optimizer.py index 006cd29143..67d12f0648 100644 --- a/python/paddle/fluid/optimizer.py +++ b/python/paddle/fluid/optimizer.py @@ -1070,8 +1070,22 @@ class LarsMomentumOptimizer(Optimizer): Examples: .. code-block:: python - optimizer = fluid.optimizer.LarsMomentum(learning_rate=0.2, momentum=0.1, lars_weight_decay=0.001) - optimizer.minimize(cost) + import paddle.fluid as fluid + import numpy as np + + np_inp = np.array([[1.0, 2.0], [3.0, 4.0]], dtype=np.float32) + inp = fluid.layers.data( + name="inp", shape=[2, 2], append_batch_size=False) + out = fluid.layers.fc(inp, size=3) + out = fluid.layers.reduce_sum(out) + optimizer = fluid.optimizer.LarsMomentumOptimizer(learning_rate=0.001, momentum=0.9) + optimizer.minimize(out) + + exe = fluid.Executor(fluid.CPUPlace()) + exe.run(fluid.default_startup_program()) + exe.run( + feed={"inp": np_inp}, + fetch_list=[out.name]) """ _velocity_acc_str = "velocity" -- GitLab