Skip to content

Commit dc6442b

Browse files
authored
Merge pull request #9158 from jacquesqiao/fix-regularization-when-parallel
fix regularizer when gradient is None
2 parents 60314ee + 2f17788 commit dc6442b

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

python/paddle/fluid/regularizer.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,20 @@ def append_regularization_ops(parameters_and_grads, regularization=None):
4444
"""
4545
params_and_grads = []
4646
for param, grad in parameters_and_grads:
47+
# If no gradient then we don't need to do anything
48+
if grad is None:
49+
params_and_grads.append((param, grad))
50+
continue
51+
4752
regularization_term = None
4853
if param.regularizer is not None:
4954
# Add variable for regularization term in grad block
5055
regularization_term = param.regularizer(param, grad, grad.block)
5156
elif regularization is not None:
5257
regularization_term = regularization(param, grad, grad.block)
5358

54-
# If no gradient or no regularization specified,
55-
# then we don't need to do anything
56-
if grad is None or regularization_term is None:
59+
# If no regularization specified, then we don't need to do anything
60+
if regularization_term is None:
5761
params_and_grads.append((param, grad))
5862
continue
5963

0 commit comments

Comments
 (0)