Softmax update - #1494
Conversation
| def __write_exp_table(self, model, path): | ||
| table_name = 'exp_table' | ||
| table_size = self.__get_table_size(model, 'softmax') | ||
| def __get_table_precision(self, model, activation, table_name='table_precision'): |
| real_val = f.exp_float() | ||
| h_file.write(sep + str(real_val)) | ||
| sep = ', ' | ||
| # Default fixed point precision |
There was a problem hiding this comment.
There is no need for default here.
There was a problem hiding this comment.
That was a redundant code from old version that i forgot to remove.
| h_file.close() | ||
| # Exp table should use the same precision as exp_table, as seen in Vivado code | ||
| # init_exp_table<data_T, CONFIG_T>(exp_table); | ||
| for layer in model.get_layers(): |
There was a problem hiding this comment.
Why loop again for layers here within the loop for layers on line 824? This looks like a bug.
There was a problem hiding this comment.
This was from the old version that i forgot to remove, now removed the inner loop and fixed it.
|
|
||
| h_file.write('};\n') | ||
| h_file.close() | ||
| # Exp table should use the same precision as exp_table, as seen in Vivado code |
There was a problem hiding this comment.
I don't understand the comment, that the exp table should use the same precision as exp table. Isn't that true inherently?
There was a problem hiding this comment.
This also was from the previous version, irrelevant in our case
| sep = ', ' | ||
| # Default fixed point precision, in case values from layer attributes cannot be extracted | ||
| # 8 bits for integer part, 10 bits for decimal - total, 18 | ||
| fp_bits = 18 |
There was a problem hiding this comment.
Again I don't think you need defaults here.
| h_file.close() | ||
| # Invert table should use the same precision as exp_table, as seen in Vivado code | ||
| # init_invert_table<typename CONFIG_T::exp_table_t, CONFIG_T>(invert_table); | ||
| for layer in model.get_layers(): |
There was a problem hiding this comment.
And again a layer loop inside of a layer loop.
Description
The softmax table generation logic was updated. The implementation for writing the softmax tables was revised, and memory attributes were added to enable a more efficient FPGA compilation flow. In addition, the templates were modified to use weights directly from the configuration.
The primary motivation for these changes was to bring the oneAPI backend closer to the Vivado backend in terms of implementation.
Memory attributes were added to enable memory banking on the FPGA, allowing for more efficient memory access. The weights are now copied directly into the configuration so that the compiler can recognise the entire table as a set of fixed values. This enables the memory to be implemented more efficiently, resulting in improved resource utilisation during FPGA compilation.
N/A
Type of change
For a new feature or function, please create an issue first to discuss it
with us before submitting a pull request.
Note: Please delete options that are not relevant.
Tests
The changes were primarily verified using black-box tests on an isolated softmax unit. Testing was performed for both quantised and non-quantised implementations. For the quantised version, both configurations, with and without exp and inv table quantisers (QuantiserConfig(...)), were tested.
Additional testing included:
This PR currently supports only the Intel oneAPI compiler. Support for the Altera HLS compiler will be added in a future PR.
The implementation was also evaluated with different table sizes, and the resulting RTL reports were inspected to verify improvements in resource utilisation.
A Python test file and a Keras model containing only a single softmax layer (Softmax or QSoftmax) were used. For the quantised implementation, the input and output quantisers for the exp and inv lookup tables were configured using QuantiserConfig(...). Tests were run with both the quantisers enabled and disabled.
The test configuration included:
Test Configuration:
Checklist
pre-commiton the files I edited or added.