Chisel4ml and a subtle rounding issue. #109
Replies: 3 comments 4 replies
-
I imagine @jmduarte or perhaps @jmitrevs would be best placed to help answer this on the QKeras side of things. |
Beta Was this translation helpful? Give feedback.
-
On a separate note, I'm a big Chisel fan and did a bunch of hardware generator work with it back in the day. I see you have started your own FPGA component libraries as part of it, here's mine which was originally written for Chisel 2 and ported to Chisel 3 by @erlingj - feel free to take a look and pick things up from there if you find them useful: https://github.com/maltanar/fpga-tidbits There's also a DSD'23 paper "FPGA-tidbits: Rapid Prototyping of FPGA Accelerators in Chisel" that goes with it, but I seem to have trouble finding a usable link.. |
Beta Was this translation helpful? Give feedback.
-
Discussion continued in #110 |
Beta Was this translation helpful? Give feedback.
-
Hey,
I am the main author of Chisel4ml (https://github.com/cs-jsi/chisel4ml), a library similar to hls4ml and FINN, but based on the Chisel HCL. Currently, we are taking QKeras models and converting them "manually" down to our own custom representation. We would like to switch to QONNX however, since this would save us a lot of work, and enable support for Brevitas.
I am currently testing qonnx, and one subtle rounding mode issue caught my attention. This issue concerns the
quantized_bits
operator in QKeras. When testing different configurations I stumbled upon a peculiar difference in rounding mode behavior. This is best shown with example:The function above will fail on the second assert (for QKeras 0.9.0). However, the scaling factors printed in the finally block will be 1, [1,1,1] and [1,1,1]. The reason is that when using "auto_po2" the rounding mode is actually "round half up". This can be seen on:
https://github.com/google/qkeras/blob/67e7c6b8cbd6befd594f142187ac4b73b35512ac/qkeras/quantizers.py#L570C45-L570C46
I've just started to look at the converter for QKeras, and it seems that quantized_bits is always converted to rounding_mode="ROUND", which is a round half to even operation. Thus, this seems to be a discrepancy. Am I missing something here? Anyway, If you are open to it, I'd be glad to open an issue on this, and/or a pull request.
Beta Was this translation helpful? Give feedback.
All reactions