Skip to content

PRF Split HGB early stopping data after binning - #35182

Draft
cakedev0 wants to merge 4 commits into
scikit-learn:mainfrom
cakedev0:hgb-split-after-binning
Draft

cakedev0 wants to merge 4 commits into
scikit-learn:mainfrom
cakedev0:hgb-split-after-binning

Conversation

@cakedev0

Copy link
Copy Markdown
Member

Reference Issues/PRs

Third part of the split of #35162. Independent of the other parts, based on main.

What does this implement/fix? Explain your changes.

With early stopping on the internal validation split, HGB used to split X, then bin both parts. Now it splits the sample indices, bins X once (the bin mapper is fitted on the training samples only, via a new sample_indices parameter of _BinMapper.fit) and then splits the binned data.

This avoids a float64 copy of X: the binned data is 8 times smaller. This is very beneficial when using HGB under *SearchCV as it reduces a lot the risk of OOM when using n_jobs=-1 (which is very often the best option for speed, but is expensive in memory).

AI usage disclosure

I used AI assistance for:

  • Code generation
  • Test/benchmark generation
  • Documentation (changelogs)

Benchmarks

HGB fit, early stopping with the internal validation split, 20 iterations:

n × d fit time (main → this PR) peak RSS above X (main → this PR)
1M × 20 0.77 → 0.73 s 260 → 112 MB
1M × 100 2.49 → 2.24 s 1015 → 261 MB
3M × 50 4.12 → 3.90 s 1498 → 364 MB

cakedev0 and others added 4 commits October 19, 2026 18:21
Only split the sample indices, fit the bin mapper on the training samples
and split the binned data. This avoids a float64 copy of X.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@itamarst

Copy link
Copy Markdown
Contributor

FWIW it's quite nice to have test infrastructure allowing to make assertions about peak memory usage... but also somewhat tricky.

Something like this works if all libraries involved use Python's memory allocators. NumPy does, at least, not sure about other sklearn dependencies though: https://github.com/itamarst/polars/blob/2cb081d9fe2e306732585dafb090f503fb7dc56e/py-polars/tests/unit/conftest.py#L146-L176

@ogrisel

ogrisel commented Oct 21, 2026

Copy link
Copy Markdown
Member

As discussed IRL, I am wondering if such an optimization will be easy to adapt to a potential feature refactoring of the early stopping feature based on callbacks. I haven't thought it through yet.

@cakedev0

Copy link
Copy Markdown
Member Author

I am wondering if such an optimization will be easy to adapt to a potential feature refactoring of the early stopping feature based on callbacks.

I'll put it back to draft while I haven't investigated that. I plan to dive a bit in callbacks at some point, I'll do it at this time.

@cakedev0
cakedev0 marked this pull request as draft October 22, 2026 14:36
@cakedev0 cakedev0 moved this from PR waiting for reviews to PR Stalled in Labs Oct 26, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants