scikit-learn-intelex 2025.0.0__py312-none-manylinux_2_28_x86_64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of scikit-learn-intelex might be problematic. Click here for more details.
- daal4py/__init__.py +73 -0
- daal4py/__main__.py +58 -0
- daal4py/_daal4py.cpython-312-x86_64-linux-gnu.so +0 -0
- daal4py/doc/third-party-programs.txt +424 -0
- daal4py/mb/__init__.py +19 -0
- daal4py/mb/model_builders.py +377 -0
- daal4py/mpi_transceiver.cpython-312-x86_64-linux-gnu.so +0 -0
- daal4py/sklearn/__init__.py +40 -0
- daal4py/sklearn/_n_jobs_support.py +242 -0
- daal4py/sklearn/_utils.py +241 -0
- daal4py/sklearn/cluster/__init__.py +20 -0
- daal4py/sklearn/cluster/dbscan.py +165 -0
- daal4py/sklearn/cluster/k_means.py +597 -0
- daal4py/sklearn/cluster/tests/test_dbscan.py +109 -0
- daal4py/sklearn/decomposition/__init__.py +19 -0
- daal4py/sklearn/decomposition/_pca.py +524 -0
- daal4py/sklearn/ensemble/AdaBoostClassifier.py +192 -0
- daal4py/sklearn/ensemble/GBTDAAL.py +318 -0
- daal4py/sklearn/ensemble/__init__.py +27 -0
- daal4py/sklearn/ensemble/_forest.py +1397 -0
- daal4py/sklearn/ensemble/tests/test_decision_forest.py +206 -0
- daal4py/sklearn/linear_model/__init__.py +29 -0
- daal4py/sklearn/linear_model/_coordinate_descent.py +848 -0
- daal4py/sklearn/linear_model/_linear.py +272 -0
- daal4py/sklearn/linear_model/_ridge.py +325 -0
- daal4py/sklearn/linear_model/coordinate_descent.py +17 -0
- daal4py/sklearn/linear_model/linear.py +17 -0
- daal4py/sklearn/linear_model/logistic_loss.py +195 -0
- daal4py/sklearn/linear_model/logistic_path.py +1026 -0
- daal4py/sklearn/linear_model/ridge.py +17 -0
- daal4py/sklearn/linear_model/tests/test_linear.py +196 -0
- daal4py/sklearn/linear_model/tests/test_ridge.py +69 -0
- daal4py/sklearn/manifold/__init__.py +19 -0
- daal4py/sklearn/manifold/_t_sne.py +405 -0
- daal4py/sklearn/metrics/__init__.py +20 -0
- daal4py/sklearn/metrics/_pairwise.py +155 -0
- daal4py/sklearn/metrics/_ranking.py +210 -0
- daal4py/sklearn/model_selection/__init__.py +19 -0
- daal4py/sklearn/model_selection/_split.py +309 -0
- daal4py/sklearn/model_selection/tests/test_split.py +56 -0
- daal4py/sklearn/monkeypatch/__init__.py +0 -0
- daal4py/sklearn/monkeypatch/dispatcher.py +232 -0
- daal4py/sklearn/monkeypatch/tests/_models_info.py +161 -0
- daal4py/sklearn/monkeypatch/tests/test_monkeypatch.py +71 -0
- daal4py/sklearn/monkeypatch/tests/test_patching.py +87 -0
- daal4py/sklearn/monkeypatch/tests/utils/_launch_algorithms.py +118 -0
- daal4py/sklearn/neighbors/__init__.py +21 -0
- daal4py/sklearn/neighbors/_base.py +503 -0
- daal4py/sklearn/neighbors/_classification.py +139 -0
- daal4py/sklearn/neighbors/_regression.py +74 -0
- daal4py/sklearn/neighbors/_unsupervised.py +55 -0
- daal4py/sklearn/neighbors/tests/test_kneighbors.py +113 -0
- daal4py/sklearn/svm/__init__.py +19 -0
- daal4py/sklearn/svm/svm.py +734 -0
- daal4py/sklearn/utils/__init__.py +21 -0
- daal4py/sklearn/utils/base.py +75 -0
- daal4py/sklearn/utils/tests/test_utils.py +51 -0
- daal4py/sklearn/utils/validation.py +693 -0
- onedal/__init__.py +83 -0
- onedal/_config.py +53 -0
- onedal/_device_offload.py +229 -0
- onedal/_onedal_py_dpc.cpython-312-x86_64-linux-gnu.so +0 -0
- onedal/_onedal_py_host.cpython-312-x86_64-linux-gnu.so +0 -0
- onedal/_onedal_py_spmd_dpc.cpython-312-x86_64-linux-gnu.so +0 -0
- onedal/basic_statistics/__init__.py +20 -0
- onedal/basic_statistics/basic_statistics.py +107 -0
- onedal/basic_statistics/incremental_basic_statistics.py +160 -0
- onedal/basic_statistics/tests/test_basic_statistics.py +298 -0
- onedal/basic_statistics/tests/test_incremental_basic_statistics.py +196 -0
- onedal/cluster/__init__.py +27 -0
- onedal/cluster/dbscan.py +110 -0
- onedal/cluster/kmeans.py +560 -0
- onedal/cluster/kmeans_init.py +115 -0
- onedal/cluster/tests/test_dbscan.py +125 -0
- onedal/cluster/tests/test_kmeans.py +88 -0
- onedal/cluster/tests/test_kmeans_init.py +93 -0
- onedal/common/_base.py +38 -0
- onedal/common/_estimator_checks.py +47 -0
- onedal/common/_mixin.py +62 -0
- onedal/common/_policy.py +59 -0
- onedal/common/_spmd_policy.py +30 -0
- onedal/common/hyperparameters.py +116 -0
- onedal/common/tests/test_policy.py +75 -0
- onedal/covariance/__init__.py +20 -0
- onedal/covariance/covariance.py +125 -0
- onedal/covariance/incremental_covariance.py +146 -0
- onedal/covariance/tests/test_covariance.py +50 -0
- onedal/covariance/tests/test_incremental_covariance.py +122 -0
- onedal/datatypes/__init__.py +19 -0
- onedal/datatypes/_data_conversion.py +95 -0
- onedal/datatypes/tests/test_data.py +235 -0
- onedal/decomposition/__init__.py +20 -0
- onedal/decomposition/incremental_pca.py +204 -0
- onedal/decomposition/pca.py +186 -0
- onedal/decomposition/tests/test_incremental_pca.py +198 -0
- onedal/ensemble/__init__.py +29 -0
- onedal/ensemble/forest.py +720 -0
- onedal/ensemble/tests/test_random_forest.py +97 -0
- onedal/linear_model/__init__.py +27 -0
- onedal/linear_model/incremental_linear_model.py +258 -0
- onedal/linear_model/linear_model.py +329 -0
- onedal/linear_model/logistic_regression.py +249 -0
- onedal/linear_model/tests/test_incremental_linear_regression.py +168 -0
- onedal/linear_model/tests/test_incremental_ridge_regression.py +107 -0
- onedal/linear_model/tests/test_linear_regression.py +149 -0
- onedal/linear_model/tests/test_logistic_regression.py +95 -0
- onedal/linear_model/tests/test_ridge.py +95 -0
- onedal/neighbors/__init__.py +19 -0
- onedal/neighbors/neighbors.py +778 -0
- onedal/neighbors/tests/test_knn_classification.py +49 -0
- onedal/primitives/__init__.py +27 -0
- onedal/primitives/get_tree.py +25 -0
- onedal/primitives/kernel_functions.py +153 -0
- onedal/primitives/tests/test_kernel_functions.py +159 -0
- onedal/spmd/__init__.py +25 -0
- onedal/spmd/_base.py +30 -0
- onedal/spmd/basic_statistics/__init__.py +20 -0
- onedal/spmd/basic_statistics/basic_statistics.py +30 -0
- onedal/spmd/basic_statistics/incremental_basic_statistics.py +69 -0
- onedal/spmd/cluster/__init__.py +28 -0
- onedal/spmd/cluster/dbscan.py +23 -0
- onedal/spmd/cluster/kmeans.py +56 -0
- onedal/spmd/covariance/__init__.py +20 -0
- onedal/spmd/covariance/covariance.py +26 -0
- onedal/spmd/covariance/incremental_covariance.py +82 -0
- onedal/spmd/decomposition/__init__.py +20 -0
- onedal/spmd/decomposition/incremental_pca.py +117 -0
- onedal/spmd/decomposition/pca.py +26 -0
- onedal/spmd/ensemble/__init__.py +19 -0
- onedal/spmd/ensemble/forest.py +28 -0
- onedal/spmd/linear_model/__init__.py +21 -0
- onedal/spmd/linear_model/incremental_linear_model.py +97 -0
- onedal/spmd/linear_model/linear_model.py +30 -0
- onedal/spmd/linear_model/logistic_regression.py +38 -0
- onedal/spmd/neighbors/__init__.py +19 -0
- onedal/spmd/neighbors/neighbors.py +75 -0
- onedal/svm/__init__.py +19 -0
- onedal/svm/svm.py +556 -0
- onedal/svm/tests/test_csr_svm.py +351 -0
- onedal/svm/tests/test_nusvc.py +204 -0
- onedal/svm/tests/test_nusvr.py +210 -0
- onedal/svm/tests/test_svc.py +168 -0
- onedal/svm/tests/test_svr.py +243 -0
- onedal/tests/test_common.py +41 -0
- onedal/tests/utils/_dataframes_support.py +168 -0
- onedal/tests/utils/_device_selection.py +107 -0
- onedal/utils/__init__.py +49 -0
- onedal/utils/_array_api.py +91 -0
- onedal/utils/validation.py +432 -0
- scikit_learn_intelex-2025.0.0.dist-info/LICENSE.txt +202 -0
- scikit_learn_intelex-2025.0.0.dist-info/METADATA +231 -0
- scikit_learn_intelex-2025.0.0.dist-info/RECORD +278 -0
- scikit_learn_intelex-2025.0.0.dist-info/WHEEL +5 -0
- scikit_learn_intelex-2025.0.0.dist-info/top_level.txt +3 -0
- sklearnex/__init__.py +65 -0
- sklearnex/__main__.py +58 -0
- sklearnex/_config.py +98 -0
- sklearnex/_device_offload.py +121 -0
- sklearnex/_utils.py +109 -0
- sklearnex/basic_statistics/__init__.py +20 -0
- sklearnex/basic_statistics/basic_statistics.py +140 -0
- sklearnex/basic_statistics/incremental_basic_statistics.py +288 -0
- sklearnex/basic_statistics/tests/test_basic_statistics.py +251 -0
- sklearnex/basic_statistics/tests/test_incremental_basic_statistics.py +384 -0
- sklearnex/cluster/__init__.py +20 -0
- sklearnex/cluster/dbscan.py +192 -0
- sklearnex/cluster/k_means.py +383 -0
- sklearnex/cluster/tests/test_dbscan.py +38 -0
- sklearnex/cluster/tests/test_kmeans.py +153 -0
- sklearnex/conftest.py +73 -0
- sklearnex/covariance/__init__.py +19 -0
- sklearnex/covariance/incremental_covariance.py +368 -0
- sklearnex/covariance/tests/test_incremental_covariance.py +226 -0
- sklearnex/decomposition/__init__.py +19 -0
- sklearnex/decomposition/pca.py +414 -0
- sklearnex/decomposition/tests/test_pca.py +58 -0
- sklearnex/dispatcher.py +543 -0
- sklearnex/doc/third-party-programs.txt +424 -0
- sklearnex/ensemble/__init__.py +29 -0
- sklearnex/ensemble/_forest.py +2016 -0
- sklearnex/ensemble/tests/test_forest.py +120 -0
- sklearnex/glob/__main__.py +72 -0
- sklearnex/glob/dispatcher.py +101 -0
- sklearnex/linear_model/__init__.py +32 -0
- sklearnex/linear_model/coordinate_descent.py +30 -0
- sklearnex/linear_model/incremental_linear.py +463 -0
- sklearnex/linear_model/incremental_ridge.py +418 -0
- sklearnex/linear_model/linear.py +302 -0
- sklearnex/linear_model/logistic_path.py +17 -0
- sklearnex/linear_model/logistic_regression.py +403 -0
- sklearnex/linear_model/ridge.py +24 -0
- sklearnex/linear_model/tests/test_incremental_linear.py +203 -0
- sklearnex/linear_model/tests/test_incremental_ridge.py +153 -0
- sklearnex/linear_model/tests/test_linear.py +142 -0
- sklearnex/linear_model/tests/test_logreg.py +134 -0
- sklearnex/manifold/__init__.py +19 -0
- sklearnex/manifold/t_sne.py +21 -0
- sklearnex/manifold/tests/test_tsne.py +26 -0
- sklearnex/metrics/__init__.py +23 -0
- sklearnex/metrics/pairwise.py +22 -0
- sklearnex/metrics/ranking.py +20 -0
- sklearnex/metrics/tests/test_metrics.py +39 -0
- sklearnex/model_selection/__init__.py +21 -0
- sklearnex/model_selection/split.py +22 -0
- sklearnex/model_selection/tests/test_model_selection.py +34 -0
- sklearnex/neighbors/__init__.py +27 -0
- sklearnex/neighbors/_lof.py +231 -0
- sklearnex/neighbors/common.py +310 -0
- sklearnex/neighbors/knn_classification.py +226 -0
- sklearnex/neighbors/knn_regression.py +203 -0
- sklearnex/neighbors/knn_unsupervised.py +170 -0
- sklearnex/neighbors/tests/test_neighbors.py +80 -0
- sklearnex/preview/__init__.py +17 -0
- sklearnex/preview/covariance/__init__.py +19 -0
- sklearnex/preview/covariance/covariance.py +133 -0
- sklearnex/preview/covariance/tests/test_covariance.py +66 -0
- sklearnex/preview/decomposition/__init__.py +19 -0
- sklearnex/preview/decomposition/incremental_pca.py +228 -0
- sklearnex/preview/decomposition/tests/test_incremental_pca.py +266 -0
- sklearnex/preview/linear_model/__init__.py +19 -0
- sklearnex/preview/linear_model/ridge.py +419 -0
- sklearnex/preview/linear_model/tests/test_ridge.py +102 -0
- sklearnex/spmd/__init__.py +25 -0
- sklearnex/spmd/basic_statistics/__init__.py +20 -0
- sklearnex/spmd/basic_statistics/basic_statistics.py +21 -0
- sklearnex/spmd/basic_statistics/incremental_basic_statistics.py +30 -0
- sklearnex/spmd/basic_statistics/tests/test_basic_statistics_spmd.py +107 -0
- sklearnex/spmd/basic_statistics/tests/test_incremental_basic_statistics_spmd.py +307 -0
- sklearnex/spmd/cluster/__init__.py +30 -0
- sklearnex/spmd/cluster/dbscan.py +50 -0
- sklearnex/spmd/cluster/kmeans.py +21 -0
- sklearnex/spmd/cluster/tests/test_dbscan_spmd.py +97 -0
- sklearnex/spmd/cluster/tests/test_kmeans_spmd.py +172 -0
- sklearnex/spmd/covariance/__init__.py +20 -0
- sklearnex/spmd/covariance/covariance.py +21 -0
- sklearnex/spmd/covariance/incremental_covariance.py +37 -0
- sklearnex/spmd/covariance/tests/test_covariance_spmd.py +107 -0
- sklearnex/spmd/covariance/tests/test_incremental_covariance_spmd.py +184 -0
- sklearnex/spmd/decomposition/__init__.py +20 -0
- sklearnex/spmd/decomposition/incremental_pca.py +30 -0
- sklearnex/spmd/decomposition/pca.py +21 -0
- sklearnex/spmd/decomposition/tests/test_incremental_pca_spmd.py +269 -0
- sklearnex/spmd/decomposition/tests/test_pca_spmd.py +128 -0
- sklearnex/spmd/ensemble/__init__.py +19 -0
- sklearnex/spmd/ensemble/forest.py +71 -0
- sklearnex/spmd/ensemble/tests/test_forest_spmd.py +265 -0
- sklearnex/spmd/linear_model/__init__.py +21 -0
- sklearnex/spmd/linear_model/incremental_linear_model.py +35 -0
- sklearnex/spmd/linear_model/linear_model.py +21 -0
- sklearnex/spmd/linear_model/logistic_regression.py +21 -0
- sklearnex/spmd/linear_model/tests/test_incremental_linear_spmd.py +329 -0
- sklearnex/spmd/linear_model/tests/test_linear_regression_spmd.py +145 -0
- sklearnex/spmd/linear_model/tests/test_logistic_regression_spmd.py +166 -0
- sklearnex/spmd/neighbors/__init__.py +19 -0
- sklearnex/spmd/neighbors/neighbors.py +25 -0
- sklearnex/spmd/neighbors/tests/test_neighbors_spmd.py +288 -0
- sklearnex/svm/__init__.py +29 -0
- sklearnex/svm/_common.py +328 -0
- sklearnex/svm/nusvc.py +332 -0
- sklearnex/svm/nusvr.py +148 -0
- sklearnex/svm/svc.py +360 -0
- sklearnex/svm/svr.py +149 -0
- sklearnex/svm/tests/test_svm.py +93 -0
- sklearnex/tests/_utils.py +328 -0
- sklearnex/tests/_utils_spmd.py +198 -0
- sklearnex/tests/test_common.py +54 -0
- sklearnex/tests/test_config.py +43 -0
- sklearnex/tests/test_memory_usage.py +291 -0
- sklearnex/tests/test_monkeypatch.py +276 -0
- sklearnex/tests/test_n_jobs_support.py +103 -0
- sklearnex/tests/test_parallel.py +48 -0
- sklearnex/tests/test_patching.py +385 -0
- sklearnex/tests/test_run_to_run_stability.py +296 -0
- sklearnex/utils/__init__.py +19 -0
- sklearnex/utils/_array_api.py +82 -0
- sklearnex/utils/parallel.py +59 -0
- sklearnex/utils/tests/test_finite.py +89 -0
- sklearnex/utils/validation.py +17 -0
sklearnex/__main__.py
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# ==============================================================================
|
|
2
|
+
# Copyright 2021 Intel Corporation
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
# ==============================================================================
|
|
16
|
+
|
|
17
|
+
import sys
|
|
18
|
+
|
|
19
|
+
from sklearnex import patch_sklearn
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def _main():
|
|
23
|
+
import argparse
|
|
24
|
+
|
|
25
|
+
parser = argparse.ArgumentParser(
|
|
26
|
+
prog="python -m sklearnex",
|
|
27
|
+
description="""
|
|
28
|
+
Run your Python script with Intel(R) Extension for
|
|
29
|
+
scikit-learn, optimizing solvers of
|
|
30
|
+
scikit-learn with Intel(R) oneAPI Data Analytics Library.
|
|
31
|
+
""",
|
|
32
|
+
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
parser.add_argument(
|
|
36
|
+
"-m", action="store_true", dest="module", help="Executes following as a module"
|
|
37
|
+
)
|
|
38
|
+
parser.add_argument("name", help="Script or module name")
|
|
39
|
+
parser.add_argument("args", nargs=argparse.REMAINDER, help="Command line arguments")
|
|
40
|
+
args = parser.parse_args()
|
|
41
|
+
|
|
42
|
+
try:
|
|
43
|
+
import sklearn
|
|
44
|
+
|
|
45
|
+
patch_sklearn()
|
|
46
|
+
except ImportError:
|
|
47
|
+
print("Scikit-learn could not be imported. Nothing to patch")
|
|
48
|
+
|
|
49
|
+
sys.argv = [args.name] + args.args
|
|
50
|
+
if "_" + args.name in globals():
|
|
51
|
+
return globals()["_" + args.name](*args.args)
|
|
52
|
+
import runpy
|
|
53
|
+
|
|
54
|
+
runf = runpy.run_module if args.module else runpy.run_path
|
|
55
|
+
runf(args.name, run_name="__main__")
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
sys.exit(_main())
|
sklearnex/_config.py
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# ==============================================================================
|
|
2
|
+
# Copyright 2021 Intel Corporation
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
# ==============================================================================
|
|
16
|
+
|
|
17
|
+
from contextlib import contextmanager
|
|
18
|
+
|
|
19
|
+
from sklearn import get_config as skl_get_config
|
|
20
|
+
from sklearn import set_config as skl_set_config
|
|
21
|
+
|
|
22
|
+
from onedal._config import _get_config as onedal_get_config
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def get_config():
|
|
26
|
+
"""Retrieve current values for configuration set by :func:`set_config`
|
|
27
|
+
Returns
|
|
28
|
+
-------
|
|
29
|
+
config : dict
|
|
30
|
+
Keys are parameter names that can be passed to :func:`set_config`.
|
|
31
|
+
See Also
|
|
32
|
+
--------
|
|
33
|
+
config_context : Context manager for global configuration.
|
|
34
|
+
set_config : Set global configuration.
|
|
35
|
+
"""
|
|
36
|
+
sklearn = skl_get_config()
|
|
37
|
+
sklearnex = onedal_get_config()
|
|
38
|
+
return {**sklearn, **sklearnex}
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def set_config(target_offload=None, allow_fallback_to_host=None, **sklearn_configs):
|
|
42
|
+
"""Set global configuration
|
|
43
|
+
Parameters
|
|
44
|
+
----------
|
|
45
|
+
target_offload : string or dpctl.SyclQueue, default=None
|
|
46
|
+
The device primarily used to perform computations.
|
|
47
|
+
If string, expected to be "auto" (the execution context
|
|
48
|
+
is deduced from input data location),
|
|
49
|
+
or SYCL* filter selector string. Global default: "auto".
|
|
50
|
+
allow_fallback_to_host : bool, default=None
|
|
51
|
+
If True, allows to fallback computation to host device
|
|
52
|
+
in case particular estimator does not support the selected one.
|
|
53
|
+
Global default: False.
|
|
54
|
+
See Also
|
|
55
|
+
--------
|
|
56
|
+
config_context : Context manager for global configuration.
|
|
57
|
+
get_config : Retrieve current values of the global configuration.
|
|
58
|
+
"""
|
|
59
|
+
skl_set_config(**sklearn_configs)
|
|
60
|
+
|
|
61
|
+
local_config = onedal_get_config(copy=False)
|
|
62
|
+
|
|
63
|
+
if target_offload is not None:
|
|
64
|
+
local_config["target_offload"] = target_offload
|
|
65
|
+
if allow_fallback_to_host is not None:
|
|
66
|
+
local_config["allow_fallback_to_host"] = allow_fallback_to_host
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
@contextmanager
|
|
70
|
+
def config_context(**new_config):
|
|
71
|
+
"""Context manager for global scikit-learn configuration
|
|
72
|
+
Parameters
|
|
73
|
+
----------
|
|
74
|
+
target_offload : string or dpctl.SyclQueue, default=None
|
|
75
|
+
The device primarily used to perform computations.
|
|
76
|
+
If string, expected to be "auto" (the execution context
|
|
77
|
+
is deduced from input data location),
|
|
78
|
+
or SYCL* filter selector string. Global default: "auto".
|
|
79
|
+
allow_fallback_to_host : bool, default=None
|
|
80
|
+
If True, allows to fallback computation to host device
|
|
81
|
+
in case particular estimator does not support the selected one.
|
|
82
|
+
Global default: False.
|
|
83
|
+
Notes
|
|
84
|
+
-----
|
|
85
|
+
All settings, not just those presently modified, will be returned to
|
|
86
|
+
their previous values when the context manager is exited.
|
|
87
|
+
See Also
|
|
88
|
+
--------
|
|
89
|
+
set_config : Set global scikit-learn configuration.
|
|
90
|
+
get_config : Retrieve current values of the global configuration.
|
|
91
|
+
"""
|
|
92
|
+
old_config = get_config()
|
|
93
|
+
set_config(**new_config)
|
|
94
|
+
|
|
95
|
+
try:
|
|
96
|
+
yield
|
|
97
|
+
finally:
|
|
98
|
+
set_config(**old_config)
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
# ==============================================================================
|
|
2
|
+
# Copyright 2021 Intel Corporation
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
# ==============================================================================
|
|
16
|
+
|
|
17
|
+
from functools import wraps
|
|
18
|
+
|
|
19
|
+
from onedal._device_offload import (
|
|
20
|
+
_copy_to_usm,
|
|
21
|
+
_get_global_queue,
|
|
22
|
+
_transfer_to_host,
|
|
23
|
+
dpnp_available,
|
|
24
|
+
)
|
|
25
|
+
from onedal.utils._array_api import _asarray, _is_numpy_namespace
|
|
26
|
+
|
|
27
|
+
if dpnp_available:
|
|
28
|
+
import dpnp
|
|
29
|
+
from onedal.utils._array_api import _convert_to_dpnp
|
|
30
|
+
|
|
31
|
+
from ._config import get_config
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def _get_backend(obj, queue, method_name, *data):
|
|
35
|
+
cpu_device = queue is None or queue.sycl_device.is_cpu
|
|
36
|
+
gpu_device = queue is not None and queue.sycl_device.is_gpu
|
|
37
|
+
|
|
38
|
+
if cpu_device:
|
|
39
|
+
patching_status = obj._onedal_cpu_supported(method_name, *data)
|
|
40
|
+
if patching_status.get_status():
|
|
41
|
+
return "onedal", queue, patching_status
|
|
42
|
+
else:
|
|
43
|
+
return "sklearn", None, patching_status
|
|
44
|
+
|
|
45
|
+
allow_fallback_to_host = get_config()["allow_fallback_to_host"]
|
|
46
|
+
|
|
47
|
+
if gpu_device:
|
|
48
|
+
patching_status = obj._onedal_gpu_supported(method_name, *data)
|
|
49
|
+
if patching_status.get_status():
|
|
50
|
+
return "onedal", queue, patching_status
|
|
51
|
+
else:
|
|
52
|
+
if allow_fallback_to_host:
|
|
53
|
+
patching_status = obj._onedal_cpu_supported(method_name, *data)
|
|
54
|
+
if patching_status.get_status():
|
|
55
|
+
return "onedal", None, patching_status
|
|
56
|
+
else:
|
|
57
|
+
return "sklearn", None, patching_status
|
|
58
|
+
else:
|
|
59
|
+
return "sklearn", None, patching_status
|
|
60
|
+
|
|
61
|
+
raise RuntimeError("Device support is not implemented")
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def dispatch(obj, method_name, branches, *args, **kwargs):
|
|
65
|
+
q = _get_global_queue()
|
|
66
|
+
q, hostargs = _transfer_to_host(q, *args)
|
|
67
|
+
q, hostvalues = _transfer_to_host(q, *kwargs.values())
|
|
68
|
+
hostkwargs = dict(zip(kwargs.keys(), hostvalues))
|
|
69
|
+
|
|
70
|
+
backend, q, patching_status = _get_backend(obj, q, method_name, *hostargs)
|
|
71
|
+
|
|
72
|
+
if backend == "onedal":
|
|
73
|
+
patching_status.write_log(queue=q)
|
|
74
|
+
return branches[backend](obj, *hostargs, **hostkwargs, queue=q)
|
|
75
|
+
if backend == "sklearn":
|
|
76
|
+
if (
|
|
77
|
+
"array_api_dispatch" in get_config()
|
|
78
|
+
and get_config()["array_api_dispatch"]
|
|
79
|
+
and "array_api_support" in obj._get_tags()
|
|
80
|
+
and obj._get_tags()["array_api_support"]
|
|
81
|
+
):
|
|
82
|
+
# If `array_api_dispatch` enabled and array api is supported for the stock scikit-learn,
|
|
83
|
+
# then raw inputs are used for the fallback.
|
|
84
|
+
patching_status.write_log()
|
|
85
|
+
return branches[backend](obj, *args, **kwargs)
|
|
86
|
+
else:
|
|
87
|
+
patching_status.write_log()
|
|
88
|
+
return branches[backend](obj, *hostargs, **hostkwargs)
|
|
89
|
+
raise RuntimeError(
|
|
90
|
+
f"Undefined backend {backend} in " f"{obj.__class__.__name__}.{method_name}"
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def wrap_output_data(func):
|
|
95
|
+
"""
|
|
96
|
+
Converts and moves the output arrays of the decorated function
|
|
97
|
+
to match the input array type and device.
|
|
98
|
+
"""
|
|
99
|
+
|
|
100
|
+
@wraps(func)
|
|
101
|
+
def wrapper(self, *args, **kwargs):
|
|
102
|
+
result = func(self, *args, **kwargs)
|
|
103
|
+
if not (len(args) == 0 and len(kwargs) == 0):
|
|
104
|
+
data = (*args, *kwargs.values())
|
|
105
|
+
usm_iface = getattr(data[0], "__sycl_usm_array_interface__", None)
|
|
106
|
+
if usm_iface is not None:
|
|
107
|
+
result = _copy_to_usm(usm_iface["syclobj"], result)
|
|
108
|
+
if dpnp_available and isinstance(data[0], dpnp.ndarray):
|
|
109
|
+
result = _convert_to_dpnp(result)
|
|
110
|
+
return result
|
|
111
|
+
config = get_config()
|
|
112
|
+
if not ("transform_output" in config and config["transform_output"]):
|
|
113
|
+
input_array_api = getattr(data[0], "__array_namespace__", lambda: None)()
|
|
114
|
+
if input_array_api:
|
|
115
|
+
input_array_api_device = data[0].device
|
|
116
|
+
result = _asarray(
|
|
117
|
+
result, input_array_api, device=input_array_api_device
|
|
118
|
+
)
|
|
119
|
+
return result
|
|
120
|
+
|
|
121
|
+
return wrapper
|
sklearnex/_utils.py
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
# ===============================================================================
|
|
2
|
+
# Copyright 2021 Intel Corporation
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
# ===============================================================================
|
|
16
|
+
|
|
17
|
+
import logging
|
|
18
|
+
import os
|
|
19
|
+
import sys
|
|
20
|
+
import warnings
|
|
21
|
+
|
|
22
|
+
from daal4py.sklearn._utils import (
|
|
23
|
+
PatchingConditionsChain as daal4py_PatchingConditionsChain,
|
|
24
|
+
)
|
|
25
|
+
from daal4py.sklearn._utils import daal_check_version
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class PatchingConditionsChain(daal4py_PatchingConditionsChain):
|
|
29
|
+
def get_status(self):
|
|
30
|
+
return self.patching_is_enabled
|
|
31
|
+
|
|
32
|
+
def write_log(self, queue=None):
|
|
33
|
+
if self.patching_is_enabled:
|
|
34
|
+
self.logger.info(
|
|
35
|
+
f"{self.scope_name}: {get_patch_message('onedal', queue=queue)}"
|
|
36
|
+
)
|
|
37
|
+
else:
|
|
38
|
+
self.logger.debug(
|
|
39
|
+
f"{self.scope_name}: debugging for the patch is enabled to track"
|
|
40
|
+
" the usage of Intel® oneAPI Data Analytics Library (oneDAL)"
|
|
41
|
+
)
|
|
42
|
+
for message in self.messages:
|
|
43
|
+
self.logger.debug(
|
|
44
|
+
f"{self.scope_name}: patching failed with cause - {message}"
|
|
45
|
+
)
|
|
46
|
+
self.logger.info(f"{self.scope_name}: {get_patch_message('sklearn')}")
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def set_sklearn_ex_verbose():
|
|
50
|
+
log_level = os.environ.get("SKLEARNEX_VERBOSE")
|
|
51
|
+
|
|
52
|
+
logger = logging.getLogger("sklearnex")
|
|
53
|
+
logging_channel = logging.StreamHandler()
|
|
54
|
+
logging_formatter = logging.Formatter("%(levelname)s:%(name)s: %(message)s")
|
|
55
|
+
logging_channel.setFormatter(logging_formatter)
|
|
56
|
+
logger.addHandler(logging_channel)
|
|
57
|
+
|
|
58
|
+
try:
|
|
59
|
+
if log_level is not None:
|
|
60
|
+
logger.setLevel(log_level)
|
|
61
|
+
except Exception:
|
|
62
|
+
warnings.warn(
|
|
63
|
+
'Unknown level "{}" for logging.\n'
|
|
64
|
+
'Please, use one of "CRITICAL", "ERROR", '
|
|
65
|
+
'"WARNING", "INFO", "DEBUG".'.format(log_level)
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def get_patch_message(s, queue=None):
|
|
70
|
+
if s == "onedal":
|
|
71
|
+
message = "running accelerated version on "
|
|
72
|
+
if queue is not None:
|
|
73
|
+
if queue.sycl_device.is_gpu:
|
|
74
|
+
message += "GPU"
|
|
75
|
+
elif queue.sycl_device.is_cpu:
|
|
76
|
+
message += "CPU"
|
|
77
|
+
else:
|
|
78
|
+
raise RuntimeError("Unsupported device")
|
|
79
|
+
else:
|
|
80
|
+
message += "CPU"
|
|
81
|
+
elif s == "sklearn":
|
|
82
|
+
message = "fallback to original Scikit-learn"
|
|
83
|
+
elif s == "sklearn_after_onedal":
|
|
84
|
+
message = "failed to run accelerated version, fallback to original Scikit-learn"
|
|
85
|
+
else:
|
|
86
|
+
raise ValueError(
|
|
87
|
+
f"Invalid input - expected one of 'onedal','sklearn',"
|
|
88
|
+
f" 'sklearn_after_onedal', got {s}"
|
|
89
|
+
)
|
|
90
|
+
return message
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def get_sklearnex_version(rule):
|
|
94
|
+
return daal_check_version(rule)
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def register_hyperparameters(hyperparameters_map):
|
|
98
|
+
"""Decorator for hyperparameters support in estimator class.
|
|
99
|
+
Adds `get_hyperparameters` method to class.
|
|
100
|
+
"""
|
|
101
|
+
|
|
102
|
+
def wrap_class(estimator_class):
|
|
103
|
+
def get_hyperparameters(self, op):
|
|
104
|
+
return hyperparameters_map[op]
|
|
105
|
+
|
|
106
|
+
estimator_class.get_hyperparameters = get_hyperparameters
|
|
107
|
+
return estimator_class
|
|
108
|
+
|
|
109
|
+
return wrap_class
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# ==============================================================================
|
|
2
|
+
# Copyright 2023 Intel Corporation
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
# ==============================================================================
|
|
16
|
+
|
|
17
|
+
from .basic_statistics import BasicStatistics
|
|
18
|
+
from .incremental_basic_statistics import IncrementalBasicStatistics
|
|
19
|
+
|
|
20
|
+
__all__ = ["BasicStatistics", "IncrementalBasicStatistics"]
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
# ==============================================================================
|
|
2
|
+
# Copyright 2023 Intel Corporation
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
# ==============================================================================
|
|
16
|
+
|
|
17
|
+
import numpy as np
|
|
18
|
+
from sklearn.base import BaseEstimator
|
|
19
|
+
from sklearn.utils import check_array
|
|
20
|
+
from sklearn.utils.validation import _check_sample_weight
|
|
21
|
+
|
|
22
|
+
from daal4py.sklearn._n_jobs_support import control_n_jobs
|
|
23
|
+
from daal4py.sklearn._utils import sklearn_check_version
|
|
24
|
+
from onedal.basic_statistics import BasicStatistics as onedal_BasicStatistics
|
|
25
|
+
|
|
26
|
+
from .._device_offload import dispatch
|
|
27
|
+
from .._utils import PatchingConditionsChain
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
@control_n_jobs(decorated_methods=["fit"])
|
|
31
|
+
class BasicStatistics(BaseEstimator):
|
|
32
|
+
"""
|
|
33
|
+
Estimator for basic statistics.
|
|
34
|
+
Allows to compute basic statistics for provided data.
|
|
35
|
+
Parameters
|
|
36
|
+
----------
|
|
37
|
+
result_options: string or list, default='all'
|
|
38
|
+
List of statistics to compute
|
|
39
|
+
|
|
40
|
+
Attributes (are existing only if corresponding result option exists)
|
|
41
|
+
----------
|
|
42
|
+
min : ndarray of shape (n_features,)
|
|
43
|
+
Minimum of each feature over all samples.
|
|
44
|
+
max : ndarray of shape (n_features,)
|
|
45
|
+
Maximum of each feature over all samples.
|
|
46
|
+
sum : ndarray of shape (n_features,)
|
|
47
|
+
Sum of each feature over all samples.
|
|
48
|
+
mean : ndarray of shape (n_features,)
|
|
49
|
+
Mean of each feature over all samples.
|
|
50
|
+
variance : ndarray of shape (n_features,)
|
|
51
|
+
Variance of each feature over all samples.
|
|
52
|
+
variation : ndarray of shape (n_features,)
|
|
53
|
+
Variation of each feature over all samples.
|
|
54
|
+
sum_squares : ndarray of shape (n_features,)
|
|
55
|
+
Sum of squares for each feature over all samples.
|
|
56
|
+
standard_deviation : ndarray of shape (n_features,)
|
|
57
|
+
Standard deviation of each feature over all samples.
|
|
58
|
+
sum_squares_centered : ndarray of shape (n_features,)
|
|
59
|
+
Centered sum of squares for each feature over all samples.
|
|
60
|
+
second_order_raw_moment : ndarray of shape (n_features,)
|
|
61
|
+
Second order moment of each feature over all samples.
|
|
62
|
+
"""
|
|
63
|
+
|
|
64
|
+
def __init__(self, result_options="all"):
|
|
65
|
+
self.options = result_options
|
|
66
|
+
|
|
67
|
+
_onedal_basic_statistics = staticmethod(onedal_BasicStatistics)
|
|
68
|
+
|
|
69
|
+
def _save_attributes(self):
|
|
70
|
+
assert hasattr(self, "_onedal_estimator")
|
|
71
|
+
|
|
72
|
+
if self.options == "all":
|
|
73
|
+
result_options = onedal_BasicStatistics.get_all_result_options()
|
|
74
|
+
else:
|
|
75
|
+
result_options = self.options
|
|
76
|
+
|
|
77
|
+
if isinstance(result_options, str):
|
|
78
|
+
setattr(self, result_options, getattr(self._onedal_estimator, result_options))
|
|
79
|
+
elif isinstance(result_options, list):
|
|
80
|
+
for option in result_options:
|
|
81
|
+
setattr(self, option, getattr(self._onedal_estimator, option))
|
|
82
|
+
|
|
83
|
+
def _onedal_supported(self, method_name, *data):
|
|
84
|
+
patching_status = PatchingConditionsChain(
|
|
85
|
+
f"sklearnex.basic_statistics.{self.__class__.__name__}.{method_name}"
|
|
86
|
+
)
|
|
87
|
+
return patching_status
|
|
88
|
+
|
|
89
|
+
_onedal_cpu_supported = _onedal_supported
|
|
90
|
+
_onedal_gpu_supported = _onedal_supported
|
|
91
|
+
|
|
92
|
+
def _onedal_fit(self, X, sample_weight=None, queue=None):
|
|
93
|
+
if sklearn_check_version("1.0"):
|
|
94
|
+
X = self._validate_data(X, dtype=[np.float64, np.float32], ensure_2d=False)
|
|
95
|
+
else:
|
|
96
|
+
X = check_array(X, dtype=[np.float64, np.float32])
|
|
97
|
+
|
|
98
|
+
if sample_weight is not None:
|
|
99
|
+
sample_weight = _check_sample_weight(sample_weight, X)
|
|
100
|
+
|
|
101
|
+
onedal_params = {
|
|
102
|
+
"result_options": self.options,
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if not hasattr(self, "_onedal_estimator"):
|
|
106
|
+
self._onedal_estimator = self._onedal_basic_statistics(**onedal_params)
|
|
107
|
+
self._onedal_estimator.fit(X, sample_weight, queue)
|
|
108
|
+
self._save_attributes()
|
|
109
|
+
|
|
110
|
+
def fit(self, X, y=None, *, sample_weight=None):
|
|
111
|
+
"""Compute statistics with X, using minibatches of size batch_size.
|
|
112
|
+
|
|
113
|
+
Parameters
|
|
114
|
+
----------
|
|
115
|
+
X : array-like of shape (n_samples, n_features)
|
|
116
|
+
Data for compute, where `n_samples` is the number of samples and
|
|
117
|
+
`n_features` is the number of features.
|
|
118
|
+
|
|
119
|
+
y : Ignored
|
|
120
|
+
Not used, present for API consistency by convention.
|
|
121
|
+
|
|
122
|
+
sample_weight : array-like of shape (n_samples,), default=None
|
|
123
|
+
Weights for compute weighted statistics, where `n_samples` is the number of samples.
|
|
124
|
+
|
|
125
|
+
Returns
|
|
126
|
+
-------
|
|
127
|
+
self : object
|
|
128
|
+
Returns the instance itself.
|
|
129
|
+
"""
|
|
130
|
+
dispatch(
|
|
131
|
+
self,
|
|
132
|
+
"fit",
|
|
133
|
+
{
|
|
134
|
+
"onedal": self.__class__._onedal_fit,
|
|
135
|
+
"sklearn": None,
|
|
136
|
+
},
|
|
137
|
+
X,
|
|
138
|
+
sample_weight,
|
|
139
|
+
)
|
|
140
|
+
return self
|