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

Add fast tanh and fast sigmoid to LSTM #43

Merged
merged 1 commit into from
May 27, 2023

Conversation

mikeoliphant
Copy link
Contributor

This PR adds fast tanh and fast sigmoid activation for LSTM models. It keys off of the enable_fast_tanh()/disable_fast_tanh() methods.

My testing indicates around a 40% performance improvement for LSTM models.

Copy link
Owner

@sdatkinson sdatkinson left a comment

Choose a reason for hiding this comment

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

LGTM! 👍🏻

@@ -32,6 +32,12 @@ inline float fast_tanh(const float x)
/ (2.44506634652299f + (2.44506634652299f + x2) * fabsf(x + 0.814642734961073f * x * ax)));
}

inline float fast_sigmoid(const float x)
{
return 0.5f * (fast_tanh(x * 0.5f) + 1.0f);
Copy link
Owner

Choose a reason for hiding this comment

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

Looks correct ✅

@@ -6,6 +6,8 @@ activations::ActivationHardTanh _HARD_TANH = activations::ActivationHardTanh();
activations::ActivationReLU _RELU = activations::ActivationReLU();
activations::ActivationSigmoid _SIGMOID = activations::ActivationSigmoid();

bool activations::Activation::using_fast_tanh = false;
Copy link
Owner

Choose a reason for hiding this comment

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

I guess this is a separate but non-conflicting way to do this, then? FWIW, I think I'm happy to have it be global like this 👍🏻

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess this is a separate but non-conflicting way to do this, then?

Because the LSTM code calls the activation functions directly (since it is operating on individual weights), it needed a flag to key off of.

@sdatkinson sdatkinson merged commit 0dc9283 into sdatkinson:main May 27, 2023
@mikeoliphant mikeoliphant deleted the lstm_fast_activation branch June 16, 2023 19:40
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