What is different in torch.ao.quantization.get_default_qat_qconfig and torch.ao.quantization.get_default_qconfig?

qconfig = torch.ao.quantization.get_default_qat_qconfig("qnnpack")
>>> print(qconfig)
QConfig(activation=functools.partial(<class 'torch.ao.quantization.fake_quantize.FusedMovingAvgObsFakeQuantize'>, observer=<class 'torch.ao.quantization.observer.MovingAverageMinMaxObserver'>, quant_min=0, quant_max=255, reduce_range=False){}, weight=functools.partial(<class 'torch.ao.quantization.fake_quantize.FusedMovingAvgObsFakeQuantize'>, observer=<class 'torch.ao.quantization.observer.MovingAverageMinMaxObserver'>, quant_min=-128, quant_max=127, dtype=torch.qint8, qscheme=torch.per_tensor_symmetric){})
>>> qconfig = torch.ao.quantization.get_default_qconfig("qnnpack")
>>> print(qconfig)
QConfig(activation=functools.partial(<class 'torch.ao.quantization.observer.HistogramObserver'>, reduce_range=False){}, weight=functools.partial(<class 'torch.ao.quantization.observer.MinMaxObserver'>, dtype=torch.qint8, qscheme=torch.per_tensor_symmetric){})

Can torch.ao.quantization.get_default_qconfig be used for QAT training,what is the difference between them?

PTQ is post training quantization, i.e. once you’ve got a model, you simply apply this type of quantization on top of it. The qconfigs include information about what type of quantization you want to apply to your model. This is what the default qconfig is set up for.

QAT is quantization aware training i.e. while training the model, you are finding weights that will work well given a specific type of quantization you will apply at the end. The qconfig contains the information for this quantization as well as functionality to simulate the quantization while still using fp32 numerics during training, since an actual quantized module doesn’t have gradients.

They are not interchangable.

for more information see Quantization — PyTorch 2.0 documentation