code: def _random_gamma_bwd(shape, log_space, aux, g):
      """The gradient of the gamma samples."""
      samples, concentration, rate, log_rate = aux
      dsamples, dimpl = g
      # Ignore any gradient contributions that come from the implementation enum.
      del dimpl
      (
          partial_concentration,
          partial_rate,
          partial_log_rate,
      ) = _compute_partials(
          samples, concentration, rate, log_rate, log_space
      )
  
      # These will need to be shifted by the extra dimensions added from
      # `sample_shape`.
      rate_shape = _shape_or_scalar(rate, log_rate)
      reduce_dims = tf.range(
          tf.size(shape)
          - tf.maximum(tf.rank(concentration), tf.size(rate_shape))
      )
      grad_concentration = tf.math.reduce_sum(
          dsamples * partial_concentration, axis=reduce_dims
      )
      grad_log_rate = None
      grad_rate = None
      if rate is not None:
          grad_rate = tf.math.reduce_sum(
              dsamples * partial_rate, axis=reduce_dims
          )
      elif log_rate is not None:
          grad_log_rate = tf.math.reduce_sum(
              dsamples * partial_log_rate, axis=reduce_dims
          )
  
      rate_tensorshape = _tensorshape_or_scalar(rate, log_rate)
      if (
          tensorshape_util.is_fully_defined(concentration.shape)
          and tensorshape_util.is_fully_defined(rate_tensorshape)
          and concentration.shape == rate_tensorshape
      ):
          return (
              grad_concentration,
              grad_rate,
              grad_log_rate,
              None,
          )  # seed=None
  
      # Dummy parameter used for fix_gradient_for_broadcasting.
      rate_param = tf.ones_like(concentration)
      grad_rate_param = rate_param
      if rate is not None:
          rate_param = rate
          grad_rate_param = grad_rate
      if log_rate is not None:
          rate_param = log_rate
          grad_rate_param = grad_log_rate
  
      (
          grad_concentration,
          grad_rate_param,
      ) = generic.fix_gradient_for_broadcasting(
          [concentration, rate_param],
          [grad_concentration, grad_rate_param],
      )
  
      if grad_rate is not None:
          grad_rate = grad_rate_param
      if grad_log_rate is not None:
          grad_log_rate = grad_rate_param
  
      return grad_concentration, grad_rate, grad_log_rate, None
  
imports: import numpy
  import tensorflow.compat.v2
  from tensorflow_probability.python.bijectors import softplus
  from tensorflow_probability.python.distributions import distribution
  from tensorflow_probability.python.distributions import kullback_leibler
  from tensorflow_probability.python.internal import assert_util
  from tensorflow_probability.python.internal import batched_rejection_sampler
  from tensorflow_probability.python.internal import custom_gradient
  from tensorflow_probability.python.internal import distribution_util
  from tensorflow_probability.python.internal import dtype_util
  from tensorflow_probability.python.internal import implementation_selection
  from tensorflow_probability.python.internal import parameter_properties
  from tensorflow_probability.python.internal import prefer_static
  from tensorflow_probability.python.internal import reparameterization
  from tensorflow_probability.python.internal import samplers
  from tensorflow_probability.python.internal import tensor_util
  from tensorflow_probability.python.internal import tensorshape_util
  from tensorflow_probability.python.math import generic
  from tensorflow_probability.python.math import special
  from tensorflow_probability.python.util.deferred_tensor import DeferredTensor
label_desc: Use image node_id 9 for calling a global function with example usage: _random_gamma_bwd(shape, log_space, aux, g) and returns: grad_concentration,  grad_rate,  grad_log_rate,  None, grad_concentration,  grad_rate,  grad_log_rate,  None