And here is my code:
#fuse model
fuse_model(subnet)
#quantize model
subnet.qconfig = torch.quantization.get_default_qconfig('qnnpack')
torch.quantization.prepare(subnet, inplace=True)
# Calibrate
print(torch.backends.quantized.supported_engines)
torch.quantization.convert(subnet, inplace=True)
#optimize
script_subnet = torch.jit.script(model)
script_subnet_optimized = optimize_for_model(script_model)