class_docstr: Encoding stage performing uniform quantization.
  
  This class performs quantization to uniformly spaced values, without realizing
  any savings by itself.
  
  In particular, given a floating point input `x` to the `encode` method, the
  output will have the same `dtype` as `x`, with values being "floating point
  integers" in the range `[0, 2**bits-1]`.
  
  If `min_max` is not provided, the extreme points of the quantized interval
  will correspond to the min and max values of the input `x`. If `min_max` is
  provided, the input `x` is first clipped to this range, and the extreme points
  of the quantized interval correspond to the provided `min_max` values.
class_docstr_tok: ["Encoding","stage","performing","uniform","quantization",".","This","class","performs","quantization","to","uniformly","spaced","values",",","without","realizing","any","savings","by","itself",".","In","particular",",","given","a","floating","point","input","`","x","`","to","the","`","encode","`","method",",","the","output","will","have","the","same","`","dtype","`","as","`","x","`",",","with","values","being","``","floating","point","integers","''","in","the","range","`","[","0",",","2","*","*","bits-1","]","`",".","If","`","min_max","`","is","not","provided",",","the","extreme","points","of","the","quantized","interval","will","correspond","to","the","min","and","max","values","of","the","input","`","x","`",".","If","`","min_max","`","is","provided",",","the","input","`","x","`","is","first","clipped","to","this","range",",","and","the","extreme","points","of","the","quantized","interval","correspond","to","the","provided","`","min_max","`","values","."]
docstr: See base class.
code: def encode(self, x, encode_params):
      """See base class."""
      if self.MIN_MAX_VALUES_KEY in encode_params:
          min_max = tf.cast(
              encode_params[self.MIN_MAX_VALUES_KEY], x.dtype
          )
          min_x, max_x = min_max[0], min_max[1]
          x = tf.clip_by_value(x, min_x, max_x)
      else:
          min_x = tf.reduce_min(x)
          max_x = tf.reduce_max(x)
  
      max_value = tf.cast(
          encode_params[self.MAX_INT_VALUE_PARAMS_KEY], x.dtype
      )
      # Shift the values to range [0, max_value].
      # In the case of min_x == max_x, this will return all zeros.
      x = tf.compat.v1.div_no_nan(x - min_x, max_x - min_x) * max_value
      if self._stochastic:  # Randomized rounding.
          floored_x = tf.floor(x)
          residuals_x = x - floored_x
          # Add graph dependencies to tensor `x` to ensure that the randomized
          # rounding variables are not created before `x` is scaled above. This
          # prevents TF from preallocating the tensor before it will actually be
          # used, reducing memory pressure (especially important for mobile
          # deployments).
          if self._force_random_op_after_clipping:
              with tf.control_dependencies([x]):
                  bernoulli = tf.random.uniform(
                      tf.shape(x), dtype=x.dtype
                  )
          else:
              bernoulli = tf.random.uniform(tf.shape(x), dtype=x.dtype)
          bernoulli = bernoulli < residuals_x
          quantized_x = floored_x + tf.cast(bernoulli, x.dtype)
      else:  # Deterministic rounding.
          quantized_x = tf.round(x)
  
      encoded_tensors = collections.OrderedDict(
          [(self.ENCODED_VALUES_KEY, quantized_x)]
      )
      if self.MIN_MAX_VALUES_KEY not in encode_params:
          encoded_tensors[self.MIN_MAX_VALUES_KEY] = tf.stack(
              [min_x, max_x]
          )
      return encoded_tensors
  
imports: import collections
  import numpy
  import tensorflow
  from tensorflow_model_optimization.python.core.internal.tensor_encoding.core import encoding_stage
  from tensorflow_model_optimization.python.core.internal.tensor_encoding.utils import tf_utils
label_desc: Use image node_id 7 for calling the UniformQuantizationEncodingStage obj's underlying member method code with example usage: obj.encode(x, encode_params) and returns: encoded_tensors