code: def testLogProbGrads(self):
      # probs = [1/2, 1, 0].
      logits = tf.constant([0.0, np.inf, -np.inf], dtype=tf.float32)
      _, grad = gradient.value_and_gradient(
          lambda x: -bernoulli.Bernoulli(logits=x).log_prob(
              [1.0, 1.0, 0.0]
          ),
          logits,
      )
  
      # For finite logits, the grad is as expected (finite...to get value do math)
      # For infinite logits, you can reason that a small perturbation of the
      # logits doesn't change anything (adding epsilon to +-Inf doesn't change
      # it), and thus gradient = 0 is expected.
      self.assertAllEqual(grad, [-0.5, 0.0, 0.0])
  
imports: import numpy
  from scipy import special
  import tensorflow.compat.v1
  import tensorflow.compat.v2
  from tensorflow_probability.python.distributions import bernoulli
  from tensorflow_probability.python.distributions import kullback_leibler
  from tensorflow_probability.python.internal import samplers
  from tensorflow_probability.python.internal import tensorshape_util
  from tensorflow_probability.python.internal import test_util
  from tensorflow_probability.python.math import gradient
label_desc: Use image node_id 29 for calling the BernoulliTest obj's underlying member method code with example usage: obj.testLogProbGrads() without return types