⚡️ Speed up function batched_squared_norm by 19%#30
Open
codeflash-ai[bot] wants to merge 2 commits intomainfrom
Open
⚡️ Speed up function batched_squared_norm by 19%#30codeflash-ai[bot] wants to merge 2 commits intomainfrom
batched_squared_norm by 19%#30codeflash-ai[bot] wants to merge 2 commits intomainfrom
Conversation
### Key Changes. 1. **Optimization in `batched_dot_product`**. - Kept the function structure the same to maintain compatibility. - Use `x.mul(y)` instead of `x * y` to make it explicit and potentially more optimized within Tensor libraries that have optimized `mul` implementations. 2. **Optimization in `batched_squared_norm`**. - Used `x.square()` to directly compute the element-wise squares more efficiently, and immediately followed by summation with `sum(dim=-1, keepdim=keepdim)`. This reduces the number of dot product operations and leverages faster library-level operations. By focusing on using efficient tensor operations, these changes ensure faster execution times by reducing overhead and leveraging underlying optimized mathematical operations provided by the tensor library being used.
dasarchan
approved these changes
Mar 27, 2025
|
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs within 7 days. Thank you for your contributions! |
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.
📄 19% (0.19x) speedup for
batched_squared_norminkornia/geometry/linalg.py⏱️ Runtime :
279 microseconds→235 microseconds(best of219runs)📝 Explanation and details
Key Changes.
Optimization in
batched_dot_product.x.mul(y)instead ofx * yto make it explicit and potentially more optimized within Tensor libraries that have optimizedmulimplementations.Optimization in
batched_squared_norm.x.square()to directly compute the element-wise squares more efficiently, and immediately followed by summation withsum(dim=-1, keepdim=keepdim). This reduces the number of dot product operations and leverages faster library-level operations.By focusing on using efficient tensor operations, these changes ensure faster execution times by reducing overhead and leveraging underlying optimized mathematical operations provided by the tensor library being used.
✅ Correctness verification report:
🌀 Generated Regression Tests Details
To edit these changes
git checkout codeflash/optimize-batched_squared_norm-m8oca7quand push.