[SPARK-59052][ML] Reduce LinearSVCModel transform closure size and improve prediction performance - #58341
Draft
zhengruifeng wants to merge 3 commits into
Draft
Conversation
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 protected column-expression hooks to
ClassificationModelfor producing rawpredictions, converting raw predictions to labels, and predicting labels directly from features.
ClassificationModel.transformuses these hooks while retaining the existing UDF-based defaults.LinearSVCModeloverrides the hooks to snapshot only coefficients, intercept, and threshold inits UDF closures. Raw-prediction-to-label conversion uses Spark column expressions, and the
model-capturing
marginfunction field is removed.Why are the changes needed?
The previous transform implementation built UDFs from bound model methods. This serialized the
entire model into each closure and performed parameter lookup for every input row. The hooks let
classification models provide compact closures or native Spark expressions without changing
prediction behavior.
An in-process comparison used 4,096-feature models for closure serialization and 3,000,000 cached
rows with 32 features for 20 alternating execution measurements:
The temporary benchmark probe was removed after measurement.
Does this PR introduce any user-facing change?
No.
How was this patch tested?
build/sbt mllib/scalastylebuild/sbt 'mllib/testOnly org.apache.spark.ml.classification.LinearSVCSuite'(16 tests passed; 1 pre-existing test ignored)
Was this patch authored or co-authored using generative AI tooling?
Generated-by: Codex (GPT-5)