docstr: Dynamic Quantize SingleLayerLinearDynamicModel which has one Linear module,
  make sure it is swapped to nnqd.Linear which is the quantized version of
  the module
docstr_tok: ["Dynamic","Quantize","SingleLayerLinearDynamicModel","which","has","one","Linear","module",",","make","sure","it","is","swapped","to","nnqd.Linear","which","is","the","quantized","version","of","the","module"]
code: def test_single_layer(self):
      r"""Dynamic Quantize SingleLayerLinearDynamicModel which has one Linear module,
      make sure it is swapped to nnqd.Linear which is the quantized version of
      the module
      """
      for dtype in [torch.qint8, torch.float16]:
          model = SingleLayerLinearDynamicModel().eval()
          qconfig = (
              float16_dynamic_qconfig
              if dtype == torch.float16
              else default_dynamic_qconfig
          )
          qconfig_dict = {"fc1": qconfig}
          prepare_dynamic(model, qconfig_dict)
          convert_dynamic(model)
  
          def checkQuantized(model):
              self.checkDynamicQuantizedLinear(model.fc1, dtype)
              self.checkScriptable(
                  model, self.calib_data, check_save_load=True
              )
              self.checkNoQconfig(model)
  
          checkQuantized(model)
  
          # test one line API - out of place version
          base = SingleLayerLinearDynamicModel()
          keys_before = set(base.state_dict().keys())
          model = quantize_dynamic(base, qconfig_dict)
          checkQuantized(model)
          keys_after = set(base.state_dict().keys())
          self.assertEqual(
              keys_before, keys_after
          )  # simple check that nothing changed
  
          # in-place version
          model = SingleLayerLinearDynamicModel()
          quantize_dynamic(model, qconfig_dict, inplace=True)
          checkQuantized(model)
  
          # Test set qconfig
          model = SingleLayerLinearDynamicModel()
          quantize_dynamic(
              model, {nn.Linear}, inplace=True, dtype=dtype
          )
          checkQuantized(model)
  
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 1 for calling the TestQuantizeEagerPTQDynamic obj's underlying member method code with example usage: obj.test_single_layer() without return types