code: def quantize(onnx_model_path: Path) -> Path:
      """
      Quantize the weights of the model from float32 to in8 to allow very efficient inference on modern CPU
  
      Args:
          onnx_model_path: Path to location the exported ONNX model is stored
  
      Returns: The Path generated for the quantized
      """
      import onnx
      import onnxruntime
      from onnx.onnx_pb import ModelProto
      from onnxruntime.quantization import QuantizationMode
      from onnxruntime.quantization.onnx_quantizer import ONNXQuantizer
      from onnxruntime.quantization.registry import IntegerOpsRegistry
  
      # Load the ONNX model
      onnx_model = onnx.load(onnx_model_path.as_posix())
  
      if parse(onnx.__version__) < parse("1.5.0"):
          print(
              "Models larger than 2GB will fail to quantize due to protobuf constraint.\n"
              "Please upgrade to onnxruntime >= 1.5.0."
          )
  
      # Copy it
      copy_model = ModelProto()
      copy_model.CopyFrom(onnx_model)
  
      # Construct quantizer
      # onnxruntime renamed input_qType to activation_qType in v1.13.1, so we
      # check the onnxruntime version to ensure backward compatibility.
      # See also: https://github.com/microsoft/onnxruntime/pull/12873
      if parse(onnxruntime.__version__) < parse("1.13.1"):
          quantizer = ONNXQuantizer(
              model=copy_model,
              per_channel=False,
              reduce_range=False,
              mode=QuantizationMode.IntegerOps,
              static=False,
              weight_qType=True,
              input_qType=False,
              tensors_range=None,
              nodes_to_quantize=None,
              nodes_to_exclude=None,
              op_types_to_quantize=list(IntegerOpsRegistry),
          )
      else:
          quantizer = ONNXQuantizer(
              model=copy_model,
              per_channel=False,
              reduce_range=False,
              mode=QuantizationMode.IntegerOps,
              static=False,
              weight_qType=True,
              activation_qType=False,
              tensors_range=None,
              nodes_to_quantize=None,
              nodes_to_exclude=None,
              op_types_to_quantize=list(IntegerOpsRegistry),
          )
  
      # Quantize and export
      quantizer.quantize_model()
  
      # Append "-quantized" at the end of the model's name
      quantized_model_path = generate_identified_filename(
          onnx_model_path, "-quantized"
      )
  
      # Save model
      print(
          f"Quantized model has been written at {quantized_model_path}: \N{heavy check mark}"
      )
      onnx.save_model(
          quantizer.model.model, quantized_model_path.as_posix()
      )
  
      return quantized_model_path
  
imports: import warnings
  from argparse import ArgumentParser
  from os import listdir, makedirs
  from pathlib import Path
  from typing import Dict, List, Optional, Tuple
  from packaging.version import Version, parse
  from transformers.pipelines import Pipeline, pipeline
  from transformers.tokenization_utils import BatchEncoding
  from transformers.utils import ModelOutput, is_tf_available, is_torch_available
label_desc: Use image node_id 10 for calling a global function with example usage: quantize(onnx_model_path) and returns: quantized_model_path