Repository navigation
ENH software prefetching of bins in HGBT histogram building - #35526
Open
lorentzenchr wants to merge 3 commits into
Open
lorentzenchr wants to merge 3 commits into
lorentzenchr wants to merge 3 commits into
Conversation
The samples of a small node are scattered over the whole column of X_binned, so reading their bins is a gather with a cache miss for almost every sample. For large X_binned, prefetch the bins 128 samples ahead. Co-Authored-By: Claude Fable 5.2 <[email protected]>
Nodes with 1/8 or 1/4 of all samples were about 13% slower with prefetching. Co-Authored-By: Claude Fable 5.2 <[email protected]>
cakedev0
self-requested a review
November 26, 2026 06:57
This branch has not been deployed
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.
Reference Issues/PRs
Follow-up of #35441.
TLDR This PR makes HGBT faster by software prefetching (as does LightGBM).
What does this implement/fix? Explain your changes.
The samples of a small node are scattered over the whole column of
X_binned.Reading their bins is a gather with a cache miss for almost every sample, which
hardware prefetchers do not detect. On Higgs (8.8M x 28, 31 leaves), nodes with less
than 1/16 of the samples take about half of the histogram time.
This PR prefetches the bins 128 samples ahead in
_build_histogramand_build_histogram_no_hessian. It is only done if all of the following hold:X_binnedhas at least 2**17 rows (smaller columns fit into the CPU caches),sequentially),
LightGBM does the same in its column-wise histograms (distance 64, without
conditions), see
dense_bin.hpp.
Results are bit-wise identical to
main.Benchmarks
Intel Core i7-8559U (4 cores), macOS, clang, 4 threads, best of 2 alternating runs of
mainand this PR.Histogram computation alone, 2M x 28, time per node in ms:
Fit time in seconds:
python benchmarks/bench_hist_gradient_boosting_higgsboson.py --n-trees 100 --no-predict:fit 51.8 s -> 43.7 s, time spent computing histograms 35.0 s -> 28.5 s.
Benchmark script: histogram computation alone
Benchmark script: fit time
AI usage disclosure
I used AI assistance for:
I, Christian, reviewed the code changes and specifically instructed Claude to improve HGBT by prefetching.
Any other comments?
other hardware, in particular Apple Silicon and AMD, are very welcome.