class_docstr: Base test class for StableHLO quant tests.
class_docstr_tok: ["Base","test","class","for","StableHLO","quant","tests","."]
code: def _create_matmul_model(
      self,
      input_shape: Sequence[int],
      weight_shape: Sequence[int],
      saved_model_path: str,
      has_bias: bool = False,
      activation_fn: Optional[ops.Operation] = None,
      bias_size: Optional[int] = None,
      use_biasadd: bool = True,
  ) -> module.Module:
      class MatmulModel(module.Module):
          """A simple model with a single matmul.
  
          Bias and activation function are optional.
          """
  
          def __init__(
              self,
              weight_shape: Sequence[int],
              bias_size: Optional[int] = None,
              activation_fn: Optional[ops.Operation] = None,
              use_biasadd: bool = True,
          ) -> None:
              """Initializes a MatmulModel.
  
              Args:
                weight_shape: Shape of the weight tensor.
                bias_size: If None, do not use bias. Else, use given size as bias.
                activation_fn: The activation function to be used. No activation
                  function if None.
                use_biasadd: If True, use BiasAdd for adding bias, else use AddV2.
              """
              self.bias_size = bias_size
              self.activation_fn = activation_fn
              self.use_biasadd = use_biasadd
              self.filters = np.random.uniform(
                  low=-1.0, high=1.0, size=weight_shape
              )
  
              if bias_size is not None:
                  self.bias = np.random.uniform(
                      low=-1.0, high=1.0, size=bias_size
                  )
  
          def has_bias(self) -> bool:
              return self.bias_size is not None
  
          def has_reshape(self) -> bool:
              return (
                  self.has_bias()
                  and self.bias_size != self.filters.shape[-1]
              )
  
          @def_function.function
          def matmul(
              self, input_tensor: core.Tensor
          ) -> Mapping[str, core.Tensor]:
              """Performs a matrix multiplication.
  
              Depending on self.has_bias and self.activation_fn, it may add a bias
              term or
              go through the activaction function.
  
              Args:
                input_tensor: Input tensor to matmul with the filter.
  
              Returns:
                A map of: output key -> output result.
              """
              out = math_ops.matmul(
                  input_tensor, self.filters, name="sample/matmul"
              )
  
              return {"output": out}
  
      # If bias_size is not explictly given, it should default to width of weight.
      if bias_size is None and has_bias:
          bias_size = weight_shape[-1]
  
      # Verify that when bias_size is not None, has_bias should be True.
      # And if bias_size is None, has_bias should be False.
      assert (bias_size is None) != has_bias
  
      model = MatmulModel(weight_shape, bias_size, activation_fn)
      saved_model_save.save(
          model,
          saved_model_path,
          signatures=model.matmul.get_concrete_function(
              tensor_spec.TensorSpec(
                  shape=input_shape,
                  dtype=dtypes.float32,
                  name="input_tensor",
              )
          ),
      )
      return model
  
imports: from typing import Mapping, Sequence, Optional, Tuple, List
  from absl.testing import parameterized
  import numpy
  import tensorflow
  from tensorflow.python.eager import def_function
  from tensorflow.python.framework import dtypes
  from tensorflow.python.framework import ops
  from tensorflow.python.framework import tensor_spec
  from tensorflow.python.module import module
  from tensorflow.python.ops import array_ops
  from tensorflow.python.ops import math_ops
  from tensorflow.python.ops import nn_ops
  from tensorflow.python.platform import test
  from tensorflow.python.saved_model import save
  from tensorflow.python.types import core
label_desc: Use image node_id 2 for calling the QuantizedModelTest obj's underlying member method code with example usage: obj._create_matmul_model(input_shape, weight_shape, saved_model_path, has_bias, activation_fn, bias_size, use_biasadd) and returns: model, unknown, unknown, dict