code: def _static_range_quantize(
      src_saved_model_path: str,
      dst_saved_model_path: str,
      quantization_options: _QuantizationOptions,
      representative_dataset: Optional[
          repr_dataset.RepresentativeDatasetOrMapping
      ] = None,
  ) -> autotrackable.AutoTrackable:
      """Quantizes the given SavedModel via static range quantization.
  
      If the model is not trained with Quantization-Aware Training (QAT) technique,
      it requires `representative_dataset` to collect statistics required for
      quantization. If non-None `representative_dataset` is provided with a QAT
      model input, `representative_dataset` will be ignored.
  
      Args:
        src_saved_model_path: Path to the saved model. When representative_dataset
          is not provided, this should be a model trained with QAT.
        dst_saved_model_path: The path to save the output SavedModel. The directory
          will be overwritten if not empty.
        quantization_options: QuantizationOptions proto describing quantization
          related config.
        representative_dataset: a generator that returns a dictionary in {input_key:
          input_value} format or a tuple with signature key and a dictionary in
          {input_key: input_value} format that feeds calibration data for quantizing
          model. This should be provided when the model is not a QAT model.
  
      Returns:
        A SavedModel object with TF quantization applied.
  
      Raises:
        ValueError: when representative_dataset is not provided for non-QAT model.
        RuntimeError: When a MetaGraphDef could not be found associated with `tags`
          in the SavedModel.
      """
      logging.info(
          "Running static range quantization on model: %s",
          src_saved_model_path,
      )
      logging.info("QuantizationOptions: \n%s", quantization_options)
  
      is_qat_saved_model_or_method_no_quantize = _is_qat_saved_model(
          src_saved_model_path
      ) or (
          quantization_options.quantization_method.preset_method
          == _QuantizationMethod.METHOD_NO_QUANTIZE
      )
      signature_def_map = save_model.get_signatures_from_saved_model(
          src_saved_model_path,
          quantization_options.signature_keys,
          set(quantization_options.tags),
      )
  
      # Checks if the model is from QAT or method is METHOD_NO_QUANTIZE.
      if (
          representative_dataset is None
          and not is_qat_saved_model_or_method_no_quantize
      ):
          raise ValueError(
              "When `representative_dataset` is not provided, the model should be "
              "trained with quantization-aware training (QAT)."
          )
      if quantization_options.min_num_elements_for_weights > 0:
          logging.warn(
              "min_num_elements_for_weights is set but is not supported for the "
              "Post-training static range quantization. "
              "The flag is ignored."
          )
  
      if is_qat_saved_model_or_method_no_quantize:
          _run_static_range_qat(
              src_saved_model_path,
              dst_saved_model_path,
              quantization_options,
              signature_def_map,
          )
      else:
          _run_static_range_ptq(
              src_saved_model_path,
              dst_saved_model_path,
              quantization_options,
              representative_dataset,
              signature_def_map,
          )
  
      return saved_model_load.load(dst_saved_model_path)
  
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 5 for calling a global function with example usage: _static_range_quantize(src_saved_model_path, dst_saved_model_path, quantization_options, representative_dataset) and returns: saved_model_load