[SPARK-59247][ML] Optimize tree ensemble classification model transform closures - #58519
Open
zhengruifeng wants to merge 1 commit into
Open
[SPARK-59247][ML] Optimize tree ensemble classification model transform closures#58519zhengruifeng wants to merge 1 commit into
zhengruifeng wants to merge 1 commit into
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 reduces the transform closure size of
RandomForestClassificationModelandGBTClassificationModel. It is the tree-ensemble counterpart to #58454.The column-expression prediction hooks snapshot only the root nodes, tree weights, class count,
loss, and thresholds needed by each requested output column. Companion-object helpers perform raw
prediction and probability conversion without retaining the complete model. A shared
TreeEnsembleModelhelper similarly detaches leaf prediction from the model.Why are the changes needed?
The default probabilistic classifier hooks and existing leaf UDF invoke bound model methods. Their
closures therefore retain the complete model and parameter graph even though scoring only needs
the tree nodes and a small amount of immutable prediction state. This adds avoidable driver memory
pressure for long-lived Spark Connect servers.
Does this PR introduce any user-facing change?
No.
How was this patch tested?
The following check passed:
No new tests were added because the existing
testPredictMethodscoverage inRandomForestClassifierSuiteandGBTClassifierSuiteexercises all combinations of rawprediction, probability, and prediction columns.
A temporary local probe trained each model on the same deterministic dataset with 256 rows and
16 features. Both models used 20 trees; Random Forest used maximum depth 5 and GBT used maximum
depth 3. The probe extracted each
ScalaUDF.functionfrom the analyzed transform plan andserialized it with Spark's closure serializer. "All" is the sum of the raw-prediction,
probability, prediction, and leaf UDF closures.
Was this patch authored or co-authored using generative AI tooling?
Generated-by: Codex (GPT-5)