aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/python/kernel_tests/bias_op_test.py
diff options
context:
space:
mode:
Diffstat (limited to 'tensorflow/python/kernel_tests/bias_op_test.py')
-rw-r--r--tensorflow/python/kernel_tests/bias_op_test.py16
1 files changed, 14 insertions, 2 deletions
diff --git a/tensorflow/python/kernel_tests/bias_op_test.py b/tensorflow/python/kernel_tests/bias_op_test.py
index 87027c8a78..862948610d 100644
--- a/tensorflow/python/kernel_tests/bias_op_test.py
+++ b/tensorflow/python/kernel_tests/bias_op_test.py
@@ -128,7 +128,13 @@ class BiasAddTest(tf.test.TestCase):
input_tensor, np_input.shape, output_tensor, np_input.shape)
bias_jacob_t, bias_jacob_n = tf.test.compute_gradient(
bias_tensor, bias.shape, output_tensor, np_input.shape)
-
+
+ # Test gradient of BiasAddGrad
+ bias_add_grad = tf.gradients(tf.nn.l2_loss(output_tensor),
+ bias_tensor)[0]
+ grad_jacob_t, grad_jacob_n = tf.test.compute_gradient(
+ output_tensor, np_input.shape, bias_add_grad, bias.shape)
+
if dtype == np.float16:
# Compare fp16 theoretical gradients to fp32 numerical gradients,
# since fp16 numerical gradients are too imprecise unless great
@@ -144,12 +150,18 @@ class BiasAddTest(tf.test.TestCase):
input_tensor, np_input.shape, output_tensor, np_input.shape)
_, bias_jacob_n = tf.test.compute_gradient(
bias_tensor, bias.shape, output_tensor, np_input.shape)
-
+
+ bias_add_grad = tf.gradients(tf.nn.l2_loss(output_tensor),
+ bias_tensor)[0]
+ _, grad_jacob_n = tf.test.compute_gradient(
+ output_tensor, np_input.shape, bias_add_grad, bias.shape)
+
threshold = 2e-3
if dtype == tf.float64:
threshold = 1e-10
self.assertAllClose(tensor_jacob_t, tensor_jacob_n, threshold, threshold)
self.assertAllClose(bias_jacob_t, bias_jacob_n, threshold, threshold)
+ self.assertAllClose(grad_jacob_t, grad_jacob_n, threshold, threshold)
def testGradientTensor(self):
for (data_format, use_gpu) in GetTestConfigs():