diff --git a/paddle/fluid/API.spec b/paddle/fluid/API.spec index 89485f458057fec9ba82cd20ebaf2145cdca1bf4..f33463ced832dd1b2c8a5312df386a4cf014d01e 100644 --- a/paddle/fluid/API.spec +++ b/paddle/fluid/API.spec @@ -898,7 +898,7 @@ paddle.fluid.dygraph.CosineDecay ('paddle.fluid.dygraph.learning_rate_scheduler. paddle.fluid.dygraph.CosineDecay.__init__ (ArgSpec(args=['self', 'learning_rate', 'step_each_epoch', 'epochs', 'begin', 'step', 'dtype'], varargs=None, keywords=None, defaults=(0, 1, 'float32')), ('document', '6adf97f83acf6453d4a6a4b1070f3754')) paddle.fluid.dygraph.CosineDecay.create_lr_var (ArgSpec(args=['self', 'lr'], varargs=None, keywords=None, defaults=None), ('document', '013bc233558149d0757b3df57845b866')) paddle.fluid.dygraph.CosineDecay.step (ArgSpec(args=['self'], varargs=None, keywords=None, defaults=None), ('document', '6adf97f83acf6453d4a6a4b1070f3754')) -paddle.fluid.dygraph.BackwardStrategy ('paddle.fluid.core_avx.BackwardStrategy', ('document', '5d9496052ec793810c9f12ffad5c73ce')) +paddle.fluid.dygraph.BackwardStrategy ('paddle.fluid.core_avx.BackwardStrategy', ('document', '4fcdc2c2d0c162f3840737abda39eb27')) paddle.fluid.dygraph.BackwardStrategy.__init__ __init__(self: paddle.fluid.core_avx.BackwardStrategy) -> None paddle.fluid.transpiler.DistributeTranspiler ('paddle.fluid.transpiler.distribute_transpiler.DistributeTranspiler', ('document', 'b2b19821c5dffcd11473d6a4eef089af')) paddle.fluid.transpiler.DistributeTranspiler.__init__ (ArgSpec(args=['self', 'config'], varargs=None, keywords=None, defaults=(None,)), ('document', '6adf97f83acf6453d4a6a4b1070f3754')) diff --git a/paddle/fluid/pybind/imperative.cc b/paddle/fluid/pybind/imperative.cc index 63e3e7e8570f3fc2afabf14c95e8a558de1482a6..22a8d0b6a6334ae53b340b6e3de3a0a837454d7f 100644 --- a/paddle/fluid/pybind/imperative.cc +++ b/paddle/fluid/pybind/imperative.cc @@ -180,28 +180,36 @@ void BindImperative(py::module *m_ptr) { py::class_ backward_strategy( m, "BackwardStrategy", R"DOC( - BackwardStrategy is a descriptor of a how to run the backward process. Now it has: + BackwardStrategy is a descriptor of how to run the backward process. - 1. :code:`sort_sum_gradient`, which will sum the gradient by the reverse order of trace. + **Note**: + **This API is only avaliable in** `Dygraph <../../user_guides/howto/dygraph/DyGraph.html>`_ **Mode** - Examples: + Attribute: + **sort_sum_gradient**: - .. code-block:: python + If framework will sum the gradient by the reverse order of trace. eg. x_var ( :ref:`api_guide_Variable` ) will be the input of multiple OP such as :ref:`api_fluid_layers_scale` , this attr will decide if framework will sum gradient of `x_var` by the reverse order. - import numpy as np - import paddle.fluid as fluid - from paddle.fluid import FC + By Default: False - x = np.ones([2, 2], np.float32) - with fluid.dygraph.guard(): - inputs2 = [] - for _ in range(10): - inputs2.append(fluid.dygraph.base.to_variable(x)) - ret2 = fluid.layers.sums(inputs2) - loss2 = fluid.layers.reduce_sum(ret2) - backward_strategy = fluid.dygraph.BackwardStrategy() - backward_strategy.sort_sum_gradient = True - loss2.backward(backward_strategy) + Examples: + .. code-block:: python + + import numpy as np + import paddle.fluid as fluid + + x = np.ones([2, 2], np.float32) + with fluid.dygraph.guard(): + x_var = fluid.dygraph.to_variable(x) + sums_inputs = [] + # x_var will be multi-scales' input here + for _ in range(10): + sums_inputs.append(fluid.layers.scale(x_var)) + ret2 = fluid.layers.sums(sums_inputs) + loss2 = fluid.layers.reduce_sum(ret2) + backward_strategy = fluid.dygraph.BackwardStrategy() + backward_strategy.sort_sum_gradient = True + loss2.backward(backward_strategy) )DOC"); backward_strategy.def(py::init()) .def_property("sort_sum_gradient",