|
|
|
|
@ -1243,7 +1243,8 @@ def append_backward(loss,
|
|
|
|
|
p_g_list6 = fluid.backward.append_backward(loss=avg_loss, parameter_list=all_weights, no_grad_set=set(all_weights))
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
assert isinstance(loss, framework.Variable)
|
|
|
|
|
check_type(loss, 'loss', framework.Variable,
|
|
|
|
|
'fluid.backward.append_backward')
|
|
|
|
|
|
|
|
|
|
if loss.op is None:
|
|
|
|
|
# the loss is from a cloned program. Find loss op manually.
|
|
|
|
|
@ -1254,7 +1255,8 @@ def append_backward(loss,
|
|
|
|
|
int(core.op_proto_and_checker_maker.OpRole.Loss))
|
|
|
|
|
|
|
|
|
|
if callbacks is not None:
|
|
|
|
|
isinstance(callbacks, list)
|
|
|
|
|
check_type(callbacks, 'callbacks', list,
|
|
|
|
|
'fluid.backward.append_backward')
|
|
|
|
|
|
|
|
|
|
program = loss.block.program
|
|
|
|
|
root_block = program.block(0)
|
|
|
|
|
@ -1370,20 +1372,17 @@ def append_backward(loss,
|
|
|
|
|
program._sync_with_cpp()
|
|
|
|
|
|
|
|
|
|
if parameter_list is not None:
|
|
|
|
|
if not isinstance(parameter_list, (list, tuple, set)):
|
|
|
|
|
raise TypeError(
|
|
|
|
|
"The type of parameter_list argument must be list or tuple or set, but received %s."
|
|
|
|
|
% (type(parameter_list)))
|
|
|
|
|
check_type(parameter_list, 'parameter_list', (list, tuple, set),
|
|
|
|
|
'fluid.backward.append_backward')
|
|
|
|
|
parameters = []
|
|
|
|
|
for i, param in enumerate(parameter_list):
|
|
|
|
|
check_type(param, 'parameter_list[%s]' % i, (framework.Variable,
|
|
|
|
|
six.string_types),
|
|
|
|
|
'fluid.backward.append_backward')
|
|
|
|
|
if isinstance(param, framework.Variable):
|
|
|
|
|
parameters.append(param.name)
|
|
|
|
|
elif isinstance(param, six.string_types):
|
|
|
|
|
parameters.append(param)
|
|
|
|
|
else:
|
|
|
|
|
raise TypeError(
|
|
|
|
|
"The type of parameter_list's member must be paddle.fluid.Variable or str, but received %s."
|
|
|
|
|
% (type(param)))
|
|
|
|
|
else:
|
|
|
|
|
params = program.global_block().all_parameters()
|
|
|
|
|
parameters = [param.name for param in params if param.trainable]
|
|
|
|
|
@ -1716,8 +1715,6 @@ def gradients(targets, inputs, target_gradients=None, no_grad_set=None):
|
|
|
|
|
'fluid.backward.gradients')
|
|
|
|
|
check_type(target_gradients, 'target_gradients', (
|
|
|
|
|
framework.Variable, list, type(None)), 'fluid.backward.gradients')
|
|
|
|
|
check_type(no_grad_set, 'no_grad_set', (set, type(None)),
|
|
|
|
|
'fluid.backward.gradients')
|
|
|
|
|
|
|
|
|
|
outs = calc_gradient(targets, inputs, target_gradients, no_grad_set)
|
|
|
|
|
return _as_list(outs)
|
|
|
|
|
|