code: def generic_test(
      self,
      model,
      sample_inputs,
      input_names=None,
      decimal=3,
      relaxed_check=False,
  ):
      torch.backends.quantized.engine = "qnnpack"
      pt_inputs = tuple(torch.from_numpy(x) for x in sample_inputs)
      model.qconfig = torch.ao.quantization.get_default_qconfig(
          "qnnpack"
      )
      q_model = torch.ao.quantization.prepare(model, inplace=False)
      q_model = torch.ao.quantization.convert(q_model, inplace=False)
  
      traced_model = torch.jit.trace(q_model, pt_inputs)
      buf = io.BytesIO()
      torch.jit.save(traced_model, buf)
      buf.seek(0)
      q_model = torch.jit.load(buf)
  
      q_model.eval()
      output = q_model(*pt_inputs)
  
      f = io.BytesIO()
      torch.onnx.export(
          q_model,
          pt_inputs,
          f,
          input_names=input_names,
          operator_export_type=torch.onnx.OperatorExportTypes.ONNX_ATEN_FALLBACK,
          # Caffe2 doesn't support newer opset versions
          opset_version=9,
      )
      f.seek(0)
      onnx_model = onnx.load(f)
      caffe_res = c2.run_model(
          onnx_model, dict(zip(input_names, sample_inputs))
      )[0]
      # Due to change in requantization logic for certain ops such conv, linear
      # in pytorch's integration of qnnpack, numerics may have a mismatc with C2.
      # This mismatch should not be off my more than 1.
      # This flag helps us override default behavior under certain circumstances.
      if relaxed_check:
          output_diff = np.absolute(
              np.squeeze(output.detach().numpy()) - caffe_res
          )
          max_diff = np.amax(output_diff)
  
          # This check had to be changed to account for changes in
          # qnnpack's requant logic.
          np.testing.assert_(
              max_diff <= 1,
              "Maximum absolute difference must be less than 1",
          )
      else:
          np.testing.assert_almost_equal(
              output.detach().numpy(), caffe_res, decimal=decimal
          )
  
imports: import io
  import caffe2.python.onnx.backend
  import numpy
  import onnx
  import pytorch_test_common
  import torch.ao.nn.quantized
  import torch.nn
  import torch.onnx
  from torch.testing._internal import common_utils
label_desc: Use image node_id 1 for calling the TestQuantizedOps obj's underlying member method code with example usage: obj.generic_test(model, sample_inputs, input_names, decimal, relaxed_check) without return types