[WIP][ML] Avoid per-leaf map for tree predictions#57389
Draft
zhengruifeng wants to merge 2 commits into
Draft
Conversation
Contributor
Author
|
Memory estimate for the leaf-prediction path (measured with JOL on Java 11 / Scala 2.13, with compressed references):
This is approximately 40-45 bytes per leaf, or 40-45 MiB for one million leaves, on this JVM. The actual number will vary with JVM and Scala collection implementation. The normal |
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?
Replace the transient
Map[LeafNode, Int]used by tree leaf prediction with a normal integerfield on each
LeafNode. Tree-model construction assigns the same left-to-right DFS indicesafter training and loading, so prediction only traverses the tree and reads the reached leaf's
stored ID. The existing
NodeDataformat deliberately omits this field, while broadcastserialization retains it.
Why are the changes needed?
Large trees can have many leaves. When leaf prediction is used, the map creates a hash-table
entry and boxed value for every leaf in each executor's model copy. A single integer per leaf
keeps the lookup constant-time while substantially reducing the memory overhead and avoids
building an executor-side lookup cache.
Does this PR introduce any user-facing change?
No. Leaf IDs and their traversal order are unchanged.
How was this patch tested?
Added persistence assertions that verify classifier and regressor leaf IDs are unchanged after
loading. Tests have not been run yet; the relevant ML suites will be run before this draft is
marked ready for review.
Was this patch authored or co-authored using generative AI tooling?
Generated-by: Codex (GPT-5)