code: def convert_saved_model(
      saved_model_dir: Union[str, os.PathLike],
      *,  # Require remaining arguments to be keyword-only.
      inference_input_type: tf.DType = tf.float32,
      inference_output_type: tf.DType = tf.float32,
      target: str = "arm",
      experimental_default_int8_range: Optional[
          tuple[float, float]
      ] = None,
  ) -> bytes:
      """Converts a SavedModel to TFLite flatbuffer.
  
      !!! example
          ```python
          tflite_model = convert_saved_model(saved_model_dir)
          with open("/tmp/my_model.tflite", "wb") as f:
              f.write(tflite_model)
          ```
  
      # Arguments
          saved_model_dir: SavedModel directory to convert.
          inference_input_type: Data type of the input layer. Defaults to `tf.float32`,
              must be either `tf.float32` or `tf.int8`.
          inference_output_type: Data type of the output layer. Defaults to `tf.float32`,
              must be either `tf.float32` or `tf.int8`.
          target: Target hardware platform. Defaults to "arm", must be either "arm"
              or "xcore".
          experimental_default_int8_range: Tuple of integers representing `(min, max)`
              range values for all arrays without a specified range. Intended for
              experimenting with quantization via "dummy quantization". (default None)
  
      # Returns
          The converted data in serialized format.
      """
      _validate_options(
          inference_input_type=inference_input_type,
          inference_output_type=inference_output_type,
          target=target,
          experimental_default_int8_range=experimental_default_int8_range,
      )
  
      saved_model_dir = str(saved_model_dir)
      saved_model_tags = [tf.saved_model.SERVING]
      saved_model_exported_names = [
          tf.saved_model.DEFAULT_SERVING_SIGNATURE_DEF_KEY
      ]
  
      from tensorflow.python.saved_model import loader_impl
  
      saved_model_pb, _ = loader_impl.parse_saved_model_with_debug_info(
          saved_model_dir
      )
  
      saved_model_version = saved_model_pb.saved_model_schema_version
      if saved_model_version not in (1, 2):
          raise ValueError(
              f"SavedModel file format({saved_model_version}) is not supported"
          )
  
      tflite_buffer = convert_saved_model_to_tflite_flatbuffer(
          saved_model_dir,
          saved_model_tags,
          saved_model_exported_names,
          saved_model_version,
          target,
          experimental_default_int8_range,
      )
  
      if (
          inference_input_type != tf.float32
          or inference_output_type != tf.float32
      ):
          tflite_buffer = modify_integer_quantized_model_io_type(
              tflite_buffer,
              inference_input_type=inference_input_type,
              inference_output_type=inference_output_type,
          )
  
      return tflite_buffer
  
file_path: compute-engine/larq_compute_engine/mlir/python/converter.py
imports: import os
  import warnings
  from typing import Optional, Union
  import tensorflow
  import tempfile
  from larq_compute_engine.mlir._tf_tfl_flatbuffer import convert_graphdef_to_tflite_flatbuffer, convert_saved_model_to_tflite_flatbuffer
  from larq_compute_engine.mlir.python.util import modify_integer_quantized_model_io_type
  from tensorflow.core.framework.types_pb2 import DataType
  from tensorflow.lite.python.util import get_tensor_name
  from tensorflow.python.eager import def_function
  from tensorflow.python.framework.convert_to_constants import convert_variables_to_constants_v2
  from tensorflow.python.keras.saving import saving_utils
label_desc: Use image node_id 4 for calling a global function with example usage: convert_saved_model(saved_model_dir) and returns: tflite_buffer