code: def quantization_offset(distribution):
      """Computes distribution-dependent quantization offset.
  
      For range coding of continuous random variables, the values need to be
      quantized first. Typically, it is beneficial for compression performance to
      align the centers of the quantization bins such that one of them coincides
      with the mode of the distribution. With `offset` being the mode of the
      distribution, for instance, this can be achieved simply by computing:
      ```
      x_hat = tf.round(x - offset) + offset
      ```
  
      This method tries to determine the offset in a best-effort fashion, based on
      which statistics the `Distribution` implements. First, a method
      `self._quantization_offset()` is tried. If that isn't defined, it tries in
      turn: `self.mode()`, `self.quantile(.5)`, then `self.mean()`. If none of
      these are implemented, it falls back on quantizing to integer values (i.e.,
      an offset of zero).
  
      Note the offset is always in the range [-.5, .5] as it is assumed to be
      combined with a round quantizer.
  
      Args:
        distribution: A `tfp.distributions.Distribution` object.
  
      Returns:
        A `tf.Tensor` broadcastable to shape `self.batch_shape`, containing
        the determined quantization offsets. No gradients are allowed to flow
        through the return value.
      """
      try:
          offset = (
              distribution._quantization_offset()
          )  # pylint:disable=protected-access
      except (AttributeError, NotImplementedError):
          try:
              offset = distribution.mode()
          except NotImplementedError:
              try:
                  offset = distribution.quantile(0.5)
              except NotImplementedError:
                  try:
                      offset = distribution.mean()
                  except NotImplementedError:
                      offset = tf.constant(0, dtype=distribution.dtype)
      return tf.stop_gradient(offset - tf.round(offset))
  
imports: import tensorflow
label_desc: Use image node_id 2 for calling a global function with example usage: quantization_offset(distribution) and returns: tf