Xilinx / finn

Dataflow compiler for QNN inference on FPGAs
https://xilinx.github.io/finn
BSD 3-Clause "New" or "Revised" License
681 stars 218 forks source link

The Trunc node must have the rounding_mode set to 'FLOOR'. #1083

Closed phixerino closed 1 month ago

phixerino commented 1 month ago

Hi, I'm trying to convert QONNX model to FINN-ONNX in FINN v0.10 with ConvertQONNXtoFINN() and it's giving me ValueError: The Trunc node must have the rounding_mode set to 'FLOOR'.. This happens during transformation of AvgPool -> Mul -> Trunc to QuantAvgPool2d. This is because I have set float_to_int_impl_type='ROUND' in Brevitas TruncAvgPool2d layer. This worked for me before with Brevitas v0.9, where I exported directly to FINN-ONNX and then imported in FINN v0.9. But this is not possible now with the export to FINN-ONNX deprecated.

So I tried to change float_to_int_impl_type='FLOOR', but with that the export to QONNX with export_onnx_qonnx() gives me AssertionError: Only round to nearest even supported.

Also I see that in the ResNet example for PYNQ, it's also set float_to_int_impl_type='FLOOR' by default. So how can that model be exported for FINN?

phixerino commented 1 month ago

Okay I figured it out. The error happens because first I tried to export it to QCDQ which fails, and then when I try to export it to QONNX it also fails for some reason. I don't know why this happens, because the error comes from brevitas/export/onnx/standard/qcdq/handler.py even though I call export_qonnx. But when I skip the export to QCDQ, then the export to QONNX works.