From 2f1778868efd93773db7f7bbfb0488e9895e97d3 Mon Sep 17 00:00:00 2001 From: qiaolongfei Date: Fri, 16 Mar 2018 15:23:08 +0800 Subject: [PATCH] fix regularizer when gradient is None --- python/paddle/fluid/regularizer.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/python/paddle/fluid/regularizer.py b/python/paddle/fluid/regularizer.py index 029db7d2d..604c6f9ab 100644 --- a/python/paddle/fluid/regularizer.py +++ b/python/paddle/fluid/regularizer.py @@ -44,6 +44,11 @@ def append_regularization_ops(parameters_and_grads, regularization=None): """ params_and_grads = [] for param, grad in parameters_and_grads: + # If no gradient then we don't need to do anything + if grad is None: + params_and_grads.append((param, grad)) + continue + regularization_term = None if param.regularizer is not None: # Add variable for regularization term in grad block @@ -51,9 +56,8 @@ def append_regularization_ops(parameters_and_grads, regularization=None): elif regularization is not None: regularization_term = regularization(param, grad, grad.block) - # If no gradient or no regularization specified, - # then we don't need to do anything - if grad is None or regularization_term is None: + # If no regularization specified, then we don't need to do anything + if regularization_term is None: params_and_grads.append((param, grad)) continue -- GitLab