Upstream/fast gelu - #53
Open
DrJesseGlass wants to merge 3 commits into
Open
Conversation
The scalar Gelu path spends nearly all its time in one libm tanh call per element; encoder-style models run tens of millions of GELUs per image. This adds a NEON f32_vec override for Gelu on aarch64 (when neither mkl nor accelerate provide one): tanh via the Eigen-style rational approximation x*P(x^2)/Q(x^2), clamped and saturating exactly to +-1 outside +-7.9053111 so gelu(x) is exactly x / exactly 0 for large inputs. Max error <= 2e-6 vs libm across a full sweep (unit test included) - considerably tighter than the f16 lookup table other CPU inference stacks use for GELU. CANDLE_FAST_GELU=0 restores the exact libm path for bit-reproducibility. Measured on Granite-Docling's SigLIP encoder (12 layers, 3.1M GELU/layer, Apple M1 4 threads): encoder step 971 -> 905 ms.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.