Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed-point Softmax() calls exp_on_negative_values() twice #3055

Open
cousteaulecommandant opened this issue Feb 27, 2025 · 0 comments
Open

Comments

@cousteaulecommandant
Copy link

Fixed-point Softmax() calls exp_on_negative_values() twice per element: once to calculate the value of the exp of each element

FixedPoint0 exp_in_0 = exp_on_negative_values(scaled_diff_f8);

and another one a few lines earlier to calculate the sum of all exps
sum_of_exps = sum_of_exps + gemmlowp::Rescale<kAccumulationIntegerBits>(
exp_on_negative_values(scaled_diff_f8));

The exp_on_negative_values() function is rather slow, taking most of the time of Softmax(), so calling it twice per element makes the whole Softmax() function be about twice as slow as necessary.

Could this be optimized so that it is only called once per element? Store the exp results in a temporary array (for example, reusing output_data), computing the sum as they're stored, and then applying the scaling to the precomputed exp results rather than computing them again.

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

No branches or pull requests

1 participant