code: def test_matmul_ptq_model(
      self,
      activation_fn: Optional[ops.Operation],
      has_bias: bool,
      dim_sizes: Sequence[int],
  ):
      target_opset = quant_opts_pb2.STABLEHLO
  
      lhs_dim_size, rhs_dim_size = dim_sizes
      input_shape = (*lhs_dim_size,)
      filter_shape = (*rhs_dim_size,)
      static_input_shape = [
          dim if dim is not None else 2 for dim in input_shape
      ]
      model = self._create_matmul_model(
          input_shape,
          filter_shape,
          self._input_saved_model_path,
          has_bias,
          activation_fn,
      )
  
      rng = np.random.default_rng(seed=1235)
      input_data = ops.convert_to_tensor(
          rng.uniform(
              low=0.0, high=1.0, size=static_input_shape
          ).astype(np.float32)
      )
  
      def data_gen() -> repr_dataset.RepresentativeDataset:
          for _ in range(100):
              yield {
                  "input_tensor": rng.uniform(
                      low=0.0, high=1.0, size=static_input_shape
                  ).astype(np.float32)
              }
  
      dataset_path = self.create_tempfile("tfrecord").full_path
      path_map = {"serving_default": dataset_path}
      repr_dataset.TfRecordRepresentativeDatasetSaver(path_map).save(
          {"serving_default": data_gen()}
      )
  
      config = quant_opts_pb2.QuantizationOptions(
          quantization_method=quant_opts_pb2.QuantizationMethod(
              preset_method=_PresetMethod.METHOD_STATIC_RANGE_INT8
          ),
          tags={tag_constants.SERVING},
          signature_keys=["serving_default"],
          op_set=target_opset,
          representative_datasets={
              "serving_default": quant_opts_pb2.RepresentativeDatasetFile(
                  tfrecord_file_path=dataset_path
              )
          },
          calibration_options=quant_opts_pb2.CalibrationOptions(
              calibration_method=quant_opts_pb2.CalibrationOptions.CALIBRATION_METHOD_MIN_MAX
          ),
      )
      quantization.quantize_saved_model(
          self._input_saved_model_path,
          self._output_saved_model_path,
          config,
      )
  
      expected_outputs = model.matmul(input_data)
  
      root = load.load(self._output_saved_model_path)
      self.assertCountEqual(root.signatures.keys(), {"serving_default"})
  
      new_outputs = root.signatures["serving_default"](
          input_tensor=ops.convert_to_tensor(input_data)
      )
      # Tests that the quantized graph outputs similar values. The rtol value is
      # arbitrary.
      # TODO: b/309674337 - Fix the large numerical errors.
      self.assertAllClose(new_outputs, expected_outputs, atol=0.3)
  
file_path: tensorflow-upstream/tensorflow/compiler/mlir/quantization/stablehlo/python/integration_test/quantize_model_test.py
imports: import itertools
  from typing import Optional, Sequence
  from absl.testing import parameterized
  import numpy
  from tensorflow.compiler.mlir.quantization.stablehlo.python import quantization
  from tensorflow.compiler.mlir.quantization.stablehlo.python.integration_test import quantize_model_test_base
  from tensorflow.compiler.mlir.quantization.tensorflow import quantization_options_pb2
  from tensorflow.compiler.mlir.quantization.tensorflow.python import representative_dataset
  from tensorflow.python.framework import ops
  from tensorflow.python.framework import test_util
  from tensorflow.python.platform import test
  from tensorflow.python.saved_model import load
  from tensorflow.python.saved_model import tag_constants
label_desc: Use image node_id 1 for calling the StaticRangeQuantizationTest obj's underlying member method code with example usage: obj.test_matmul_ptq_model(activation_fn, has_bias, dim_sizes) without return types