PRF: Optimize binning in HGBT - #34248
Merged
Merged
Conversation
cakedev0
marked this pull request as ready for review
June 11, 2026 16:11
Contributor
Author
Some data to back-up this claim: on my laptop, it's 4x slower for 1 thread and 20x slower for 12 threads (for the cases that pass into the code path calling |
lorentzenchr
left a comment
Member
There was a problem hiding this comment.
Looks good. Some minor comments. In particular a missing test.
Comments improvement Co-authored-by: Christian Lorentzen <[email protected]>
Co-authored-by: Christian Lorentzen <[email protected]>
Co-authored-by: Christian Lorentzen <[email protected]>
Contributor
Author
|
Hi @lorentzenchr, I think this PR should be good to merge after a second review, right? |
ogrisel
approved these changes
Jun 24, 2026
Co-authored-by: Olivier Grisel <[email protected]>
Contributor
Author
|
Thx! I should really take the time to install and configure a spellchecker in VS-code 😅 I had that in my previous set-up... |
lorentzenchr
approved these changes
Jun 24, 2026
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 optimizes binning in histogram gradient boosting, specifically
_find_binning_thresholds.Closes #34304
Initial motivation
The weighted path is currently very slow for datasets with fewer than 200k samples because
_weighted_percentiledominates the binning time. For larger datasets, sample weights are consumed by subsampling, so this bottleneck does not apply in the same way.For example, on a 100k x 32 weighted dataset, binning takes more around 90% of the total fit time. The main issue is that the current implementation loops over percentiles and calls
_weighted_percentileonce per percentile. A single call to_weighted_percentileis still not that efficient, especially with many threads, so this PR adds a small local helper optimized for this use case.What does this implement/fix? Explain your changes.
This PR optimizes threshold computation by:
_weighted_percentile_1d_sortedhelper instead of_weighted_percentile;np.sortinstead ofnp.argsortfor the unweighted case;np.searchsorted;np.uniquewith a simple distinct-value mask on already sorted data.AI usage disclosure
I used AI assistance for:
Speed-up
Weighted datasets under 200k samples with more than 255 distinct values get the largest speed-ups. For small datasets the speed-up can be extremely large, and for a typical 100k x 32 dataset it is already around 100x.
For unweighted datasets:
Detailed benchmark results were produced with this benchmark script and this runner script. The tables report speed-up of this branch relative to
main.On a large machine:
On my laptop: