提交 2f177886 编写于 作者: Q qiaolongfei

fix regularizer when gradient is None

上级 60314ee9
...@@ -44,6 +44,11 @@ def append_regularization_ops(parameters_and_grads, regularization=None): ...@@ -44,6 +44,11 @@ def append_regularization_ops(parameters_and_grads, regularization=None):
""" """
params_and_grads = [] params_and_grads = []
for param, grad in parameters_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 regularization_term = None
if param.regularizer is not None: if param.regularizer is not None:
# Add variable for regularization term in grad block # Add variable for regularization term in grad block
...@@ -51,9 +56,8 @@ def append_regularization_ops(parameters_and_grads, regularization=None): ...@@ -51,9 +56,8 @@ def append_regularization_ops(parameters_and_grads, regularization=None):
elif regularization is not None: elif regularization is not None:
regularization_term = regularization(param, grad, grad.block) regularization_term = regularization(param, grad, grad.block)
# If no gradient or no regularization specified, # If no regularization specified, then we don't need to do anything
# then we don't need to do anything if regularization_term is None:
if grad is None or regularization_term is None:
params_and_grads.append((param, grad)) params_and_grads.append((param, grad))
continue continue
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册