Accuracy decreasing after optimize_for_mobile


traced_script_module_optimized = optimize_for_mobile(traced_script_module)```

The traced_script_module gives an accuracy of 98% but for optimised one the accuracy falls down to 6%. How can I overcome this?

Is it a quantized model? cc: @kimishpatel

Yes. The model was dynamically quantized then optimised

I experienced exact same case:
Model that is not quantized and optimized is perfectly ok, however when I quantize model and then optimize its output is complete chaos. I think that is architecture dependent, bc I didn’t reproduced this problem for example of DeiT.

Can you provide a simpler repro for this?

One thing I can suggest is to check the memory format of output tensor for both models. If one is in NHWC format vs NCHW format, that may make a difference, if you are directly consuming the tensor without regards for the memory format.