You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Expose get_namespace_and_device and move_estimator_to in public API #34135
This issue is not yet ready for a PR. If you are interested in contributing to scikit-learn, please have a look at our contributing guidelines, and in particular the sections for new contributors and the "Needs triage" label.
I just stumbled over the error message of the new ValueError added in #33076:
ValueError: Inputs passed to LinearRegression.predict() must use the same namespace and the same device as those passed to fit(). Array namespaces used during fit (sklearn.externals.array_api_compat.numpy) and predict (sklearn.externals.array_api_compat.torch) differ. You can move the estimator to the same namespace and device as X with: 'from sklearn.utils._array_api import move_estimator_to; xp, _, device = get_namespace_and_device(X); estimator = move_estimator_to(estimator, xp, device)'
I am wondering why move_estimator_to and get_namespace_and_device are not exposed in the public API then. Did we forget to do that or was that a conscious choice? (I tried to find discussion on that but couldn't find any.)
If we expose both methods in the API, users can access the docstrings from the website and import via from sklearn.utils import move_estimator_to, get_namespace_and_device.
Also, we may want to expose get_namespace and get_device, though I don't find that so important.
Clarifying if these two methods were not added to the API on purpose or by accident may be of interest for the 1.9 release.
CC @betatim@ogrisel@jeremiedbb
This is definitely something we need to tackle on our way to #33444.
I think move_estimator_to (and maybe move_to) should be public.
I think we could keep sklearn.utils._array_api.get_namespace_and_device private and instead recommend using the array_api_compat.array_namespace and array_api_compat.device which are already public (but would require scikit-learn users to add a dependency or vendor array-api-compat to/in their own project).
Alternatively, we could expand move_estimator_to to accept being called as move_estimator_to(estimator, X) in addition to move_estimator_to(estimator, xp=xp, device=device) and then we can simplify the recommendation in the exception message and not have to make sklearn.utils._array_api.get_namespace_and_device public.
I like the idea of changing to move_estimator_to(estimator, X). That feels like the better API for users.
The reason these functions live in a private namespace at the moment is that we thought this is a good way to signal that they are part of the experimental nature of array API. For example, it allows us to change the signature of move_estimator_to without deprecation cycles. So my immediate thought is that we should keep them "private" or use a different way of marking them as experimental (use the sklearn.experimental namespace??) until we make array API support generally available.
The reason these functions live in a private namespace at the moment is that we thought this is a good way to signal that they are part of the experimental nature of array API.
Okay, then we're not in a rush for the 1.9 release. That's wonderful. :)
I also like the move_estimator_to(estimator, X) idea.
I think we should keep them private as long as possible and only open a PR to make move_estimator_to public once all the other items of #33444 have been fixed.
But we can already open a PR to implement support for move_estimator_to(estimator, X) and update the exception message to simplify it without making that function public since people feel that this would result in a net usability improvement.
Reacted by Stefanie Senger, Tim Head, Virgil Chan and Lucas Colley
Hi @SahilKumar75, we don't need genAI suggestions here, because these are areas where you need a lot of context knowledge about internal decisions we had discussed before and the directions and next steps that we want to take in Array API. Not sure if your input helps here. Also, @ogrisel had already suggested an action that four people that are longtime concerned with Array API posted a thumps up to.
Activity
StefanieSenger commentedon May 28, 2026
Clarifying if these two methods were not added to the API on purpose or by accident may be of interest for the 1.9 release.
CC @betatim @ogrisel @jeremiedbb
ogrisel commentedon May 28, 2026
This is definitely something we need to tackle on our way to #33444.
I think
move_estimator_to(and maybemove_to) should be public.I think we could keep
sklearn.utils._array_api.get_namespace_and_deviceprivate and instead recommend using thearray_api_compat.array_namespaceandarray_api_compat.devicewhich are already public (but would require scikit-learn users to add a dependency or vendorarray-api-compatto/in their own project).Alternatively, we could expand
move_estimator_toto accept being called asmove_estimator_to(estimator, X)in addition tomove_estimator_to(estimator, xp=xp, device=device)and then we can simplify the recommendation in the exception message and not have to makesklearn.utils._array_api.get_namespace_and_devicepublic.StefanieSenger commentedon May 28, 2026
Yes, that's a good plan (both alternatives).
And do we want to make
move_estimator_topublic in 1.9? We mention it in the changelog (doc/whats_new/v1.9.rst), but it doesn't get rendered like API because we did not expose it, see: https://scikit-learn.org/dev/whats_new/v1.10.html (link will change path to https://scikit-learn.org/dev/whats_new/v1.9.html in a few days). Because of that in the error message mentioned above, we give users an private import path.I propose to expose
move_estimator_tofor the release.betatim commentedon May 28, 2026
I like the idea of changing to
move_estimator_to(estimator, X). That feels like the better API for users.The reason these functions live in a private namespace at the moment is that we thought this is a good way to signal that they are part of the experimental nature of array API. For example, it allows us to change the signature of
move_estimator_towithout deprecation cycles. So my immediate thought is that we should keep them "private" or use a different way of marking them as experimental (use thesklearn.experimentalnamespace??) until we make array API support generally available.StefanieSenger commentedon May 28, 2026
Okay, then we're not in a rush for the 1.9 release. That's wonderful. :)
I also like the
move_estimator_to(estimator, X)idea.ogrisel commentedon May 28, 2026
I think we should keep them private as long as possible and only open a PR to make
move_estimator_topublic once all the other items of #33444 have been fixed.But we can already open a PR to implement support for
move_estimator_to(estimator, X)and update the exception message to simplify it without making that function public since people feel that this would result in a net usability improvement.SahilKumar75 commentedon Jun 15, 2026
StefanieSenger commentedon Jun 15, 2026
Hi @SahilKumar75, we don't need genAI suggestions here, because these are areas where you need a lot of context knowledge about internal decisions we had discussed before and the directions and next steps that we want to take in Array API. Not sure if your input helps here. Also, @ogrisel had already suggested an action that four people that are longtime concerned with Array API posted a thumps up to.