Skip to content

[SPARK-59052][ML] Reduce LinearSVCModel transform closure size and improve prediction performance - #58341

Draft
zhengruifeng wants to merge 3 commits into
apache:masterfrom
zhengruifeng:ml-spark-59052-linearsvc-closure-dev-4
Draft

[SPARK-59052][ML] Reduce LinearSVCModel transform closure size and improve prediction performance#58341
zhengruifeng wants to merge 3 commits into
apache:masterfrom
zhengruifeng:ml-spark-59052-linearsvc-closure-dev-4

Conversation

@zhengruifeng

@zhengruifeng zhengruifeng commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

This PR adds protected column-expression hooks to ClassificationModel for producing raw
predictions, converting raw predictions to labels, and predicting labels directly from features.
ClassificationModel.transform uses these hooks while retaining the existing UDF-based defaults.

LinearSVCModel overrides the hooks to snapshot only coefficients, intercept, and threshold in
its UDF closures. Raw-prediction-to-label conversion uses Spark column expressions, and the
model-capturing margin function 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:

Transform path Previous closure New closure Previous median New median
Raw prediction 38,268 B 34,627 B (-9.5%) 553.5 ms 527.1 ms (-4.8%)
Prediction only 38,206 B 34,580 B (-9.5%) 426.3 ms 229.2 ms (-46.2%)
Raw + prediction 76,552 B (2 UDFs) 34,627 B (1 UDF) (-54.8%) 818.8 ms 586.7 ms (-28.3%)

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/scalastyle
  • build/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)

@zhengruifeng zhengruifeng changed the title [SPARK-59052][ML] Reduce LinearSVCModel transform closure size [SPARK-59052][ML] Reduce LinearSVCModel transform closure size and improve prediction performance Aug 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant