From 3b0692032d92fcc11b8e6577a2b172a9aebb0fe1 Mon Sep 17 00:00:00 2001 From: Jiabin Yang Date: Fri, 11 Oct 2019 12:52:30 +0800 Subject: [PATCH] Cherry pick en doc (#20471) * test=document_fix, test=release/1.6, refine en doc (#20317) * test=develop, fix docker with paddle nccl problem * test=develop, refine en_doc for Variable and Program * test=document_fix, fix English doc for Variable and Program * test=document_fix, refine astype code block style * test=document_fix, add example code for Variable properties * test=release/1.6, test=document_fix, Refine en doc (#20409) * test=develop, fix docker with paddle nccl problem * test=develop, refine en_doc for Variable and Program * test=document_fix, fix English doc for Variable and Program * test=document_fix, refine astype code block style * test=document_fix, add example code for Variable properties * test=document_fix, fix BackwardStrategy English Doc * test=document_fix, fix syntax * test=document_fix, refresh API.spec * test=document_fix, refine api spec * test=document_fix, refine api spec * test=release/1.6, test=document_fix, remove useless files --- paddle/fluid/API.spec | 2 +- paddle/fluid/pybind/imperative.cc | 42 ++++++++++++++++++------------- 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/paddle/fluid/API.spec b/paddle/fluid/API.spec index 89485f4580..f33463ced8 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 63e3e7e857..22a8d0b6a6 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", -- GitLab