Skip to content

Fix arm_softmax_s16 normalization and output saturation - #249

Merged
mansnils merged 3 commits into
ARM-software:mainfrom
vera-rubin:fix/softmax-s16-boundaries
Nov 5, 2026
Merged

mansnils merged 3 commits into
ARM-software:mainfrom
vera-rubin:fix/softmax-s16-boundaries

Conversation

@vera-rubin

@vera-rubin vera-rubin commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

arm_softmax_s16 could double outputs at a normalization boundary and wrap a one-class result. We use unsigned normalization arithmetic and clamp the reciprocal input and final output. The regression and all softmax Unity tests pass with the normal Release CMake build.

Fixes #248

— ChipLab

@mansnils mansnils left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!
Could you leave the Arm copyright years, as it is given you are not Arm employee?

@vera-rubin

Copy link
Copy Markdown
Contributor Author

@mansnils Arm copyright years restored. We switched to your int32 expression (identical for all reachable inputs, tested).

— ChipLab

@mansnils

mansnils commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Thank you and sorry for the delay. Can you make datasets reproducible through existing generators and TFL/TFLM reference kernels following unit test conventions (Tests/UnitTest/README.md:147)?

Replace the hand-written boundary arrays in test_arm_softmax_s16.c with
three generated test sets. SoftmaxSettings takes an optional input_data
argument so a set can use fixed inputs; the expected outputs come from
the TFL reference kernel, and a rerun of the generator gives identical
headers.

- softmax_s16_sum_boundary: one row whose exp sum is 262142, the largest
  sum whose normalized reciprocal input still fits in int16, and one at
  262143, where the normalization overflowed before this fix.
- softmax_s16_equal_inputs: two equal inputs, each output exactly one half.
- softmax_s16_single_input: one input, the output saturates at INT16_MAX.
@vera-rubin

Copy link
Copy Markdown
Contributor Author

@mansnils Done: the hand-written arrays are replaced by three softmax s16 sets from generate_test_data.py with fixed inputs (a rerun gives identical headers), and the expected outputs come from the TFL reference kernel. sum_boundary puts the exp sum just below and exactly at the point where the old normalization overflowed, and equal_inputs and single_input cover the other two cases. The old kernel fails the overflow row and the single-input set, and the fixed one passes all softmax s16 sets. I added an optional input_data argument to SoftmaxSettings for the fixed inputs; happy to move it if you'd prefer another place.

@mansnils
mansnils merged commit 346be27 into ARM-software:main Nov 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: arm_softmax_s16 doubles outputs at a normalization boundary and wraps one-class output

2 participants