-
Notifications
You must be signed in to change notification settings - Fork 399
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Vivado-equivalent implementation of Softmax on Quartus #540
Conversation
How about moving the computation of the table data out of the writer and into a backend optimizer pass? You could attach the table data to the layer in an analogous way to weights for other layers. |
I don't see why not. But then, for consistency sake, we should do that for all of the other activations as well - which, I'm more than happy to do, but feel like this should be a part of a separate PR? Not necessarily softmax-specific? |
I agree, let's not do that here. But I think it still makes sense to do it for softmax in an optimizer pass. I think these write_exp_table and write_inv_table methods are for softmax specifically right? I think the logic using this new
It looks essentially like you're using the same type for the address (
, and I think what's happening here in the Quartus code is a little different. The pytest for Softmax just checks the accuracy by taking the argmax in the end, but could you take a look at the values produced to check this (e.g. here)? |
Re: The logic breakdown behind this is:
To my understanding, this is equivalent to the Vivado C++ function below:
I did also check the outputs with Vivado HLS and a stand-alone Python script to test this functionality, and the values were equal.
However, there seems to be a discrepancy in the raw values between Quartus and Vivado, so I will fix that. |
No, this was recent change. Look-up tables for Quartus need to be generated from Python and written to external files before compile-time. Unlike Vivado (which can generate tables only once and re-use them), on Quartus this doesn't work (or so I've been told). Therefore, all look-up tables (Sigmoid, Softmax, Tanh, Softplus etc.) are generated from |
I think the issue is just that, in the Vivado code you showed, the computation is done for |
Exactly, I just realised that an hour ago. So it needs to be changed from |
Addressed discrepancy between data and tables, as explained above. Manually checked results to Keras prediction for 5 tests, on 5 data points. Results are accurate. RegEx was removed, in favour of attributes. Commit with main changes here: 937cc49 |
Vivado-equivalent implementation of Softmax on Quartus
fixed_point_utils.py
, emulating some fixed-point and bit-manipulation operations in Python. These are usually done through HLS, but are needed in Python for generating LUTs. For reasoning behind Softmax LUT, see Vivado implemenation, intemplates/vivado/nnet_utils/nnet_activation.h
.