Skip to content

Fix stable softmax exp_table indexing sign-bit inefficiency#1480

Closed
niteshg97 wants to merge 2 commits into
fastmachinelearning:mainfrom
niteshg97:niteshg97-patch-1
Closed

Fix stable softmax exp_table indexing sign-bit inefficiency#1480
niteshg97 wants to merge 2 commits into
fastmachinelearning:mainfrom
niteshg97:niteshg97-patch-1

Conversation

@niteshg97
Copy link
Copy Markdown

Fix stable softmax LUT indexing to avoid wasting the sign bit for nonnegative normalized inputs.

Description

Problem:-

the stable softmax implementation computes x_max - x_i, which is guaranteed to be nonnegative, however, the existing LUT indexing helper slices the sign bit as part of the exp_table address generation, reducing effective LUT utilization and precision.

Fix:-

Introduce a specialized unsigned lookup indexing helper for stable softmax inputs and use it only in the stable softmax path.,

this preserves existing behavior for latency and legacy implementations while improving LUT address utilization for stable softmax.

niteshg97 added 2 commits May 23, 2026 12:33
Stable softmax computes x_max - x_i, which is guaranteed nonnegative.
Skip the sign bit when generating exp_table lookup indices
to avoid wasting half of the LUT address space.
@jmitrevs
Copy link
Copy Markdown
Contributor

jmitrevs commented May 23, 2026

Note that we also have #1476. Does that fix the issues you are looking at? With that PR the default values become unsigned.

@niteshg97
Copy link
Copy Markdown
Author

Note that we also have #1476. Does that fix the issues you are looking at? With that PR the default values become unsigned.

Thanks for pointing that out, i took a look at #1476, and it seems like the changes to the stable softmax type handling might already cover the sign-bit indexing issue I was trying to fix here.

Also, it looks like the GitLab failures were already present before this PR, so I’ll wait for your guidance on whether this change still adds anything on its own or if #1476 already fully addresses it.

@jmitrevs
Copy link
Copy Markdown
Contributor

I think it's best to use an unsigned type for the unsigned value and not a signed type and ignore the sign bit. So I'll close this PR.

@jmitrevs jmitrevs closed this May 23, 2026
@niteshg97
Copy link
Copy Markdown
Author

I think it's best to use an unsigned type for the unsigned value and not a signed type and ignore the sign bit. So I'll close this PR.

that makes sense..... using an unsigned type directly for values that are always nonnegative is definitely a cleaner approach than handling the sign bit during indexing, thanks for the clarification and for taking the time to review the PR.

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.

2 participants