Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Draft] ENH: Enable linear regression on GPU with non-PSD systems #2167

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions deselected_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -462,8 +462,3 @@ gpu:
# RuntimeError: Device support is not implemented, failing as result of fallback to cpu false
- svm/tests/test_svm.py::test_unfitted
- tests/test_common.py::test_estimators[SVC()-check_estimators_unfitted]

# Failed on the onedal's LinearRegression call.
# RuntimeError: oneapi::mkl::lapack::potrf: computation error: info = 2: Leading principal minor of order
# 2 is not positive, and the factorization could not be completed.
- ensemble/tests/test_stacking.py::test_stacking_prefit[StackingRegressor-DummyRegressor-predict-final_estimator1-X1-y1]
4 changes: 2 additions & 2 deletions doc/sources/algorithms.rst
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ Regression

- ``normalize`` != `False`
- ``sample_weight`` != `None`
- Only dense data is supported, `#observations` should be >= `#features` and there should be no linearly dependent features in the data.
- Only dense data is supported.

Clustering
**********
Expand Down Expand Up @@ -456,7 +456,7 @@ Regression

- ``normalize`` != `False`
- ``sample_weight`` != `None`
- Only dense data is supported, `#observations` should be >= `#features` and there should be no linearly dependent features in the data.
- Only dense data is supported.

Clustering
**********
Expand Down
17 changes: 13 additions & 4 deletions onedal/linear_model/tests/test_linear_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,16 @@ def test_reconstruct_model(queue, dtype):
assert_allclose(gtr, res, rtol=tol)


@pytest.mark.parametrize("queue", get_queues("cpu"))
@pytest.mark.parametrize("queue", get_queues())
@pytest.mark.parametrize("dtype", [np.float32, np.float64])
@pytest.mark.parametrize("fit_intercept", [False, True])
@pytest.mark.skipif(
not daal_check_version((2025, "P", 1)),
reason="Functionality introduced in later versions",
)
def test_overdetermined_system(queue, dtype, fit_intercept):
if queue and queue.sycl_device.is_gpu and not daal_check_version((2025, "P", 200)):
pytest.skip("Functionality introduced in later versions")
gen = np.random.default_rng(seed=123)
X = gen.standard_normal(size=(10, 20))
y = gen.standard_normal(size=X.shape[0])
Expand All @@ -176,14 +178,16 @@ def test_overdetermined_system(queue, dtype, fit_intercept):
assert np.all(np.abs(residual) < 1e-6)


@pytest.mark.parametrize("queue", get_queues("cpu"))
@pytest.mark.parametrize("queue", get_queues())
@pytest.mark.parametrize("dtype", [np.float32, np.float64])
@pytest.mark.parametrize("fit_intercept", [False, True])
@pytest.mark.skipif(
not daal_check_version((2025, "P", 1)),
reason="Functionality introduced in later versions",
)
def test_singular_matrix(queue, dtype, fit_intercept):
if queue and queue.sycl_device.is_gpu and not daal_check_version((2025, "P", 200)):
pytest.skip("Functionality introduced in later versions")
gen = np.random.default_rng(seed=123)
X = gen.standard_normal(size=(20, 4))
X[:, 2] = X[:, 3]
Expand Down Expand Up @@ -212,8 +216,13 @@ def test_singular_matrix(queue, dtype, fit_intercept):
reason="Functionality introduced in the versions >= 2025.0",
)
def test_multioutput_regression(queue, dtype, fit_intercept, problem_type):
if problem_type != "regular" and queue and queue.sycl_device.is_gpu:
pytest.skip("Not yet implemented on GPU")
if (
problem_type != "regular"
and queue
and queue.sycl_device.is_gpu
and not daal_check_version((2025, "P", 200))
):
pytest.skip("Functionality introduced in later versions")
gen = np.random.default_rng(seed=123)
if problem_type == "regular":
X = gen.standard_normal(size=(20, 5))
Expand Down
2 changes: 1 addition & 1 deletion sklearnex/linear_model/linear.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def _onedal_gpu_supported(self, method_name, *data):
f"sklearn.linear_model.{self.__class__.__name__}.{method_name}"
)

if method_name == "fit":
if method_name == "fit" and not daal_check_version((2025, "P", 200)):
n_samples = _num_samples(data[0])
n_features = _num_features(data[0], fallback_1d=True)
is_underdetermined = n_samples < (n_features + int(self.fit_intercept))
Expand Down
11 changes: 8 additions & 3 deletions sklearnex/linear_model/tests/test_linear.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,14 @@ def test_sklearnex_import_linear(
dataframe, queue, dtype, macro_block, overdetermined, multi_output
):
if (overdetermined or multi_output) and not daal_check_version((2025, "P", 1)):
pytest.skip()
if overdetermined and queue and queue.sycl_device.is_gpu:
pytest.skip()
pytest.skip("Functionality introduced in later versions")
if (
overdetermined
and queue
and queue.sycl_device.is_gpu
and not daal_check_version((2025, "P", 200))
):
pytest.skip("Functionality introduced in later versions")

from sklearnex.linear_model import LinearRegression

Expand Down
Loading