MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / _FusedBatchNormGradGrad

Function _FusedBatchNormGradGrad

tensorflow/python/ops/nn_grad.py:1038–1072  ·  view source on GitHub ↗

Returns the gradients for the 3 inputs of FusedBatchNormGrad. Args: op: The FusedBatchNormGradOp for which we need to compute gradients. *grad: An argument list for tensors of gradients wrt the outputs with grad[0] as grad_grad_x, grad[1] as grad_grad_scale, grad[2] as grad_gr

(op, *grad)

Source from the content-addressed store, hash-verified

1036
1037@ops.RegisterGradient("FusedBatchNormGrad")
1038def _FusedBatchNormGradGrad(op, *grad):
1039 """Returns the gradients for the 3 inputs of FusedBatchNormGrad.
1040
1041 Args:
1042 op: The FusedBatchNormGradOp for which we need to compute gradients.
1043 *grad: An argument list for tensors of gradients wrt the outputs with
1044 grad[0] as grad_grad_x, grad[1] as grad_grad_scale, grad[2] as
1045 grad_grad_offset.
1046
1047 Returns:
1048 A tuple (grad_grad_y, grad_x, grad_scale, None, None), where grad_grad_y
1049 is the gradient for grad_y, grad_x the gradient for x, grad_scale the
1050 gradient for scale.
1051 """
1052 data_format = op.get_attr("data_format")
1053 epsilon = op.get_attr("epsilon")
1054 is_training = op.get_attr("is_training")
1055 grad_y = op.inputs[0]
1056 x = op.inputs[1]
1057 scale = op.inputs[2]
1058 pop_mean = op.inputs[3]
1059 pop_var = op.inputs[4]
1060 grad_grad_x = grad[0]
1061 grad_grad_scale = grad[1]
1062 grad_grad_offset = grad[2]
1063 with backprop.GradientTape() as tape:
1064 tape.watch(grad_y)
1065 tape.watch(x)
1066 tape.watch(scale)
1067 grad_x, grad_scale, grad_offset = _BatchNormGrad(
1068 grad_y, x, scale, pop_mean, pop_var, epsilon, data_format, is_training)
1069 grad_initial = [grad_grad_x, grad_grad_scale, grad_grad_offset]
1070 grad_grad_y, grad_x, grad_scale = tape.gradient(
1071 [grad_x, grad_scale, grad_offset], [grad_y, x, scale], grad_initial)
1072 return grad_grad_y, grad_x, grad_scale, None, None
1073
1074
1075@ops.RegisterGradient("FusedBatchNormGradV2")

Callers 2

Calls 5

_BatchNormGradFunction · 0.85
gradientMethod · 0.80
get_attrMethod · 0.45
GradientTapeMethod · 0.45
watchMethod · 0.45

Tested by

no test coverage detected