Skip to content

[SPARK-59047][ML] Avoid retaining random forest tree weights - #58371

Closed
zhengruifeng wants to merge 1 commit into
apache:masterfrom
zhengruifeng:ml-spark-59047-tree-weights-dev-5
Closed

[SPARK-59047][ML] Avoid retaining random forest tree weights#58371
zhengruifeng wants to merge 1 commit into
apache:masterfrom
zhengruifeng:ml-spark-59047-tree-weights-dev-5

Conversation

@zhengruifeng

Copy link
Copy Markdown
Contributor

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)

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>
@zhengruifeng

Copy link
Copy Markdown
Contributor Author

Merge Summary:

Posted by merge_spark_pr.py

@zhengruifeng
zhengruifeng deleted the ml-spark-59047-tree-weights-dev-5 branch August 28, 2026 05:54
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.

2 participants