RuntimeError: Could not run 'aten::empty.memory_format' with arguments from the 'QuantizedCPU' backend

I am trying to quantize the model of image network. and I faced the error.

For the call the function below

dummy_input = torch.randn(1, 3, 320, 320).cpu()
script_model = torch.jit.trace(net, dummy_input)

the tensor operation of sum shows the Exception

norm = x.sum(dim=1, keepdim=True).sqrt()

RuntimeError: Could not run ‘aten::empty.memory_format’ with arguments from the ‘QuantizedCPU’ backend. ‘aten::empty.memory_format’ is only available for these backends: [CPU, CUDA, MkldnnCPU, SparseCPU, SparseCUDA, BackendSelect, Autograd, Profiler, Tracer].

Is there any way bypassing this error?

1 Like

it’s because quantized::sum is not supported, can you put dequant/quant around the sum op?

2 Likes

hi, how to put dequant/quant around the sum op?? sorry,i am new

There is an example here: https://pytorch.org/docs/stable/quantization.html - if you search that page for torch.quantization.QuantStub() and torch.quantization.DeQuantStub(), that should help.

1 Like