Raise if fit and predict use different array API namespaces or devices (continued) - #33076
Conversation
Co-authored-by: Olivier Grisel <[email protected]>
…edockes/scikit-learn into check-fitted-same-namespace-device
|
I pushed my merge conflict resolution commit without running the tests locally. Sorry for that. I am on it. |
ogrisel
left a comment
There was a problem hiding this comment.
LGTM (if CI is green after my pass few commits).
| yield partial( | ||
| check_array_api_same_namespace, | ||
| array_namespace="array_api_strict", | ||
| ) |
There was a problem hiding this comment.
It's good to only test with array_api_strict for this to keep time cost bounded. There is no reason for this to depend on the kind of namespace.
| run: | | ||
| source "${HOME}/conda/etc/profile.d/conda.sh" | ||
| conda activate sklearn | ||
| cd doc |
There was a problem hiding this comment.
For some reason, this is necessary, because otherwise it would try to import from the unbuilt sklearn source folder.
There was a problem hiding this comment.
I don't fully understand it either, in build_tools/github/test_docs.sh we also use this "one weird trick they don't want you to know"
|
@OmarManzoor @virchan merge? |
OmarManzoor
left a comment
There was a problem hiding this comment.
LGTM. Thank you @betatim
Co-authored-by: Omar Salman <[email protected]>
|
Thanks for the reviews, I turned on automerge |
| # XXX Do we need this? What else could the custom logic do that wouldn't work | ||
| # with the default logic? |
There was a problem hiding this comment.
@betatim just checking, is this comment meant to remain? Is this questioning the need for the line self.converted_ = True ?
Not sure how realistic but would a e.g., NamedTuple attribute work? Since we do: estimator_type in (list, tuple, set, frozenset)
There was a problem hiding this comment.
Wasn't planning on leaving it in, but only if we resolved the question.
What it is asking is "what is a somewhat realistic thing the custom array API conversion logic could do?" For now it just sets some arbitrary estimator fitted attribute, but that seems totally "weird"/we wouldn't see this in the real world.
So the comment is more about my lack of imagination than anything else.
Given it has now been merged I'd leave it until we can come up with a better example.
Reference Issues/PRs
Continuation of #29313
What does this implement/fix? Explain your changes.
This PR adds
_array_api.check_same_namespaceto raise an error if the array namespace used duringfitandpredict/transformdo not match, and_array_api.convert_estimatorto move the array attributes of an estimator to the namespace and device of a reference array. Eventually we should putconvert_estimatorin a public part of the API, because users should use it. For now I think it is Ok to have it insklearn.utils._array_apias things are still experimental.A change I've made compared to #29313 is that none of our library code turns on
sklearn.set_config(array_api_dispatch=True)for its run (original version in #29313). I think this makes sense because users should opt-in themselves. But it does open up the question of what exactly should happen if you useconvert_estimatoron an estimator without turning on array API support in scikit-learn. My thinking is there should be an exception to let people know they are doing something weird.AI usage disclosure
There were quite a few merge conflicts which Cursor managed to resolve and it managed to figure out how to change from the old "what's new" system to the new one once I explained that there is a README to read.
I used AI assistance for: