From aadd81b662f36b9a6317bc15c3813a200d752caa Mon Sep 17 00:00:00 2001 From: lvmengsi Date: Wed, 30 Oct 2019 16:45:54 +0800 Subject: [PATCH] Fix gradients (#20857) * fix_gradients * fix_gradients, test=develop --- python/paddle/fluid/backward.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/python/paddle/fluid/backward.py b/python/paddle/fluid/backward.py index 860e7092f69..3eca39c2b18 100644 --- a/python/paddle/fluid/backward.py +++ b/python/paddle/fluid/backward.py @@ -1247,9 +1247,13 @@ def calc_gradient(targets, inputs, target_gradients=None, no_grad_set=None): target = targets[i] if grad is None: grad_name = _append_grad_suffix_(target.name) - target_shape = paddle.fluid.layers.shape(target) + target_shape = target.name + '_shape' + block.desc.append_op().copy_from( + _create_op_desc_("shape", {'Input': [target.name]}, + {"Out": [target_shape]}, {})) + input_grad_names_set.add(target_shape) op_desc = _create_op_desc_("fill_constant", - {"ShapeTensor": [target_shape.name]}, + {"ShapeTensor": [target_shape]}, {"Out": [grad_name]}, { "shape": target.shape, "value": 1.0, -- GitLab