Skip to content

Commit be9a2b2

Browse files
authored
Merge pull request #8652 from jacquesqiao/fix-parallel-do-with-non-parameter
parallel-do should not merge the gradient of parameter that stop_gradient=True
2 parents f9c1b6f + c4996fb commit be9a2b2

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

python/paddle/fluid/backward.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,10 @@ def _callback_lookup_(op):
220220
:return: callback function
221221
"""
222222
if op.type == 'parallel_do' and op.attr('use_nccl'):
223+
all_vars = op.block.vars
223224
param_names = set(op.input('parameters'))
225+
param_names = filter(lambda name: all_vars[name].stop_gradient is False,
226+
param_names)
224227
param_grad_names = [n + "@GRAD" for n in param_names]
225228

226229
class ParallelDoCallBack(object):

python/paddle/fluid/tests/unittests/test_parallel_op.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ def __network__():
170170
x = fluid.layers.data(shape=[784], dtype='float32', name='img')
171171
x = yield x
172172
hidden = fluid.layers.fc(input=x, size=200, param_attr='fc1.w')
173+
hidden = fluid.layers.batch_norm(input=hidden)
173174
loss = fluid.layers.mean(hidden)
174175
yield loss
175176

0 commit comments

Comments
 (0)