docstr: Test PTQ flow of creating a model and quantizing it and saving the quantized state_dict
  Load the quantized state_dict for eval and compare results against original model
docstr_tok: ["Test","PTQ","flow","of","creating","a","model","and","quantizing","it","and","saving","the","quantized","state_dict","Load","the","quantized","state_dict","for","eval","and","compare","results","against","original","model"]
code: def test_save_load_state_dict(self):
      r"""Test PTQ flow of creating a model and quantizing it and saving the quantized state_dict
      Load the quantized state_dict for eval and compare results against original model
      """
  
      for qengine in supported_qengines:
          with override_quantized_engine(qengine):
              model = TwoLayerLinearModel()
              model = torch.ao.quantization.QuantWrapper(model)
              model.qconfig = torch.ao.quantization.get_default_qconfig(
                  qengine
              )
  
              model = prepare(model)
              # calibrate
              test_only_eval_fn(model, self.calib_data)
              model = convert(model)
              x = torch.rand(2, 5, dtype=torch.float)
              ref = model(x)
  
              quant_state_dict = model.state_dict()
  
              # Create model again for eval
              model = TwoLayerLinearModel()
              model = torch.ao.quantization.QuantWrapper(model)
              model.qconfig = torch.ao.quantization.get_default_qconfig(
                  qengine
              )
              model = prepare(model)
              model = convert(model)
              new_state_dict = model.state_dict()
  
              # Check to make sure the state dict keys match original model after convert.
              self.assertEqual(
                  set(new_state_dict.keys()),
                  set(quant_state_dict.keys()),
              )
  
              model.load_state_dict(quant_state_dict)
  
              out = model(x)
              self.assertEqual(ref, out)
  
imports: import torch
  import torch.nn
  import torch.ao.nn.quantized
  from torch.nn.utils.rnn import PackedSequence
  from torch.ao.quantization import quantize, prepare, convert, prepare_qat, quantize_dynamic, QuantWrapper, QuantStub, DeQuantStub, default_qconfig, default_dynamic_qconfig, per_channel_dynamic_qconfig, float16_dynamic_qconfig, float_qparams_weight_only_qconfig, float_qparams_weight_only_qconfig_4bit, FixedQParamsObserver, PerChannelMinMaxObserver, default_dynamic_quant_observer, default_weight_observer, QConfig
  from torch.testing._internal.common_quantization import QuantizationTestCase, AnnotatedSingleLayerLinearModel, QuantStubModel, ModelWithFunctionals, SingleLayerLinearDynamicModel, TwoLayerLinearModel, NestedModel, ResNetBase, RNNDynamicModel, RNNCellDynamicModel, ActivationsTestModel, NormalizationTestModel, test_only_eval_fn, prepare_dynamic, convert_dynamic, skipIfNoFBGEMM, EmbeddingBagModule, EmbeddingModule, EmbeddingWithStaticLinear, LinearReluLinearModel
  from torch.testing._internal.common_quantization import AnnotatedTwoLayerLinearModel, AnnotatedNestedModel, AnnotatedSubNestedModel, AnnotatedCustomConfigNestedModel, AnnotatedSkipQuantModel
  from torch.testing._internal.common_quantized import override_quantized_engine, supported_qengines, override_qengines
  from hypothesis import given
  from hypothesis import strategies
  import torch.testing._internal.hypothesis_utils
  from typing import Tuple
  import numpy
label_desc: Use image node_id 10 for calling the TestQuantizeEagerPTQStatic obj's underlying member method code with example usage: obj.test_save_load_state_dict() without return types