code: def quantize(
      saved_model_path: str,
      output_directory: Optional[str] = None,
      quantization_options: Optional[_QuantizationOptions] = None,
      representative_dataset: Optional[
          repr_dataset.RepresentativeDatasetOrMapping
      ] = None,
      *,
      overwrite_output_directory: bool = False,
  ) -> autotrackable.AutoTrackable:
      """Quantizes the SavedModel with the given quantization options.
  
      Example usage:
      ```python
      # Quantizing a model trained with QAT.
      quantization_options = tf.quantization.experimental.QuantizationOptions(
          signature_keys=['your_signature_key'],
      )
      tf.quantization.experimental.quantize_saved_model(
          '/tmp/input_model',
          '/tmp/output_model',
          quantization_options=quantization_options,
      )
  
      # When quantizing a model trained without QAT (Post-Training Quantization),
      # a representative dataset is required.
      representative_dataset = [{"input": tf.random.uniform(shape=(3, 3))}
                            for _ in range(256)]
      tf.quantization.experimental.quantize_saved_model(
          '/tmp/input_model',
          '/tmp/output_model',
          quantization_options=quantization_options,
          representative_dataset={'your_signature_key': representative_dataset},
        )
  
      # In addition to preset quantization methods, fine-grained control of
      # quantization for each component is also supported.
      _QuantizationComponentSpec = (
          tf.quantization.experimental.QuantizationComponentSpec
      )
      quantization_options = tf.quantization.experimental.QuantizationOptions(
          signature_keys=['your_signature_key'],
          quantization_method=tf.quantization.experimental.QuantizationMethod(
              quantization_component_specs=[
                  _QuantizationComponentSpec(
                      quantization_component=(
                          _QuantizationComponentSpec.COMPONENT_ACTIVATION
                      ),
                      tensor_type=_QuantizationComponentSpec.TENSORTYPE_INT_8,
                  )
              ]
          )
      )
      tf.quantization.experimental.quantize_saved_model(
          '/tmp/input_model',
          '/tmp/output_model',
          quantization_options=quantization_options,
      )
      ```
  
      Args:
        saved_model_path: Path to the saved model. When representative_dataset is
          not provided, this should be a model trained with QAT.
        output_directory: The path to save the output SavedModel. Set
          `overwrite_output_directory` to `True` to overwrite any existing contents
          in the directory if not empty.
        quantization_options: A set of options for quantization. If None, it uses
          post-training static range quantization with XLA opset by default.
        representative_dataset: an iterator that returns a dictionary of {input_key:
          input_value} or a map from signature key to a dictionary of {input_key:
          input_value} that feeds calibration data for quantizing model. The
          representative should be provided when the model is a PTQ model. It can be
          provided either via this parameter or via the `representative_datasets`
          field in `QuantizationOptions`.
        overwrite_output_directory: If set to true, overwrites the output directory
          iff it isn't empty. The default value is false.
  
      Returns:
        A SavedModel object with TF quantization applied, or None if no quantization
        is performed.
  
      Raises:
        ValueError: When 1) representative_dataset is not provided for non QAT model
          for enabling static range quantization, 2) invalid value is provided as
          a quantization method, or 3) provide representative dataset via both
          argument and QuantizationOptions.
        ValueError: When the specified quantization method is not yet supported.
      """
      _verify_output_dir(output_directory, overwrite_output_directory)
  
      # Set default values for None arguments.
      if output_directory is None:
          output_directory = tempfile.mkdtemp()
  
      if quantization_options is None:
          quantization_options = _QuantizationOptions()
  
      _populate_quantization_options_default_values(
          quantization_options
      )
  
      if (
          representative_dataset is not None
          and quantization_options.representative_datasets
      ):
          raise ValueError(
              "Do not specify both the `representative_dataset` argument and"
              " the `representative_datasets` field in `QuantizationOptions`."
          )
  
      if quantization_options.representative_datasets:
          representative_dataset = (
              repr_dataset.RepresentativeDatasetLoader(
                  quantization_options.representative_datasets
              ).load()
          )
  
      method: _QuantizationMethod = (
          quantization_options.quantization_method
      )
      if (
          method.preset_method == _PresetMethod.METHOD_STATIC_RANGE_INT8
          or method.preset_method == _PresetMethod.METHOD_NO_QUANTIZE
      ):
          return _static_range_quantize(
              saved_model_path,
              output_directory,
              quantization_options,
              representative_dataset,
          )
      elif (
          method.preset_method
          == _PresetMethod.METHOD_DYNAMIC_RANGE_INT8
      ):
          return _dynamic_range_quantize(
              saved_model_path,
              output_directory,
              quantization_options,
          )
      elif (
          method.preset_method
          == _PresetMethod.METHOD_STATIC_RANGE_WEIGHT_ONLY_INT8
      ):
          return _weight_only_quantize(
              saved_model_path,
              output_directory,
              quantization_options,
          )
      else:
          raise ValueError(
              "Quantization method {method.preset_method} is not supported."
          )
  
imports: import tempfile
  from typing import Mapping, Optional
  from absl import logging
  from tensorflow.compiler.mlir.quantization.tensorflow import quantization_options_pb2
  from tensorflow.compiler.mlir.quantization.tensorflow.python import py_function_lib
  from tensorflow.compiler.mlir.quantization.tensorflow.python import pywrap_quantize_model
  from tensorflow.compiler.mlir.quantization.tensorflow.python import representative_dataset
  from tensorflow.compiler.mlir.quantization.tensorflow.python import save_model
  from tensorflow.core.protobuf import meta_graph_pb2
  from tensorflow.python.lib.io import file_io
  from tensorflow.python.saved_model import load
  from tensorflow.python.saved_model import loader_impl
  from tensorflow.python.saved_model import signature_constants
  from tensorflow.python.saved_model import tag_constants
  from tensorflow.python.trackable import autotrackable
  from tensorflow.python.util import tf_export
label_desc: Use image node_id 13 for calling a global function with example usage: quantize(saved_model_path, output_directory, quantization_options, representative_dataset) and returns: _static_range_quantize, _dynamic_range_quantize, _weight_only_quantize