Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Implement "everything follows X" for GridSearchCV - #33633

Merged
OmarManzoor merged 6 commits into
scikit-learn:mainfrom
betatim:array-api-gridsearch-follow-X
Jul 28, 2026
Merged

Implement "everything follows X" for GridSearchCV#33633
OmarManzoor merged 6 commits into
scikit-learn:mainfrom
betatim:array-api-gridsearch-follow-X

Conversation

@betatim

@betatim betatim commented Mar 25, 2026

Copy link
Copy Markdown
Member

What does this implement/fix? Explain your changes.

This implements the "everything follows X" story for GridSearchCV.

Noticed that this estimator doesn't do that and it looked like an easy fix.

A downside is that I added a "custom" test to check it works which will be redundant once we merge #33525

AI usage disclosure

I used AI assistance for:

  • Code generation (e.g., when writing an implementation or fixing a bug)
  • Test/benchmark generation
  • Documentation (including examples)
  • Research and understanding

Comment thread sklearn/model_selection/tests/test_search.py Outdated
Comment thread sklearn/model_selection/_validation.py Outdated
@betatim
betatim marked this pull request as ready for review March 25, 2026 15:31
@betatim

betatim commented Jul 22, 2026

Copy link
Copy Markdown
Member Author

Refreshed this PR. It is more of a small fix now then really implementing something new.

Could be an easy review.

cc @lucyleeow @virchan

@virchan virchan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks, @betatim!

@OmarManzoor, would you like to have a look and merge this?

@OmarManzoor

Copy link
Copy Markdown
Contributor

@betatim there is one failing test. Could you please check?

@betatim

betatim commented Jul 28, 2026

Copy link
Copy Markdown
Member Author

The failure happened because we use y.dtype.metadata['unique'] as a place to store unique values for numpy arrays. This short cut is cool, but it turns out when you convert a numpy array (with such metadata) to a cupy array the metadata is kept, but the type of the cached metadata isn't changed. So later on you end up mixing cupy and numpy arrays. I think the reason we run into this is because the two calls to attach_unique were not removed. It looks like github.com//pull/34221 remove all the other attach_unique calls but missed these two. So I removed them. This seems to fix things.

I added a new combination of "numpy" -> "cupy" to the mixed namespace test generator. This would have caught this bug before. But I could be convinced that we are starting down a slippery slope of combinatorics by doing this. The yield_mixed_namespace_input_permutations function is explicit about the fact that it does not want to yield all possible combinations because that would be too much. I think I'd add this case, because cupy does not strip the metadata, but torch does.

@OmarManzoor OmarManzoor left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thank you @betatim

@OmarManzoor
OmarManzoor merged commit 9ddf4d3 into scikit-learn:main Jul 28, 2026
43 checks passed
@lucyleeow

Copy link
Copy Markdown
Member

I added a new combination of "numpy" -> "cupy" to the mixed namespace test generator.

I think this is very reasonable. When we made the initial list, it was a best guess at what would encompass "all" cases.
Only thing I would think about is maybe adding a note in the yield_mixed_namespace_input_permutations docstring, about it also including a case of 2 different namespaces but both have the metadata attribute (for attach unique).

@betatim
betatim deleted the array-api-gridsearch-follow-X branch July 29, 2026 07:48
prady0t pushed a commit to prady0t/scikit-learn that referenced this pull request Sep 2, 2026
@jeremiedbb jeremiedbb mentioned this pull request Sep 8, 2026
14 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants