Dynamic quantization error: Mixed serialization of script and non-script modules is not supported

Hi, I have an issue in quantizing yolov3 model. I am working on this implementation: https://github.com/eriklindernoren/PyTorch-YOLOv3
I followed the dynamic quantization tutorial and the quantization code as following: loading the model, loading pretrained weights from Darknet and using the dynamic quantization.

model = Darknet(opt.model_def, img_size=opt.img_size).to(device)

if opt.weights_path.endswith(".weights"):
    # Load darknet weights
    model.load_darknet_weights(opt.weights_path)
else:
    # Load checkpoint weights
    model.load_state_dict(torch.load(opt.weights_path))

qmodel = torch.quantization.quantize_dynamic(model, dtype=torch.qint8)

But I got this error message:

“For purely script modules use my_script_module.save() instead.”)
_pickle.PickleError: ScriptModules cannot be deepcopied using copy.deepcopy or saved using torch.save. Mixed serialization of script and non-script modules is not supported. For purely script modules use my_script_module.save() instead.

Do you have any suggestions guys?

It looks like you are trying to quantize the scripted net.
The correct order seems like first quantize your net then script it!