Repository navigation
MNT Refactor/Improve features sampling in HGB splitting - #34786
Conversation
ogrisel
left a comment
There was a problem hiding this comment.
LGTM. I agree that it's having parallel loops with more homogeneous workloads should help optimize the thread-scalability in subsequent PRs.
Another benefit: I find the code easier to reason about this way.
| subsample_mask = subsample_mask_arr | ||
|
|
||
| if has_interaction_cst: | ||
| split_features = self.rng.choice( |
There was a problem hiding this comment.
If I'm not mistaken, this can lead to different features being selected than the previous shuffling, so we probably need to mention this in a changelog here.
There was a problem hiding this comment.
Actually, after discussing with @ogrisel last week, I realized this was not a good idea: it introduce some kind of behavior discontinuity:
- max_features=1. => features are considered in order
- max_features=1. - eps => features are shuffled.
I added a sort after rng.choice to preserve behavior.
There was a problem hiding this comment.
That sounds reasonable. But the trees can still differ in terms of which features are selected for feature_fraction_per_split < 1.0 between the masking approach in main and the sampling in this PR, right?
There was a problem hiding this comment.
Ah yes, I can mention this in a changelog.
We have a small imperfect heuristic: if a test file was changed in the PR, it probably means that it's a user facing change and that a changelog is needed, otherwise we don't require a changelog. See scikit-learn/.github/workflows/check-changelog.yml Lines 20 to 29 in e03bc6e As many things, it could probably be improved but maybe good enough for now 🤷 |
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Changelog added, let's merge once CI is green. |
Reference Issues/PRs
Will help in implementing strategy 4 described in #34764 (comment)
What does this implement/fix? Explain your changes.
It changes the features subsampling of HGB (when
max_features < 1.0): instead of a boolean mask, it samples without replacement.It has two benefits:
prange(..., schedule="static"), which will help for future scalability heuristic I'm working onmax_features < 1.0), as it randomized the order in which features are split (and we use > in the loop).The effect on runtime is not visible as far as I could experiment, even in extreme cases where split time is dominant. But I think it should be visible in some (relatively rare) cases once combine with the "use_threads_if" heuristic as it allow having a more accurate estimate of the work to do.
There is no added complexity so it's worth the PR/merge I'd say.
AI usage disclosure
Very guided session, I had a precise idea of what I wanted.