Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 1 addition & 2 deletions doc/sources/building-from-source.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ To install the necessary Python dependencies:
Non-Python dependencies
~~~~~~~~~~~~~~~~~~~~~~~

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

- A C++ compiler.
- clang-format.
Expand Down Expand Up @@ -228,7 +228,6 @@ The following environment variables can be used to control setup aspects:
- ``NO_DIST``: set to '1', 'yes' or alike to build without support for distributed mode.
- ``NO_STREAM``: set to '1', 'yes' or alike to build without support for streaming mode.
- ``NO_DPC``: set to '1', 'yes' or alike to build without support of oneDAL DPC++ interfaces.
- ``OFF_ONEDAL_IFACE``: set to '1' to build without the support of oneDAL interfaces.
- ``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.

.. note:: The ``-j`` flag in the ``MAKEFLAGS`` environment variable is superseded in ``setup.py`` modes which support the ``--parallel`` and ``-j`` command line flags.
Expand Down
32 changes: 9 additions & 23 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,10 @@ def check_for_build_arg(arg: str) -> bool:
dal_root, "binary"
)
ONEDAL_VERSION = get_onedal_version(dal_root)
ONEDAL_2021_3 = 2021 * 10000 + 3 * 100
ONEDAL_2023_0_1 = 2023 * 10000 + 0 * 100 + 1
is_onedal_iface = (
os.environ.get("OFF_ONEDAL_IFACE", "0") == "0" and ONEDAL_VERSION >= ONEDAL_2021_3
)
if ONEDAL_VERSION < 20210300:
raise ValueError(
"OneDAL version is too old. Please use a more recent version (>= 2021.04)."
)

sklearnex_version = (
os.environ["SKLEARNEX_VERSION"]
Expand Down Expand Up @@ -479,12 +478,11 @@ def onedal_run(self):
debug_build=DEBUG_BUILD,
using_lld=USING_LLD,
)
if is_onedal_iface:
build_onedal("host")
if dpcpp:
build_onedal("dpc")
if build_distributed:
build_onedal("spmd_dpc")
build_onedal("host")
if dpcpp:
build_onedal("dpc")
if build_distributed:
build_onedal("spmd_dpc")

def onedal_post_build(self):
if IS_MAC:
Expand All @@ -495,18 +493,6 @@ def onedal_post_build(self):
major_is_available = (
find_library(f"libonedal_core.{major_version}.dylib") is not None
)
if major_is_available and ONEDAL_VERSION == ONEDAL_2023_0_1:
extension_libs = list(pathlib.Path(".").glob("**/*darwin.so"))
onedal_libs = ["onedal", "onedal_dpc", "onedal_core", "onedal_thread"]
for ext_lib in extension_libs:
for onedal_lib in onedal_libs:
subprocess.call(
"/usr/bin/install_name_tool -change "
f"lib{onedal_lib}.dylib "
f"lib{onedal_lib}.{major_version}.dylib "
f"{ext_lib}".split(" "),
shell=False,
)


class develop(onedal_build, orig_develop.develop):
Expand Down
11 changes: 4 additions & 7 deletions sklearnex/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,11 @@
"utils",
]
__version__ = "2199.9.9"
onedal_iface_flag = os.environ.get("OFF_ONEDAL_IFACE", "0")
if onedal_iface_flag == "0":
from onedal import _spmd_backend
from onedal.common.hyperparameters import get_hyperparameters, reset_hyperparameters

if _spmd_backend is not None:
__all__.append("spmd")
from onedal import _spmd_backend
from onedal.common.hyperparameters import get_hyperparameters, reset_hyperparameters

if _spmd_backend is not None:
__all__.append("spmd")

from ._utils import set_sklearn_ex_verbose

Expand Down
112 changes: 46 additions & 66 deletions sklearnex/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@
from daal4py.sklearn.monkeypatch.dispatcher import PatchMap


def _is_new_patching_available():
return os.environ.get("OFF_ONEDAL_IFACE", "0") == "0" and daal_check_version(
(2021, "P", 300)
)


def _is_preview_enabled() -> bool:
return "SKLEARNEX_PREVIEW" in os.environ

Expand Down Expand Up @@ -58,68 +52,54 @@ def get_patch_map_core(preview: bool = False) -> PatchMap:
if preview:
mapping = get_patch_map_core(preview=False)

if _is_new_patching_available():
import sklearn.covariance as covariance_module
import sklearn.decomposition as decomposition_module
from sklearn.covariance import (
EmpiricalCovariance as EmpiricalCovariance_sklearn,
import sklearn.covariance as covariance_module
import sklearn.decomposition as decomposition_module
from sklearn.covariance import EmpiricalCovariance as EmpiricalCovariance_sklearn
from sklearn.decomposition import IncrementalPCA as IncrementalPCA_sklearn

# Preview classes for patching
from .preview.covariance import (
EmpiricalCovariance as EmpiricalCovariance_sklearnex,
)
from .preview.decomposition import IncrementalPCA as IncrementalPCA_sklearnex

# Since the state of the lru_cache without preview cannot be
# guaranteed to not have already enabled sklearnex algorithms
# when preview is used, setting the mapping element[1] to None
# should NOT be done. This may lose track of the unpatched
# sklearn estimator or function.
# Covariance
preview_mapping = {
"sklearn.covariance.EmpiricalCovariance": (
covariance_module,
"EmpiricalCovariance",
EmpiricalCovariance_sklearnex,
EmpiricalCovariance_sklearn,
),
"sklearn.decomposition.IncrementalPCA": (
decomposition_module,
"IncrementalPCA",
IncrementalPCA_sklearnex,
IncrementalPCA_sklearn,
),
}
if daal_check_version((2024, "P", 1)):
import sklearn.linear_model as linear_model_module
from sklearn.linear_model import (
LogisticRegressionCV as LogisticRegressionCV_sklearn,
)

from .preview.linear_model import (
LogisticRegressionCV as LogisticRegressionCV_sklearnex,
)
from sklearn.decomposition import IncrementalPCA as IncrementalPCA_sklearn

# Preview classes for patching
from .preview.covariance import (
EmpiricalCovariance as EmpiricalCovariance_sklearnex,
preview_mapping["sklearn.linear_model.LogisticRegressionCV"] = (
linear_model_module,
"LogisticRegressionCV",
LogisticRegressionCV_sklearnex,
LogisticRegressionCV_sklearn,
)
from .preview.decomposition import IncrementalPCA as IncrementalPCA_sklearnex

# Since the state of the lru_cache without preview cannot be
# guaranteed to not have already enabled sklearnex algorithms
# when preview is used, setting the mapping element[1] to None
# should NOT be done. This may lose track of the unpatched
# sklearn estimator or function.
# Covariance
preview_mapping = {
"sklearn.covariance.EmpiricalCovariance": (
covariance_module,
"EmpiricalCovariance",
EmpiricalCovariance_sklearnex,
EmpiricalCovariance_sklearn,
),
"sklearn.decomposition.IncrementalPCA": (
decomposition_module,
"IncrementalPCA",
IncrementalPCA_sklearnex,
IncrementalPCA_sklearn,
),
}
if daal_check_version((2024, "P", 1)):
import sklearn.linear_model as linear_model_module
from sklearn.linear_model import (
LogisticRegressionCV as LogisticRegressionCV_sklearn,
)

from .preview.linear_model import (
LogisticRegressionCV as LogisticRegressionCV_sklearnex,
)

preview_mapping["sklearn.linear_model.LogisticRegressionCV"] = (
linear_model_module,
"LogisticRegressionCV",
LogisticRegressionCV_sklearnex,
LogisticRegressionCV_sklearn,
)
return mapping | preview_mapping

return mapping

# Comment 2026-01-20: This route is untested. It was meant to support
# a situation in which the 'onedal' module is not compiled, and instead
# the patching takes classes from daal4py, while still importing from
# the sklearnex module. This is not tested in any kind of configurations.
if not _is_new_patching_available():
from daal4py.sklearn.monkeypatch.dispatcher import _get_map_of_algorithms

return _get_map_of_algorithms()
return mapping | preview_mapping

# Scikit-learn* modules
import sklearn as base_module
Expand Down Expand Up @@ -515,7 +495,7 @@ def patch_sklearn(

patch_map: PatchMap = get_patch_map()

if name is not None and _is_new_patching_available():
if name is not None:
names_mandatory = [
"sklearn.set_config",
"sklearn.get_config",
Expand Down
Loading