CEA-LIST / N2D2

N2D2 is an open source CAD framework for Deep Neural Network simulation and full DNN-based applications building.
Other
146 stars 35 forks source link

Floating point exception when exporting ResNet ONNX to quantifed network #80

Closed stephaneburel-cea closed 3 years ago

stephaneburel-cea commented 3 years ago

Hello.

The ONNX importation of a ResNet works well :

n2d2.sh "$N2D2_MODELS/ResNet_ONNX.ini"-seed 1 -test -w /dev/null

(With onnx model from https://s3.amazonaws.com/onnx-model-zoo/resnet/resnet18v1/resnet18v1.onnx) (With ResNet_ONNX.ini file from N2D2-IP repository)

Give a good accuracy so I understand that ONNX import works well.

But quantified export always give a floating point exception. n2d2.sh "$N2D2_MODELS/ResNet_ONNX.ini"-seed 1 -w /dev/null -export C -calib -1 -no-unsigned

I had the same problem with ResNet trained from scratch, but ONNX export make the error easilly reproductible.

Regards.

olivierbichler-cea commented 3 years ago

Hi,

This issue is due to the fact the scaling factor of one layer is > 1.0 after quantization and the scaling factor approximation is "Single-shift", which allows only right-shifts. If you use "Floating-point" for the scaling factor (with -act-rescaling-mode Floating-point), this issue disappear. In this case you need to use the novel CPP export instead of the C export which only supports "Signe-shift" and is not much maintained any more.

This is a known issue of the "Single-shift" mode and we are still thinking about the best solution in this case.

Cheers

olivierbichler-cea commented 3 years ago

Closing the issue. The latest version of N2D2 now generates a proper error message.