Skip to content

Commit 4a1d1f2

Browse files
MAINT: Remove untested option to build without onedal module (#2916)
* remove untested option to build without onedal * Update setup.py Co-authored-by: ethanglaser <42726565+ethanglaser@users.noreply.github.com> --------- Co-authored-by: ethanglaser <42726565+ethanglaser@users.noreply.github.com>
1 parent 88ee40b commit 4a1d1f2

4 files changed

Lines changed: 60 additions & 98 deletions

File tree

doc/sources/building-from-source.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ To install the necessary Python dependencies:
6262
Non-Python dependencies
6363
~~~~~~~~~~~~~~~~~~~~~~~
6464

65-
Apart from Python libraries and from the |onedal|, the following dependencies are needed in order to compile the |sklearnex|:
65+
Apart from Python libraries and from the |onedal| (version ``2021.4`` or higher), the following dependencies are needed in order to compile the |sklearnex|:
6666

6767
- A C++ compiler.
6868
- clang-format.
@@ -246,7 +246,6 @@ The following environment variables can be used to control setup aspects:
246246
- ``NO_DIST``: set to '1', 'yes' or alike to build without support for distributed mode.
247247
- ``NO_STREAM``: set to '1', 'yes' or alike to build without support for streaming mode.
248248
- ``NO_DPC``: set to '1', 'yes' or alike to build without support of oneDAL DPC++ interfaces.
249-
- ``OFF_ONEDAL_IFACE``: set to '1' to build without the support of oneDAL interfaces.
250249
- ``MAKEFLAGS``: the last `-j` flag determines the number of threads for building the onedal extension. It will default to the number of CPU threads when not set.
251250

252251
.. note:: The ``-j`` flag in the ``MAKEFLAGS`` environment variable is superseded in ``setup.py`` modes which support the ``--parallel`` and ``-j`` command line flags.

setup.py

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,10 @@ def check_for_build_arg(arg: str) -> bool:
8080
dal_root, "binary"
8181
)
8282
ONEDAL_VERSION = get_onedal_version(dal_root)
83-
ONEDAL_2021_3 = 2021 * 10000 + 3 * 100
84-
ONEDAL_2023_0_1 = 2023 * 10000 + 0 * 100 + 1
85-
is_onedal_iface = (
86-
os.environ.get("OFF_ONEDAL_IFACE", "0") == "0" and ONEDAL_VERSION >= ONEDAL_2021_3
87-
)
83+
if ONEDAL_VERSION < 20210300:
84+
raise ValueError(
85+
"OneDAL version is too old. Please use a more recent version (>= 2021.4)."
86+
)
8887

8988
sklearnex_version = (
9089
os.environ["SKLEARNEX_VERSION"]
@@ -479,12 +478,11 @@ def onedal_run(self):
479478
debug_build=DEBUG_BUILD,
480479
using_lld=USING_LLD,
481480
)
482-
if is_onedal_iface:
483-
build_onedal("host")
484-
if dpcpp:
485-
build_onedal("dpc")
486-
if build_distributed:
487-
build_onedal("spmd_dpc")
481+
build_onedal("host")
482+
if dpcpp:
483+
build_onedal("dpc")
484+
if build_distributed:
485+
build_onedal("spmd_dpc")
488486

489487
def onedal_post_build(self):
490488
if IS_MAC:
@@ -495,18 +493,6 @@ def onedal_post_build(self):
495493
major_is_available = (
496494
find_library(f"libonedal_core.{major_version}.dylib") is not None
497495
)
498-
if major_is_available and ONEDAL_VERSION == ONEDAL_2023_0_1:
499-
extension_libs = list(pathlib.Path(".").glob("**/*darwin.so"))
500-
onedal_libs = ["onedal", "onedal_dpc", "onedal_core", "onedal_thread"]
501-
for ext_lib in extension_libs:
502-
for onedal_lib in onedal_libs:
503-
subprocess.call(
504-
"/usr/bin/install_name_tool -change "
505-
f"lib{onedal_lib}.dylib "
506-
f"lib{onedal_lib}.{major_version}.dylib "
507-
f"{ext_lib}".split(" "),
508-
shell=False,
509-
)
510496

511497

512498
class develop(onedal_build, orig_develop.develop):

sklearnex/__init__.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,11 @@
5555
"utils",
5656
]
5757
__version__ = "2199.9.9"
58-
onedal_iface_flag = os.environ.get("OFF_ONEDAL_IFACE", "0")
59-
if onedal_iface_flag == "0":
60-
from onedal import _spmd_backend
61-
from onedal.common.hyperparameters import get_hyperparameters, reset_hyperparameters
62-
63-
if _spmd_backend is not None:
64-
__all__.append("spmd")
58+
from onedal import _spmd_backend
59+
from onedal.common.hyperparameters import get_hyperparameters, reset_hyperparameters
6560

61+
if _spmd_backend is not None:
62+
__all__.append("spmd")
6663

6764
from ._utils import set_sklearn_ex_verbose
6865

sklearnex/dispatcher.py

Lines changed: 46 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,6 @@
2424
from daal4py.sklearn.monkeypatch.dispatcher import PatchMap
2525

2626

27-
def _is_new_patching_available():
28-
return os.environ.get("OFF_ONEDAL_IFACE", "0") == "0" and daal_check_version(
29-
(2021, "P", 300)
30-
)
31-
32-
3327
def _is_preview_enabled() -> bool:
3428
return "SKLEARNEX_PREVIEW" in os.environ
3529

@@ -58,68 +52,54 @@ def get_patch_map_core(preview: bool = False) -> PatchMap:
5852
if preview:
5953
mapping = get_patch_map_core(preview=False)
6054

61-
if _is_new_patching_available():
62-
import sklearn.covariance as covariance_module
63-
import sklearn.decomposition as decomposition_module
64-
from sklearn.covariance import (
65-
EmpiricalCovariance as EmpiricalCovariance_sklearn,
55+
import sklearn.covariance as covariance_module
56+
import sklearn.decomposition as decomposition_module
57+
from sklearn.covariance import EmpiricalCovariance as EmpiricalCovariance_sklearn
58+
from sklearn.decomposition import IncrementalPCA as IncrementalPCA_sklearn
59+
60+
# Preview classes for patching
61+
from .preview.covariance import (
62+
EmpiricalCovariance as EmpiricalCovariance_sklearnex,
63+
)
64+
from .preview.decomposition import IncrementalPCA as IncrementalPCA_sklearnex
65+
66+
# Since the state of the lru_cache without preview cannot be
67+
# guaranteed to not have already enabled sklearnex algorithms
68+
# when preview is used, setting the mapping element[1] to None
69+
# should NOT be done. This may lose track of the unpatched
70+
# sklearn estimator or function.
71+
# Covariance
72+
preview_mapping = {
73+
"sklearn.covariance.EmpiricalCovariance": (
74+
covariance_module,
75+
"EmpiricalCovariance",
76+
EmpiricalCovariance_sklearnex,
77+
EmpiricalCovariance_sklearn,
78+
),
79+
"sklearn.decomposition.IncrementalPCA": (
80+
decomposition_module,
81+
"IncrementalPCA",
82+
IncrementalPCA_sklearnex,
83+
IncrementalPCA_sklearn,
84+
),
85+
}
86+
if daal_check_version((2024, "P", 1)):
87+
import sklearn.linear_model as linear_model_module
88+
from sklearn.linear_model import (
89+
LogisticRegressionCV as LogisticRegressionCV_sklearn,
90+
)
91+
92+
from .preview.linear_model import (
93+
LogisticRegressionCV as LogisticRegressionCV_sklearnex,
6694
)
67-
from sklearn.decomposition import IncrementalPCA as IncrementalPCA_sklearn
6895

69-
# Preview classes for patching
70-
from .preview.covariance import (
71-
EmpiricalCovariance as EmpiricalCovariance_sklearnex,
96+
preview_mapping["sklearn.linear_model.LogisticRegressionCV"] = (
97+
linear_model_module,
98+
"LogisticRegressionCV",
99+
LogisticRegressionCV_sklearnex,
100+
LogisticRegressionCV_sklearn,
72101
)
73-
from .preview.decomposition import IncrementalPCA as IncrementalPCA_sklearnex
74-
75-
# Since the state of the lru_cache without preview cannot be
76-
# guaranteed to not have already enabled sklearnex algorithms
77-
# when preview is used, setting the mapping element[1] to None
78-
# should NOT be done. This may lose track of the unpatched
79-
# sklearn estimator or function.
80-
# Covariance
81-
preview_mapping = {
82-
"sklearn.covariance.EmpiricalCovariance": (
83-
covariance_module,
84-
"EmpiricalCovariance",
85-
EmpiricalCovariance_sklearnex,
86-
EmpiricalCovariance_sklearn,
87-
),
88-
"sklearn.decomposition.IncrementalPCA": (
89-
decomposition_module,
90-
"IncrementalPCA",
91-
IncrementalPCA_sklearnex,
92-
IncrementalPCA_sklearn,
93-
),
94-
}
95-
if daal_check_version((2024, "P", 1)):
96-
import sklearn.linear_model as linear_model_module
97-
from sklearn.linear_model import (
98-
LogisticRegressionCV as LogisticRegressionCV_sklearn,
99-
)
100-
101-
from .preview.linear_model import (
102-
LogisticRegressionCV as LogisticRegressionCV_sklearnex,
103-
)
104-
105-
preview_mapping["sklearn.linear_model.LogisticRegressionCV"] = (
106-
linear_model_module,
107-
"LogisticRegressionCV",
108-
LogisticRegressionCV_sklearnex,
109-
LogisticRegressionCV_sklearn,
110-
)
111-
return mapping | preview_mapping
112-
113-
return mapping
114-
115-
# Comment 2026-01-20: This route is untested. It was meant to support
116-
# a situation in which the 'onedal' module is not compiled, and instead
117-
# the patching takes classes from daal4py, while still importing from
118-
# the sklearnex module. This is not tested in any kind of configurations.
119-
if not _is_new_patching_available():
120-
from daal4py.sklearn.monkeypatch.dispatcher import _get_map_of_algorithms
121-
122-
return _get_map_of_algorithms()
102+
return mapping | preview_mapping
123103

124104
# Scikit-learn* modules
125105
import sklearn as base_module
@@ -515,7 +495,7 @@ def patch_sklearn(
515495

516496
patch_map: PatchMap = get_patch_map()
517497

518-
if name is not None and _is_new_patching_available():
498+
if name is not None:
519499
names_mandatory = [
520500
"sklearn.set_config",
521501
"sklearn.get_config",

0 commit comments

Comments
 (0)