[SPARK-59047][ML] Avoid retaining random forest tree weights - #58371
Closed
zhengruifeng wants to merge 1 commit into
Closed
[SPARK-59047][ML] Avoid retaining random forest tree weights#58371zhengruifeng wants to merge 1 commit into
zhengruifeng wants to merge 1 commit into
Conversation
HyukjinKwon
approved these changes
Aug 28, 2026
zhengruifeng
added a commit
that referenced
this pull request
Aug 28, 2026
### What changes were proposed in this pull request? Generate unit tree weights on demand for random forest classification and regression models instead of retaining a lazily initialized array. Cache the generated weights locally while saving an ensemble model to avoid repeated allocation in the per-tree loop. This also removes the stale comments about possibly supporting weighted random forests later. ### Why are the changes needed? Random forest tree weights are rarely accessed and are not used during prediction. Generating the unit weights when requested avoids retaining an otherwise unused array for the lifetime of the model. ### Does this PR introduce _any_ user-facing change? No. Random forest tree weights continue to contain one unit weight for every tree. ### How was this patch tested? The existing classification and regression model persistence tests were run: ``` build/sbt 'mllib/testOnly *RandomForestClassifierSuite -- -z "read/write"' build/sbt 'mllib/testOnly *RandomForestRegressorSuite -- -z "read/write"' ``` ### Was this patch authored or co-authored using generative AI tooling? Generated-by: OpenAI Codex (GPT-5) Closes #58371 from zhengruifeng/ml-spark-59047-tree-weights-dev-5. Authored-by: Ruifeng Zheng <ruifengz@apache.org> Signed-off-by: Ruifeng Zheng <ruifengz@foxmail.com> (cherry picked from commit 182f00c) Signed-off-by: Ruifeng Zheng <ruifengz@foxmail.com>
Contributor
Author
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?
Generate unit tree weights on demand for random forest classification and regression models instead
of retaining a lazily initialized array. Cache the generated weights locally while saving an
ensemble model to avoid repeated allocation in the per-tree loop.
This also removes the stale comments about possibly supporting weighted random forests later.
Why are the changes needed?
Random forest tree weights are rarely accessed and are not used during prediction. Generating the
unit weights when requested avoids retaining an otherwise unused array for the lifetime of the
model.
Does this PR introduce any user-facing change?
No. Random forest tree weights continue to contain one unit weight for every tree.
How was this patch tested?
The existing classification and regression model persistence tests were run:
Was this patch authored or co-authored using generative AI tooling?
Generated-by: OpenAI Codex (GPT-5)