class_docstr: Quantization tests for dynamic Int8 - Int8 matrix multiplications
class_docstr_tok: ["Quantization","tests","for","dynamic","Int8","-","Int8","matrix","multiplications"]
code: def compare(self, specification_modified=True):
      x = np.random.rand(*self.input_shape)
  
      def _get_preds(spec):
          mlmodel = coremltools.models.MLModel(
              spec, compute_units=ComputeUnit.CPU_ONLY
          )
          return mlmodel.predict({"data": x})["output"]
  
      preds = _get_preds(self.builder.spec)
      self.assertEqual(self.builder.spec.specificationVersion, 4)
  
      quantized_spec = activate_int8_int8_matrix_multiplications(
          self.builder.spec, self.selector
      )
  
      layer = self.builder.spec.neuralNetwork.layers[0]
      layer_type = layer.WhichOneof("layer")
      if layer_type == "innerProduct":
          matmul_layer = layer.innerProduct
  
      elif layer_type == "batchedMatmul":
          matmul_layer = layer.batchedMatmul
      wp = matmul_layer.weights
  
      if specification_modified:
          self.assertEqual(self.builder.spec.specificationVersion, 5)
          quant_preds = _get_preds(quantized_spec)
          self._test_predictions(preds, quant_preds, SNR=40)
          self.assertEqual(len(wp.floatValue), 0)
      else:
          self.assertEqual(self.builder.spec.specificationVersion, 4)
          quant_preds = _get_preds(quantized_spec)
          np.testing.assert_array_almost_equal(preds, quant_preds)
          self.assertGreater(len(wp.floatValue), 0)
  
imports: import itertools
  import unittest
  import numpy
  import pytest
  import coremltools
  import coremltools.models.datatypes
  from coremltools import ComputeUnit
  from coremltools.models import _QUANTIZATION_MODE_LINEAR_QUANTIZATION, neural_network
  from coremltools.models.neural_network import quantization_utils
  from coremltools.models.neural_network.quantization_utils import MatrixMultiplyLayerSelector, _quantize_spec_weights, activate_int8_int8_matrix_multiplications
label_desc: Use image node_id 3 for calling the DynamicQuantizedInt8Int8MatMul obj's underlying member method code with example usage: obj.compare(specification_modified) and returns: mlmodel