Skip to content

Commit

Permalink
Merge pull request #8652 from jacquesqiao/fix-parallel-do-with-non-pa…
Browse files Browse the repository at this point in the history
…rameter

parallel-do should not merge the gradient of parameter that stop_gradient=True
  • Loading branch information
jacquesqiao authored Feb 28, 2018
2 parents f9c1b6f + c4996fb commit be9a2b2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
3 changes: 3 additions & 0 deletions python/paddle/fluid/backward.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,10 @@ def _callback_lookup_(op):
:return: callback function
"""
if op.type == 'parallel_do' and op.attr('use_nccl'):
all_vars = op.block.vars
param_names = set(op.input('parameters'))
param_names = filter(lambda name: all_vars[name].stop_gradient is False,
param_names)
param_grad_names = [n + "@GRAD" for n in param_names]

class ParallelDoCallBack(object):
Expand Down
1 change: 1 addition & 0 deletions python/paddle/fluid/tests/unittests/test_parallel_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ def __network__():
x = fluid.layers.data(shape=[784], dtype='float32', name='img')
x = yield x
hidden = fluid.layers.fc(input=x, size=200, param_attr='fc1.w')
hidden = fluid.layers.batch_norm(input=hidden)
loss = fluid.layers.mean(hidden)
yield loss

Expand Down

0 comments on commit be9a2b2

Please sign in to comment.