Floating point module class <class 'torch.nn.quantized._reference.modules.conv.Conv2d'> does not have a corresponding quantized module class

I am trying to run quantization on a MobileNetv3.

My code is as follows:

import torch
import copy
from torch.quantization import get_default_qconfig
qmodel = copy.deepcopy(model)
from torch.quantization.quantize_fx import prepare_fx, convert_fx
qconfig = get_default_qconfig("qnnpack")
qconfig_dict = {"": qconfig}
def calibrate(model, data_loader):
    with torch.no_grad():
        for image, target in data_loader:
prepared_model = prepare_fx(qmodel, qconfig_dict)  # fuse modules and insert observers
calibrate(prepared_model, val_loader)  # run calibration on sample data
quantized_model = convert_fx(prepared_model, is_reference=True)

the convert_fx function returns the following error:

AssertionError: Floating point module class <class ‘torch.nn.quantized._reference.modules.conv.Conv2d’> does not have a corresponding quantized module class

What am I missing here?

What version of torch are you using? I’m unable to reproduce this error in 1.10.1.

Does this error persist if you switch the flag to is_reference=False?

I am using version “1.11.0”
If i turn of the is_reference, I get the following error:

only conv2d calls with all arguments specified is supported right now in is_reference=False option

But my MobileNet is connected to another model. Maybe it is not tracable?

Hmm, I’m not sure - I’d guess if it wasn’t traceable it should throw an error specific to that. Paging @jerryzh168 for help here!

Pretty weird indeed.
I ended up doing some magic wiring to have the eager mode working on selective quantization. But I am still interested in FX.

there might be some bugs in previous versions of pytorch, can you try pytorch master to see if the error is fixed?