code: def test_fake_quant_true_quant_compare(self):
      for qengine in supported_qengines:
          with override_quantized_engine(qengine):
              torch.manual_seed(67)
              my_model = ModelMultipleOpsNoAvgPool().to(torch.float32)
              calib_data = torch.rand(
                  2048, 3, 15, 15, dtype=torch.float32
              )
              eval_data = torch.rand(10, 3, 15, 15, dtype=torch.float32)
              my_model.eval()
              out_ref = my_model(eval_data)
              fq_model = torch.ao.quantization.QuantWrapper(my_model)
              fq_model.train()
              fq_model.qconfig = (
                  torch.ao.quantization.default_qat_qconfig
              )
              torch.ao.quantization.fuse_modules_qat(
                  fq_model.module,
                  [["conv1", "bn1", "relu1"]],
                  inplace=True,
              )
              torch.ao.quantization.prepare_qat(fq_model)
              fq_model.eval()
              fq_model.apply(torch.ao.quantization.disable_fake_quant)
              fq_model.apply(torch.ao.nn.intrinsic.qat.freeze_bn_stats)
              fq_model(calib_data)
              fq_model.apply(torch.ao.quantization.enable_fake_quant)
              fq_model.apply(torch.ao.quantization.disable_observer)
              out_fq = fq_model(eval_data)
              SQNRdB = 20 * torch.log10(
                  torch.norm(out_ref) / torch.norm(out_ref - out_fq)
              )
              # Quantized model output should be close to floating point model output numerically
              # Setting target SQNR to be 35 dB
              self.assertGreater(
                  SQNRdB,
                  35,
                  msg="Quantized model numerics diverge from float, expect SQNR > 35 dB",
              )
              torch.ao.quantization.convert(fq_model)
              out_q = fq_model(eval_data)
              SQNRdB = 20 * torch.log10(
                  torch.norm(out_fq)
                  / (torch.norm(out_fq - out_q) + 1e-10)
              )
              self.assertGreater(
                  SQNRdB,
                  60,
                  msg="Fake quant and true quant numerics diverge, expect SQNR > 60 dB",
              )
  
file_path: pytorch/test/quantization/eager/test_model_numerics.py
imports: import torch
  from torch.testing._internal.common_quantization import QuantizationTestCase, ModelMultipleOps, ModelMultipleOpsNoAvgPool
  from torch.testing._internal.common_quantized import override_quantized_engine, supported_qengines
label_desc: Use image node_id 3 for calling the TestModelNumericsEager obj's underlying member method code with example usage: obj.test_fake_quant_true_quant_compare() without return types