code: def _binomial_inversion(counts, probs, full_shape, seed):
      """Use multiple geometric samples to sample binomials with count*prob < 10."""
      # Binomial inversion. Given probs, sum geometric random variables until they
      # exceed counts. The number of random variables used is binomially
      # distributed. This is also known as binomial inversion, as this is equivalent
      # to inverting the Binomial CDF.
      seed = samplers.sanitize_seed(seed)
      zero_init = tf.zeros(full_shape, counts.dtype)
  
      def cond(keep_going, *_):
          return keep_going
  
      # If probs were 1 we would loop forever. :(
      # But probs is always <= 0.5 here, as guaranteed by the caller.
      log1minusprob = tf.math.log1p(-probs)
  
      def body(unused_keep_going, geom_sum, num_geom, seed):
          u_seed, next_seed = samplers.split_seed(seed)
          u = samplers.uniform(
              full_shape, seed=u_seed, dtype=counts.dtype
          )
          geom = tf.math.ceil(tf.math.log(u) / log1minusprob)
          geom_sum += geom
          keep_going = geom_sum <= counts
          num_geom = tf.where(keep_going, num_geom + 1, num_geom)
          return (
              tf.reduce_any(keep_going),
              geom_sum,
              num_geom,
              next_seed,
          )
  
      _, _, num_geom, _ = tf.while_loop(
          cond, body, (True, zero_init, zero_init, seed)
      )
      return num_geom
  
imports: import tensorflow.compat.v2
  from tensorflow_probability.python.bijectors import sigmoid
  from tensorflow_probability.python.distributions import distribution
  from tensorflow_probability.python.internal import assert_util
  from tensorflow_probability.python.internal import batched_rejection_sampler
  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 special
label_desc: Use image node_id 3 for calling a global function with example usage: _binomial_inversion(counts, probs, full_shape, seed) and returns: num_geom, keep_going, tf,  geom_sum,  num_geom,  next_seed