class_docstr: Tests for ops in horovod.tensorflow.
class_docstr_tok: ["Tests","for","ops","in","horovod.tensorflow","."]
docstr: Test the correctness of the allreduce gradient on XLA/GPU.
docstr_tok: ["Test","the","correctness","of","the","allreduce","gradient","on","XLA\/GPU","."]
code: def test_horovod_allreduce_grad_gpu(self):
      """Test the correctness of the allreduce gradient on XLA/GPU."""
      # Only do this test if there are GPUs available.
      if not tf.test.is_gpu_available(cuda_only=True):
          self.skipTest(("No GPUs available"))
  
      if int(os.environ.get("HOROVOD_MIXED_INSTALL", 0)):
          # Skip if compiled with CUDA but without HOROVOD_GPU_OPERATIONS.
          self.skipTest("Not compiled with HOROVOD_GPU_OPERATIONS")
  
      hvd.init()
      local_rank = hvd.local_rank()
      size = hvd.size()
  
      def allreduce_grad_test(self, dtype, dim):
          tensor = self.random_uniform(
              [5] * dim, -100, 100, dtype=dtype
          )
          summed = hvd.allreduce(tensor, average=False)
  
          grad_ys = tf.ones([5] * dim)
          grad = tf.gradients(summed, tensor, grad_ys)[0]
          return grad
  
      # As of TensorFlow v1.9, gradients are not supported on
      # integer tensors
      dtypes = [tf.float32, tf.float64]
      dims = [1, 2, 3]
      for dtype, dim in itertools.product(dtypes, dims):
          with tf.device("/gpu:%d" % local_rank):
              grad = tf.function(allreduce_grad_test, jit_compile=True)(
                  self, dtype, dim
              )
              grad_out = self.evaluate(grad)
          expected = np.ones([5] * dim) * size
          err = np.linalg.norm(expected - grad_out)
          self.assertLess(
              err,
              0.00000001,
              "gradient %s differs from expected %s, "
              "error: %s" % (grad_out, expected, str(err)),
          )
  
imports: import os
  import sys
  import pytest
  import math
  import numpy
  import itertools
  from packaging import version
  import warnings
  import tensorflow
  from horovod.tensorflow.util import _executing_eagerly
  from tensorflow.python.framework import ops
  import horovod.tensorflow
  from tensorflow.python.framework.test_util import run_all_in_graph_and_eager_modes
label_desc: Use image node_id 8 for calling the XLATests obj's underlying member method code with example usage: obj.test_horovod_allreduce_grad_gpu() and returns: grad