[SPARK-59563][ML] Use BLAS routines for vector L1 and L2 norms - #58849
Open
zhengruifeng wants to merge 2 commits into
Open
zhengruifeng wants to merge 2 commits into
zhengruifeng wants to merge 2 commits into
Conversation
zhengruifeng
marked this pull request as ready for review
September 16, 2026 12:38
zhengruifeng
marked this pull request as draft
September 16, 2026 12:39
zhengruifeng
marked this pull request as ready for review
September 16, 2026 15:21
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.
What changes were proposed in this pull request?
This PR adds
BLAS.asum(Vector)andBLAS.nrm2(Vector)to both ML and MLlib and uses them forL1 and L2 vector norms. Dense vectors pass their backing arrays to BLAS, while sparse vectors pass
only their stored values.
Why are the changes needed?
The existing Scala loops do not use the SIMD BLAS implementation available to Spark.
On an Intel Xeon Platinum 8375C with JDK 17 and
VectorBLAS, a local benchmark measured thesespeedups over the existing Scala loops:
Dense and sparse vectors had equivalent results for the same stored-value count.
Does this PR introduce any user-facing change?
No. This replaces the internal norm loops with equivalent BLAS routines.
How was this patch tested?
Ran the existing dense and sparse vector norm coverage:
All 76 tests passed (36 in
mllib-local, 40 inmllib). The performance results above weremeasured with a temporary Spark
Benchmarkharness that compared the previous loops withVectors.norm; the harness is not included in this PR.Was this patch authored or co-authored using generative AI tooling?
Generated-by: Codex (GPT-5)