Skip to content

Softmax LUT Optimization

Javier Duarte requested to merge github/fork/bo3z/softmax-lut-opt into main

Created by: bo3z

This PR exploits the following properties of the current Softmax implementation:

  1. For all inputs, the maximum is subtracted, before calculating the exponential. Therefore the exponential lookup table need only have entries for negative inputs.
  2. The sum of exponential is always positive. Therefore, the invert table need only have positive values, not negative.

The following plot shows the accuracy of hls4ml (old vs. new) compared to Keras at identifying argmax - the accuracy is identical for both implementations: acc

The following plot shows the mean absolute percentage error of hls4ml (old vs. new) compared to Keras's output - new version performs slightly better compared to the old one due to more "relevant" elements in the LUT: mape

Finally, the arrays holding the differences between the elements and the maximum is removed (as no significant accuracy was achieved), so resources were saved, as seen below: softmax_results

Merge request reports

Loading