code: def test_calibrate_model_with_offset_buffer(self):
      # Define a simple model to run calibration with.
      class MatMulModel(tf.Module):
          def __init__(self):
              # Use ones for predictable calibration results.
              self.filter = np.ones((4, 3)).astype(np.float32)
  
          @tf.function(
              input_signature=[
                  tf.TensorSpec(shape=(1, 4), dtype=dtypes.float32)
              ]
          )
          def __call__(self, input_tensor: tf.Tensor) -> tf.Tensor:
              output_tensor = tf.linalg.matmul(
                  input_tensor, self.filter
              )
              return {"output": output_tensor}
  
      model = MatMulModel()
      saved_model_path = self.create_tempdir().full_path
      tf.saved_model.save(model, saved_model_path)
  
      converter = lite.TFLiteConverter.from_saved_model(
          saved_model_path
      )
      # Enable the use of buffer offsets.
      # pylint: disable=protected-access
      converter._experimental_use_buffer_offset = True
      # pylint: enable=protected-access
      converter.exclude_conversion_metadata = True
  
      model_serialized = converter.convert()
  
      model = flatbuffer_utils.convert_bytearray_to_object(
          model_serialized
      )
      self.assertTrue(_uses_buffer_offset(model))
  
      quantizer = _calibrator.Calibrator(model_serialized)
  
      # Input generator for the model.
      def input_gen():
          for _ in range(2):
              yield [np.array([1.0, 1.0, 1.0, 1.0], dtype=np.float32)]
  
      calibrated_model_serialized = quantizer.calibrate(input_gen)
      self.assertIsNotNone(calibrated_model_serialized)
  
      calibrated_model = flatbuffer_utils.convert_bytearray_to_object(
          calibrated_model_serialized
      )
      self.assertTrue(_uses_buffer_offset(calibrated_model))
  
      # Confirm that the tensors are correctly calibrated.
      subgraph = calibrated_model.subgraphs[0]
  
      matmul_input_tensor = subgraph.tensors[0]
      self.assertAllClose(matmul_input_tensor.quantization.min, [1.0])
      self.assertAllClose(matmul_input_tensor.quantization.max, [1.0])
  
      matmul_filter_tensor = subgraph.tensors[1]
      self.assertAllClose(matmul_filter_tensor.quantization.min, [1.0])
      self.assertAllClose(matmul_filter_tensor.quantization.max, [1.0])
  
      # The matmul is performed with all ones so the output is expected to be 4s.
      matmul_output_tensor = subgraph.tensors[2]
      self.assertAllClose(matmul_output_tensor.quantization.min, [4.0])
      self.assertAllClose(matmul_output_tensor.quantization.max, [4.0])
  
imports: from absl.testing import parameterized
  import numpy
  import tensorflow
  from tensorflow.lite.python import lite
  from tensorflow.lite.python import schema_py_generated
  from tensorflow.lite.python.optimize import calibrator
  from tensorflow.lite.tools import flatbuffer_utils
  from tensorflow.python.framework import dtypes
  from tensorflow.python.framework import test_util
  from tensorflow.python.platform import resource_loader
  from tensorflow.python.platform import test
label_desc: Use image node_id 12 for calling the CalibratorTest obj's underlying member method code with example usage: obj.test_calibrate_model_with_offset_buffer() and returns: dict