Optimize Scikit-learn model loading by adding Bulk Tree Construction API #651
Open
dantegd wants to merge 2 commits intodmlc:mainlinefrom
Open
Optimize Scikit-learn model loading by adding Bulk Tree Construction API #651dantegd wants to merge 2 commits intodmlc:mainlinefrom
dantegd wants to merge 2 commits intodmlc:mainlinefrom
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## mainline #651 +/- ##
============================================
- Coverage 84.35% 83.73% -0.63%
============================================
Files 75 76 +1
Lines 6653 6927 +274
Branches 543 561 +18
============================================
+ Hits 5612 5800 +188
- Misses 1041 1127 +86 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
hcho3
requested changes
Jan 7, 2026
Collaborator
There was a problem hiding this comment.
Can we go ahead and simply remove the old sklearn model builder functions? So LoadSKLearnRandomForestRegressorBulk should be simply called LoadSKLearnRandomForestRegressor, etc.
I don't see a good reason to keep the old functions around, if the new functions are equivalent in functionalities but faster.
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.
This PR introduces a bulk tree construction API that significantly improves performance when importing scikit-learn RandomForest models into Treelite. In my benchmarks, the new API achieves ~7-10x speedup over the existing node-by-node construction approach of the current sklearn loader.
The current implementation spends significant time in per-node overhead due to:
This becomes a bottleneck in workflows like cuML's
RandomForestClassifier.from_sklearn(), where treelite import time dominates the conversion process.This PR implements a
BulkConstructTreefriend function that directly populates the Tree class's internal ContiguousArray members in a single pass, bypassing theModelBuilderabstraction for sklearn imports.Initial benchmarks: