code: def _quantize(x, params, randomize=True):
      """Quantize x according to params, optionally randomizing the rounding."""
      if not params.quantize:
          return x
  
      if not randomize:
          return tf.bitcast(
              tf.cast(x / params.quantization_scale, tf.int16),
              tf.float16,
          )
  
      abs_x = tf.abs(x)
      sign_x = tf.sign(x)
      y = abs_x / params.quantization_scale
      y = tf.floor(y + tf.random_uniform(common_layers.shape_list(x)))
      y = tf.minimum(y, tf.int16.max) * sign_x
      q = tf.bitcast(tf.cast(y, tf.int16), tf.float16)
      return q
  
imports: from collections import defaultdict
  import copy
  import math
  from tensor2tensor.layers import common_layers
  from tensor2tensor.utils import hparam
  import tensorflow.compat.v1
label_desc: Use image node_id 4 for calling a global function with example usage: _quantize(x, params, randomize) and returns: q, x, tf