Repository navigation
fix: Increase inverse softmax LUT resolution to reduce argmax flips (closes #1512) - #1513
botbikamordehai2-sketch wants to merge 2 commits into
Conversation
|
@botbikamordehai2-sketch thank you for the quick PR, One note: my reproduction script uses a standard Keras Could you confirm whether this PR also addresses the |
|
pre-commit.ci autofix |
|
This diverges from the configured precision in the qat model, and you won't get the same results seen at qat though. |
|
The conclusion is that this would lead to a regression in performance for models trained using QAT in HGQ2, and is therefore not desired. Softmax performance is being improved by other PRs such as #1542 instead. |
What
In hls4ml 1.3.0, converting models with a softmax output layer to HLS can cause a large fraction of argmax classification decisions to differ from the float32 reference, despite correctly normalized probabilities (Σp = 1). The issue is traced to the softmax LUT approximation in the QSoftmax converter, which for some weight distributions has insufficient resolution in the inverse (1/exp) table.
Fix
Ensure that the input fixed-point precision for the inverse table has at least 16 bits of total width, which provides sufficient LUT entries to accurately represent exp(-x) across a wide range of inputs. The patch modifies the QSoftmaxHandler to upgrade the inverse table input precision to at least 16 bits when the original width is smaller. This is a minimal change that affects only the LUT resolution and should reduce argmax flips without breaking normalization.
Closes #1512