Quantized Resnet has no parameters()

Hi there,
i’m currently trying to perform a quantization-aware fine-tuning of a Resnet50 model on another dataset and experiencing some issues related to the initialization of the training optimizer.

import torch
from torchvision.models.quantization.resnet import resnet50, ResNet50_QuantizedWeights

model = resnet50(weights=ResNet50_QuantizedWeights.IMAGENET1K_FBGEMM_V1, quantize=True)
model.train()
model.qconfig = torch.quantization.get_default_qat_qconfig("qnnpack")
model_qat = torch.quantization.prepare_qat(model, inplace=False)
optimizer = torch.optim.SGD(model_qat.parameters(), lr=1e-4)

Running this script leads to the following error: ValueError: optimizer got an empty parameter list.

I must admit that I am pretty inexperienced in quantization in Pytorch so I may be missing a crucial step here. Thanks!

quantize = True returns a quantized model with 8 bit weights. Quantized models only support inference and run on CPUs. So you cannot do QAT on that, since we don’t support training integer weights.

You can follow the tutorial here for details on how to do QAT.

Note that for resnet you can also try the PT2 export based QAT, which doesn’t require any manual model changes. Please refer to the tutorials
1 (prototype) PyTorch 2 Export Quantization-Aware Training (QAT) — PyTorch Tutorials 2.2.1+cu121 documentation
2. PyTorch 2 Export Quantization with X86 Backend through Inductor — PyTorch Tutorials 2.2.1+cu121 documentation

Thank you very much for your response. Does it means that once a model is trained in a quantized-aware manner, it can no longer be modified (say, in a continuous training setting)?