class_docstr: Base QuantizationTestCase for PT2E QAT with some helper methods.
class_docstr_tok: ["Base","QuantizationTestCase","for","PT2E","QAT","with","some","helper","methods","."]
docstr: Helper method to verify that the QAT numerics for PT2E quantization match those of
  FX graph mode quantization for symmetric qnnpack.
docstr_tok: ["Helper","method","to","verify","that","the","QAT","numerics","for","PT2E","quantization","match","those","of","FX","graph","mode","quantization","for","symmetric","qnnpack","."]
code: def _verify_symmetric_xnnpack_qat_numerics_helper(
      self,
      model: torch.nn.Module,
      example_inputs: Tuple[Any, ...],
      is_per_channel: bool,
      verify_convert: bool = True,
  ):
      """
      Helper method to verify that the QAT numerics for PT2E quantization match those of
      FX graph mode quantization for symmetric qnnpack.
      """
      # resetting dynamo cache
      torch._dynamo.reset()
      MANUAL_SEED = 100
  
      # PT2 export
  
      model_pt2e = copy.deepcopy(model)
      quantizer = XNNPACKQuantizer()
      quantizer.set_global(
          get_symmetric_quantization_config(
              is_per_channel=is_per_channel, is_qat=True
          )
      )
      model_pt2e = capture_pre_autograd_graph(
          model_pt2e,
          example_inputs,
      )
      model_pt2e = prepare_qat_pt2e(model_pt2e, quantizer)
      torch.manual_seed(MANUAL_SEED)
      after_prepare_result_pt2e = model_pt2e(*example_inputs)
  
      model_fx = copy.deepcopy(model)
      if is_per_channel:
          default_qconfig = (
              default_per_channel_symmetric_qnnpack_qat_qconfig
          )
      else:
          default_qconfig = default_symmetric_qnnpack_qat_qconfig
      qconfig_mapping = QConfigMapping().set_global(default_qconfig)
      backend_config = get_qnnpack_backend_config()
      model_fx = prepare_qat_fx(
          model_fx,
          qconfig_mapping,
          example_inputs,
          backend_config=backend_config,
      )
      torch.manual_seed(MANUAL_SEED)
      after_prepare_result_fx = model_fx(*example_inputs)
  
      # Verify that numerics match
      self.assertEqual(
          after_prepare_result_pt2e, after_prepare_result_fx
      )
  
      if verify_convert:
          # We don't want to impose any ordering requirements between move_exported_model_to_eval and convert_pt2e
          torch.ao.quantization.move_exported_model_to_eval(model_pt2e)
          model_pt2e = convert_pt2e(model_pt2e)
          quant_result_pt2e = model_pt2e(*example_inputs)
          model_fx.eval()
          model_fx = _convert_to_reference_decomposed_fx(
              model_fx,
              backend_config=backend_config,
          )
          quant_result_fx = model_fx(*example_inputs)
          self.assertEqual(quant_result_pt2e, quant_result_fx)
  
imports: import copy
  import operator
  import unittest
  from typing import Any, Optional, Tuple, Type
  import torch
  from torch._export import capture_pre_autograd_graph
  from torch.ao.quantization import default_fake_quant, FusedMovingAvgObsFakeQuantize, MovingAverageMinMaxObserver, MovingAveragePerChannelMinMaxObserver, QConfigMapping
  from torch.ao.quantization.backend_config import get_qnnpack_backend_config
  from torch.ao.quantization.qconfig import default_per_channel_symmetric_qnnpack_qat_qconfig, default_symmetric_qnnpack_qat_qconfig
  from torch.ao.quantization.quantize_fx import prepare_qat_fx
  from torch.ao.quantization.quantize_pt2e import _convert_to_reference_decomposed_fx, convert_pt2e, prepare_pt2e, prepare_qat_pt2e
  from torch.ao.quantization.quantizer import DerivedQuantizationSpec, QuantizationAnnotation, QuantizationSpec, Quantizer
  from torch.ao.quantization.quantizer.xnnpack_quantizer import get_symmetric_quantization_config, XNNPACKQuantizer
  from torch.testing._internal.common_cuda import TEST_CUDA
  from torch.testing._internal.common_quantization import NodeSpec, QuantizationTestCase, skip_if_no_torchvision, skipIfNoQNNPACK
  from torch.testing._internal.common_quantized import override_quantized_engine
label_desc: Use image node_id 3 for calling the PT2EQATTestCase obj's underlying member method code with example usage: obj._verify_symmetric_xnnpack_qat_numerics_helper(model, example_inputs, is_per_channel, verify_convert) without return types