docstr: Tests the gradient of nccl_reduce.
  
  Args:
    nccl_reduce: A function taking a list of tensors and a list of devices,
        and returns a list of reduced tensors and a list of ops to perform the
        reduction.
    numpy_fn: A function taking two tensors and returning the gradient of the
        reduction of the two.
docstr_tok: ["Tests","the","gradient","of","nccl_reduce",".","Args",":","nccl_reduce",":","A","function","taking","a","list","of","tensors","and","a","list","of","devices",",","and","returns","a","list","of","reduced","tensors","and","a","list","of","ops","to","perform","the","reduction",".","numpy_fn",":","A","function","taking","two","tensors","and","returning","the","gradient","of","the","reduction","of","the","two","."]
code: def _TestGradient(self, nccl_reduce, numpy_fn):
      """Tests the gradient of nccl_reduce.
  
      Args:
        nccl_reduce: A function taking a list of tensors and a list of devices,
            and returns a list of reduced tensors and a list of ops to perform the
            reduction.
        numpy_fn: A function taking two tensors and returning the gradient of the
            reduction of the two.
      """
  
      def _Gradient(tensors, devices):
          inputs = [
              array_ops.placeholder(t.dtype, t.shape) for t in tensors
          ]
          reduce_tensors = nccl_reduce(inputs, devices)
          losses = _DeviceTensors(
              tensors, [t.device for t in reduce_tensors]
          )
          grads = gradients.gradients(
              reduce_tensors,
              inputs,
              losses,
              colocate_gradients_with_ops=True,
          )
          return [g for g in grads if g is not None]
  
      self._Test(_Gradient, numpy_fn)
  
imports: from functools import partial
  import numpy
  from tensorflow.python.framework import errors
  from tensorflow.python.framework import ops
  from tensorflow.python.ops import array_ops
  from tensorflow.python.ops import gradients
  from tensorflow.python.ops import nccl_ops
  from tensorflow.python.platform import test
label_desc: Use image node_id 2 for calling the NcclTestCase obj's underlying member method code with example usage: obj._TestGradient(nccl_reduce, numpy_fn) and returns: unknown