code: def testKernelGradient(self, kernel_name, data):
      event_dim = data.draw(hps.integers(min_value=2, max_value=3))
      feature_ndims = data.draw(hps.integers(min_value=0, max_value=2))
      feature_dim = data.draw(hps.integers(min_value=2, max_value=4))
      batch_shape = data.draw(tfp_hps.shapes(max_ndims=2))
  
      kernel, kernel_parameter_variable_names = data.draw(
          kernel_hps.kernels(
              batch_shape=batch_shape,
              kernel_name=kernel_name,
              event_dim=event_dim,
              feature_dim=feature_dim,
              feature_ndims=feature_ndims,
              enable_vars=True,
          )
      )
  
      # Check that variable parameters get passed to the kernel.variables
      kernel_variables_names = [
          v.name.strip("_0123456789:") for v in kernel.variables
      ]
      kernel_parameter_variable_names = [
          n.strip("_0123456789:")
          for n in kernel_parameter_variable_names
      ]
      self.assertEqual(
          set(kernel_parameter_variable_names),
          set(kernel_variables_names),
      )
  
      example_ndims = data.draw(hps.integers(min_value=1, max_value=2))
      input_batch_shape = data.draw(
          tfp_hps.broadcast_compatible_shape(kernel.batch_shape)
      )
      xs = tf.identity(
          data.draw(
              kernel_hps.kernel_input(
                  batch_shape=input_batch_shape,
                  example_ndims=example_ndims,
                  feature_dim=feature_dim,
                  feature_ndims=feature_ndims,
              )
          )
      )
  
      # Check that we pick up all relevant kernel parameters.
      wrt_vars = [xs] + list(kernel.variables)
      self.evaluate([v.initializer for v in kernel.variables])
  
      max_permissible = 2 + EXTRA_TENSOR_CONVERSION_KERNELS.get(
          kernel_name, 0
      )
  
      with tf.GradientTape() as tape:
          with tfp_hps.assert_no_excessive_var_usage(
              "method `apply` of {}".format(kernel),
              max_permissible=max_permissible,
          ):
              tape.watch(wrt_vars)
              with tfp_hps.no_tf_rank_errors():
                  diag = kernel.apply(
                      xs, xs, example_ndims=example_ndims
                  )
      grads = tape.gradient(diag, wrt_vars)
      assert_no_none_grad(kernel, "apply", wrt_vars, grads)
  
      # Check that copying the kernel works.
      with tfp_hps.no_tf_rank_errors():
          diag2 = self.evaluate(
              kernel.copy().apply(xs, xs, example_ndims=example_ndims)
          )
      self.assertAllClose(diag, diag2)
  
file_path: probability/tensorflow_probability/python/math/psd_kernels/psd_kernel_properties_test.py
imports: import collections
  from absl.testing import parameterized
  import hypothesis
  from hypothesis import strategies
  import numpy
  import tensorflow.compat.v2
  from tensorflow_probability.python.internal import hypothesis_testlib
  from tensorflow_probability.python.internal import tensor_util
  from tensorflow_probability.python.internal import test_util
  from tensorflow_probability.python.math.psd_kernels import hypothesis_testlib
label_desc: Use image node_id 1 for calling the KernelPropertiesTest obj's underlying member method code with example usage: obj.testKernelGradient(kernel_name, data) without return types