Skip to content

Commit e3dfa62

Browse files
authored
[maintenance] use inheritance to handle spmd support in LogisticRegression (#3219)
* Update logistic_regression.py * Update logistic_regression.py * Update logistic_regression.py * Update logistic_regression.py * Update logistic_regression.py
1 parent a404684 commit e3dfa62

2 files changed

Lines changed: 15 additions & 16 deletions

File tree

sklearnex/linear_model/logistic_regression.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -255,10 +255,6 @@ def score(self, X, y, sample_weight=None):
255255
)
256256

257257
def _onedal_score(self, X, y, sample_weight=None, queue=None):
258-
if "spmd" in self._onedal_LogisticRegression.__module__:
259-
raise RuntimeError(
260-
"score method is not supported for LogisticRegression SPMD estimator."
261-
)
262258
return accuracy_score(
263259
y, self._onedal_predict(X, queue=queue), sample_weight=sample_weight
264260
)
@@ -414,12 +410,6 @@ def _onedal_gpu_initialize_from_coefs(self) -> None:
414410

415411
def _onedal_fit(self, X, y, sample_weight=None, queue=None):
416412
if queue is None or queue.sycl_device.is_cpu:
417-
# We don't use onedal backend for CPU, so we need an additional check here
418-
if "spmd" in self._onedal_LogisticRegression.__module__:
419-
raise RuntimeError(
420-
"Executing functions from SPMD backend requires a queue"
421-
)
422-
423413
# TODO add array-api support for CPU
424414
return self._onedal_cpu_fit(X, y, sample_weight)
425415
assert sample_weight is None
@@ -471,12 +461,6 @@ def _onedal_fit(self, X, y, sample_weight=None, queue=None):
471461

472462
# This should only be called when 'X' is on CPU
473463
def _error_out_on_incompatible_devices(self, X, method_name: str) -> None:
474-
# We don't use onedal backend for CPU, so we need an additional check here
475-
if "spmd" in self._onedal_LogisticRegression.__module__:
476-
raise RuntimeError(
477-
"Executing functions from SPMD backend requires a queue"
478-
)
479-
480464
# This can happen when fitting on GPU and then passing a CPU array to predict
481465
if not isinstance(self.coef_, np.ndarray) and not issparse(self.coef_):
482466
if sklearn_check_version("1.9"):

sklearnex/spmd/linear_model/logistic_regression.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,18 @@
2222
class LogisticRegression(LogisticRegression_Batch):
2323
__doc__ = LogisticRegression_Batch.__doc__
2424
_onedal_LogisticRegression = staticmethod(onedal_LogisticRegression)
25+
26+
def _onedal_fit(self, X, y, sample_weight=None, queue=None):
27+
if queue is None or queue.sycl_device.is_cpu:
28+
# We don't use onedal backend for CPU, so we need an additional check here
29+
raise RuntimeError("Executing functions from SPMD backend requires a queue")
30+
return super()._onedal_fit(X, y, sample_weight=sample_weight, queue=queue)
31+
32+
def _error_out_on_incompatible_devices(self, X, method_name: str) -> None:
33+
# custom function in LogisticRegression which will trigger for cpu data
34+
raise RuntimeError("Executing functions from SPMD backend requires a queue")
35+
36+
def _onedal_score(self, X, y, sample_weight=None, queue=None):
37+
raise RuntimeError(
38+
"score method is not supported for LogisticRegression SPMD estimator."
39+
)

0 commit comments

Comments
 (0)