⚡️ Speed up function erfinv by 148% - #7
Open
codeflash-ai[bot] wants to merge 1 commit into
Open
Conversation
Here’s an optimized rewrite for your provided code. The current version is already fairly minimal, but calling `jax.lax.erf_inv` dispatches to JAX internals, and there is a slightly faster way by using `jax.scipy.special.erfinv`, which applies XLA fusion/matching and is the preferred interface for element-wise operations in JAX. Also, if you expect input arrays, using `@jax.jit` for Just-In-Time compilation will further optimize its runtime. Here’s the faster rewrite. **Key changes:** - Uses `jax.scipy.special.erfinv` for best-in-class performance and compatibility. - Decorated the function with `@jax.jit` for auto-compilation and faster repeated calls, especially for array inputs. Return values and signature are unchanged.
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.
📄 148% (1.48x) speedup for
erfinvinkeras/src/backend/jax/math.py⏱️ Runtime :
22.9 milliseconds→9.26 milliseconds(best of139runs)📝 Explanation and details
Here’s an optimized rewrite for your provided code. The current version is already fairly minimal, but calling
jax.lax.erf_invdispatches to JAX internals, and there is a slightly faster way by usingjax.scipy.special.erfinv, which applies XLA fusion/matching and is the preferred interface for element-wise operations in JAX. Also, if you expect input arrays, using@jax.jitfor Just-In-Time compilation will further optimize its runtime.Here’s the faster rewrite.
Key changes:
jax.scipy.special.erfinvfor best-in-class performance and compatibility.@jax.jitfor auto-compilation and faster repeated calls, especially for array inputs.Return values and signature are unchanged.
✅ Correctness verification report:
🌀 Generated Regression Tests Details
To edit these changes
git checkout codeflash/optimize-erfinv-max95krvand push.