Skip to content

FIX: fix array API support for float32-only devices on integer inputs#33898

Open
cakedev0 wants to merge 49 commits into
scikit-learn:mainfrom
cakedev0:xp/dpnp/fixes-from-cpu-tests
Open

FIX: fix array API support for float32-only devices on integer inputs#33898
cakedev0 wants to merge 49 commits into
scikit-learn:mainfrom
cakedev0:xp/dpnp/fixes-from-cpu-tests

Conversation

@cakedev0
Copy link
Copy Markdown
Contributor

@cakedev0 cakedev0 commented Apr 29, 2026

Reference Issues/PRs

Follow-up from #32460 and #33895

What does this implement/fix? Explain your changes.

This PR mostly passes around device=device. Mostly in supported_float_dtypes function. With dpnp the default device is the GPU, and on my laptop the GPU doesn't support float64, so supported_float_dtypes called without passing the CPU device doesn't return float64 and this turns into test failures.

This PR also adapt how a float64 gaussian noise numpy-array is transferred from numpy to xp in _randomized_range_finder, for similar reasons than above.

With this PR, all dpnp tests pass on my machine (GPU and CPU), as proven by this CI pipeline (see issue: https://github.com/probabl-ai/scikit-learn-intel-workflow/actions/runs/25327052888/job/74250515053

ogrisel and others added 30 commits October 9, 2025 15:39
Comment thread sklearn/utils/extmath.py Outdated
@cakedev0 cakedev0 changed the title [WIP] FIX: Array API: Fix CPU-dpnp tests FIX: Array API: Fix CPU-dpnp tests Apr 30, 2026
Comment on lines +1153 to +1168
max_dtype = _max_precision_float_dtype(xp, device=device)
# Also test with integer input only once per namespace/device for
# namespaces that support integer-by-floating matmul.
if X_xp.dtype != max_dtype or array_namespace in {"array_api_strict", "torch"}:
return

X_int = (X * 10).astype(np.int64)
atol *= 10
X_xp = xp.asarray(X_int, device=device)
with config_context(array_api_dispatch=True):
Q_np = randomized_range_finder(X_int, size=size, n_iter=n_iter, random_state=0)
Q_xp = randomized_range_finder(X_xp, size=size, n_iter=n_iter, random_state=0)

assert get_namespace(Q_xp)[0].__name__ == xp.__name__
assert Q_xp.dtype == max_dtype
assert_allclose(move_to(Q_xp, xp=np, device="cpu"), Q_np, atol=atol)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is maybe out-of-scope for this PR: it checks for a bug that happened in my first iteration of this PR if X was an int-array (which is allowed but probably fairly uncommon). This case was not covered by tests, so I added this piece of test. I'm ok to move it in a separate PR.

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.

I think it's ok to keep it here.

@cakedev0 cakedev0 marked this pull request as ready for review May 4, 2026 14:14
Copy link
Copy Markdown
Member

@ogrisel ogrisel left a comment

Choose a reason for hiding this comment

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

Some feedback below:

Comment thread sklearn/utils/extmath.py
Comment thread sklearn/utils/_array_api.py Outdated
@ogrisel ogrisel moved this to In Progress in Array API May 12, 2026
Copy link
Copy Markdown
Member

@ogrisel ogrisel left a comment

Choose a reason for hiding this comment

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

Could you please try to find a way to add a few non regression tests (e.g. for the code that previously failed to pass the device to supported_float_dtypes)? I suppose this can be achieved by adding a few test cases to run on integer array API inputs using the MPS device on macOS as it does not support float64.

We could add a TODO comment to later change those tests to use array-api-strict instead once released with data-apis/array-api-strict#206.

@github-actions github-actions Bot removed the CUDA CI label May 12, 2026
@ogrisel ogrisel changed the title FIX: Array API: Fix CPU-dpnp tests FIX: fix array API support for float32-only devices on integer inputs May 12, 2026
@ogrisel
Copy link
Copy Markdown
Member

ogrisel commented May 12, 2026

I changed the title to make reflect the actual scope of this fix. Please also add a changelog entry (once the non-regression tests are in).

@cakedev0
Copy link
Copy Markdown
Contributor Author

Added non-reg tests and changelog.

You can see that they are indeed failing before the fixes from this PR: https://github.com/scikit-learn/scikit-learn/actions/runs/25725657860/job/75537790919?pr=33997

@ogrisel ogrisel added Waiting for Second Reviewer First reviewer is done, need a second one! CUDA CI labels May 12, 2026
@github-actions github-actions Bot removed the CUDA CI label May 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Array API Waiting for Second Reviewer First reviewer is done, need a second one!

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

3 participants