scikit-learn-intelex 2024.2.0__py312-none-manylinux1_x86_64.whl → 2024.3.0__py312-none-manylinux1_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.
- {scikit_learn_intelex-2024.2.0.dist-info → scikit_learn_intelex-2024.3.0.dist-info}/METADATA +2 -2
- {scikit_learn_intelex-2024.2.0.dist-info → scikit_learn_intelex-2024.3.0.dist-info}/RECORD +30 -33
- sklearnex/__init__.py +9 -7
- sklearnex/cluster/dbscan.py +3 -1
- sklearnex/conftest.py +63 -0
- sklearnex/decomposition/pca.py +322 -1
- sklearnex/decomposition/tests/test_pca.py +34 -5
- sklearnex/dispatcher.py +72 -41
- sklearnex/ensemble/_forest.py +10 -14
- sklearnex/ensemble/tests/test_forest.py +15 -19
- sklearnex/linear_model/logistic_regression.py +13 -2
- sklearnex/linear_model/tests/test_logreg.py +0 -2
- sklearnex/neighbors/_lof.py +39 -2
- sklearnex/neighbors/knn_classification.py +7 -9
- sklearnex/neighbors/knn_regression.py +6 -9
- sklearnex/neighbors/knn_unsupervised.py +5 -8
- sklearnex/neighbors/tests/test_neighbors.py +0 -5
- sklearnex/preview/__init__.py +1 -1
- sklearnex/spmd/ensemble/forest.py +4 -12
- sklearnex/svm/nusvc.py +4 -0
- sklearnex/svm/nusvr.py +3 -3
- sklearnex/svm/svc.py +4 -0
- sklearnex/tests/_utils.py +155 -0
- sklearnex/tests/test_memory_usage.py +8 -3
- sklearnex/tests/test_monkeypatch.py +177 -149
- sklearnex/tests/test_parallel.py +6 -8
- sklearnex/tests/test_patching.py +305 -80
- sklearnex/preview/decomposition/__init__.py +0 -19
- sklearnex/preview/decomposition/pca.py +0 -374
- sklearnex/preview/decomposition/tests/test_preview_pca.py +0 -42
- sklearnex/tests/_models_info.py +0 -170
- sklearnex/tests/utils/_launch_algorithms.py +0 -118
- {scikit_learn_intelex-2024.2.0.dist-info → scikit_learn_intelex-2024.3.0.dist-info}/LICENSE.txt +0 -0
- {scikit_learn_intelex-2024.2.0.dist-info → scikit_learn_intelex-2024.3.0.dist-info}/WHEEL +0 -0
- {scikit_learn_intelex-2024.2.0.dist-info → scikit_learn_intelex-2024.3.0.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
# ==============================================================================
|
|
2
|
+
# Copyright 2024 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 inspect import isclass
|
|
18
|
+
|
|
19
|
+
import numpy as np
|
|
20
|
+
from sklearn.base import (
|
|
21
|
+
BaseEstimator,
|
|
22
|
+
ClassifierMixin,
|
|
23
|
+
ClusterMixin,
|
|
24
|
+
OutlierMixin,
|
|
25
|
+
RegressorMixin,
|
|
26
|
+
TransformerMixin,
|
|
27
|
+
)
|
|
28
|
+
from sklearn.datasets import load_diabetes, load_iris
|
|
29
|
+
from sklearn.neighbors._base import KNeighborsMixin
|
|
30
|
+
|
|
31
|
+
from onedal.tests.utils._dataframes_support import _convert_to_dataframe
|
|
32
|
+
from sklearnex import get_patch_map, patch_sklearn, sklearn_is_patched, unpatch_sklearn
|
|
33
|
+
from sklearnex.neighbors import (
|
|
34
|
+
KNeighborsClassifier,
|
|
35
|
+
KNeighborsRegressor,
|
|
36
|
+
LocalOutlierFactor,
|
|
37
|
+
NearestNeighbors,
|
|
38
|
+
)
|
|
39
|
+
from sklearnex.svm import SVC, NuSVC
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def _load_all_models(with_sklearnex=True, estimator=True):
|
|
43
|
+
# insure that patch state is correct as dictated by patch_sklearn boolean
|
|
44
|
+
# and return it to the previous state no matter what occurs.
|
|
45
|
+
already_patched_map = sklearn_is_patched(return_map=True)
|
|
46
|
+
already_patched = any(already_patched_map.values())
|
|
47
|
+
try:
|
|
48
|
+
if with_sklearnex:
|
|
49
|
+
patch_sklearn()
|
|
50
|
+
elif already_patched:
|
|
51
|
+
unpatch_sklearn()
|
|
52
|
+
|
|
53
|
+
models = {}
|
|
54
|
+
for patch_infos in get_patch_map().values():
|
|
55
|
+
candidate = getattr(patch_infos[0][0][0], patch_infos[0][0][1], None)
|
|
56
|
+
if candidate is not None and isclass(candidate) == estimator:
|
|
57
|
+
if not estimator or issubclass(candidate, BaseEstimator):
|
|
58
|
+
models[patch_infos[0][0][1]] = candidate
|
|
59
|
+
finally:
|
|
60
|
+
if with_sklearnex:
|
|
61
|
+
unpatch_sklearn()
|
|
62
|
+
# both branches are now in an unpatched state, repatch as necessary
|
|
63
|
+
if already_patched:
|
|
64
|
+
patch_sklearn(name=[i for i in already_patched_map if already_patched_map[i]])
|
|
65
|
+
|
|
66
|
+
return models
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
PATCHED_MODELS = _load_all_models(with_sklearnex=True)
|
|
70
|
+
UNPATCHED_MODELS = _load_all_models(with_sklearnex=False)
|
|
71
|
+
|
|
72
|
+
PATCHED_FUNCTIONS = _load_all_models(with_sklearnex=True, estimator=False)
|
|
73
|
+
UNPATCHED_FUNCTIONS = _load_all_models(with_sklearnex=False, estimator=False)
|
|
74
|
+
|
|
75
|
+
mixin_map = [
|
|
76
|
+
[
|
|
77
|
+
ClassifierMixin,
|
|
78
|
+
["decision_function", "predict", "predict_proba", "predict_log_proba", "score"],
|
|
79
|
+
"classification",
|
|
80
|
+
],
|
|
81
|
+
[RegressorMixin, ["predict", "score"], "regression"],
|
|
82
|
+
[ClusterMixin, ["fit_predict"], "classification"],
|
|
83
|
+
[TransformerMixin, ["fit_transform", "transform", "score"], "classification"],
|
|
84
|
+
[OutlierMixin, ["fit_predict", "predict"], "classification"],
|
|
85
|
+
[KNeighborsMixin, ["kneighbors"], None],
|
|
86
|
+
]
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
SPECIAL_INSTANCES = {
|
|
90
|
+
str(i): i
|
|
91
|
+
for i in [
|
|
92
|
+
LocalOutlierFactor(novelty=True),
|
|
93
|
+
SVC(probability=True),
|
|
94
|
+
NuSVC(probability=True),
|
|
95
|
+
KNeighborsClassifier(algorithm="brute"),
|
|
96
|
+
KNeighborsRegressor(algorithm="brute"),
|
|
97
|
+
NearestNeighbors(algorithm="brute"),
|
|
98
|
+
]
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def gen_models_info(algorithms):
|
|
103
|
+
output = []
|
|
104
|
+
for i in algorithms:
|
|
105
|
+
# split handles SPECIAL_INSTANCES or custom inputs
|
|
106
|
+
# custom sklearn inputs must be a dict of estimators
|
|
107
|
+
# with keys set by the __str__ method
|
|
108
|
+
est = PATCHED_MODELS[i.split("(")[0]]
|
|
109
|
+
|
|
110
|
+
methods = set()
|
|
111
|
+
candidates = set(
|
|
112
|
+
[i for i in dir(est) if not i.startswith("_") and not i.endswith("_")]
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
for mixin, method, _ in mixin_map:
|
|
116
|
+
if issubclass(est, mixin):
|
|
117
|
+
methods |= candidates & set(method)
|
|
118
|
+
|
|
119
|
+
output += [[i, j] for j in methods]
|
|
120
|
+
return output
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def gen_dataset(estimator, queue=None, target_df=None, dtype=np.float64):
|
|
124
|
+
dataset = None
|
|
125
|
+
name = estimator.__class__.__name__
|
|
126
|
+
est = PATCHED_MODELS[name]
|
|
127
|
+
for mixin, _, data in mixin_map:
|
|
128
|
+
if issubclass(est, mixin) and data is not None:
|
|
129
|
+
dataset = data
|
|
130
|
+
# load data
|
|
131
|
+
if dataset == "classification" or dataset is None:
|
|
132
|
+
X, y = load_iris(return_X_y=True)
|
|
133
|
+
elif dataset == "regression":
|
|
134
|
+
X, y = load_diabetes(return_X_y=True)
|
|
135
|
+
else:
|
|
136
|
+
raise ValueError("Unknown dataset type")
|
|
137
|
+
|
|
138
|
+
X = _convert_to_dataframe(X, sycl_queue=queue, target_df=target_df, dtype=dtype)
|
|
139
|
+
y = _convert_to_dataframe(y, sycl_queue=queue, target_df=target_df, dtype=dtype)
|
|
140
|
+
return X, y
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
DTYPES = [
|
|
144
|
+
np.int8,
|
|
145
|
+
np.int16,
|
|
146
|
+
np.int32,
|
|
147
|
+
np.int64,
|
|
148
|
+
np.float16,
|
|
149
|
+
np.float32,
|
|
150
|
+
np.float64,
|
|
151
|
+
np.uint8,
|
|
152
|
+
np.uint16,
|
|
153
|
+
np.uint32,
|
|
154
|
+
np.uint64,
|
|
155
|
+
]
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
# limitations under the License.
|
|
15
15
|
# ==============================================================================
|
|
16
16
|
|
|
17
|
+
|
|
17
18
|
import gc
|
|
18
19
|
import logging
|
|
19
20
|
import tracemalloc
|
|
@@ -30,7 +31,6 @@ from sklearn.model_selection import KFold
|
|
|
30
31
|
from sklearnex import get_patch_map
|
|
31
32
|
from sklearnex.metrics import pairwise_distances, roc_auc_score
|
|
32
33
|
from sklearnex.model_selection import train_test_split
|
|
33
|
-
from sklearnex.preview.decomposition import PCA as PreviewPCA
|
|
34
34
|
from sklearnex.utils import _assert_all_finite
|
|
35
35
|
|
|
36
36
|
|
|
@@ -75,6 +75,8 @@ class RocAucEstimator:
|
|
|
75
75
|
|
|
76
76
|
|
|
77
77
|
# add all daal4py estimators enabled in patching (except banned)
|
|
78
|
+
|
|
79
|
+
|
|
78
80
|
def get_patched_estimators(ban_list, output_list):
|
|
79
81
|
patched_estimators = get_patch_map().values()
|
|
80
82
|
for listing in patched_estimators:
|
|
@@ -96,7 +98,6 @@ def remove_duplicated_estimators(estimators_list):
|
|
|
96
98
|
|
|
97
99
|
BANNED_ESTIMATORS = ("TSNE",) # too slow for using in testing on common data size
|
|
98
100
|
estimators = [
|
|
99
|
-
PreviewPCA,
|
|
100
101
|
TrainTestSplitEstimator,
|
|
101
102
|
FiniteCheckEstimator,
|
|
102
103
|
CosineDistancesEstimator,
|
|
@@ -153,6 +154,7 @@ def split_train_inference(kf, x, y, estimator):
|
|
|
153
154
|
y_train, y_test = y.iloc[train_index], y.iloc[test_index]
|
|
154
155
|
# TODO: add parameters for all estimators to prevent
|
|
155
156
|
# fallback to stock scikit-learn with default parameters
|
|
157
|
+
|
|
156
158
|
alg = estimator()
|
|
157
159
|
alg.fit(x_train, y_train)
|
|
158
160
|
if hasattr(alg, "predict"):
|
|
@@ -163,7 +165,6 @@ def split_train_inference(kf, x, y, estimator):
|
|
|
163
165
|
alg.kneighbors(x_test)
|
|
164
166
|
del alg, x_train, x_test, y_train, y_test
|
|
165
167
|
mem_tracks.append(tracemalloc.get_traced_memory()[0])
|
|
166
|
-
|
|
167
168
|
return mem_tracks
|
|
168
169
|
|
|
169
170
|
|
|
@@ -215,6 +216,10 @@ def _kfold_function_template(estimator, data_transform_function, data_shape):
|
|
|
215
216
|
)
|
|
216
217
|
|
|
217
218
|
|
|
219
|
+
# disable fallback check as logging impacts memory use
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
@pytest.mark.allow_sklearn_fallback
|
|
218
223
|
@pytest.mark.parametrize("data_transform_function", data_transforms)
|
|
219
224
|
@pytest.mark.parametrize("estimator", estimators)
|
|
220
225
|
@pytest.mark.parametrize("data_shape", data_shapes)
|
|
@@ -17,6 +17,12 @@
|
|
|
17
17
|
import sklearnex
|
|
18
18
|
from daal4py.sklearn._utils import daal_check_version
|
|
19
19
|
|
|
20
|
+
# General use of patch_sklearn and unpatch_sklearn in pytest is not recommended.
|
|
21
|
+
# It changes global state and can impact the operation of other tests. This file
|
|
22
|
+
# specifically tests patch_sklearn and unpatch_sklearn and is exempt from this.
|
|
23
|
+
# If sklearnex patching is necessary in testing, use the 'with_sklearnex' pytest
|
|
24
|
+
# fixture.
|
|
25
|
+
|
|
20
26
|
|
|
21
27
|
def test_monkey_patching():
|
|
22
28
|
_tokens = sklearnex.get_patch_names()
|
|
@@ -27,150 +33,170 @@ def test_monkey_patching():
|
|
|
27
33
|
for c in v:
|
|
28
34
|
_classes.append(c[0])
|
|
29
35
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
"
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
sklearn_class
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
36
|
+
try:
|
|
37
|
+
sklearnex.patch_sklearn()
|
|
38
|
+
|
|
39
|
+
for i, _ in enumerate(_tokens):
|
|
40
|
+
t = _tokens[i]
|
|
41
|
+
p = _classes[i][0]
|
|
42
|
+
n = _classes[i][1]
|
|
43
|
+
|
|
44
|
+
class_module = getattr(p, n).__module__
|
|
45
|
+
assert class_module.startswith("daal4py") or class_module.startswith(
|
|
46
|
+
"sklearnex"
|
|
47
|
+
), "Patching has completed with error."
|
|
48
|
+
|
|
49
|
+
for i, _ in enumerate(_tokens):
|
|
50
|
+
t = _tokens[i]
|
|
51
|
+
p = _classes[i][0]
|
|
52
|
+
n = _classes[i][1]
|
|
53
|
+
|
|
54
|
+
sklearnex.unpatch_sklearn(t)
|
|
55
|
+
sklearn_class = getattr(p, n, None)
|
|
56
|
+
if sklearn_class is not None:
|
|
57
|
+
sklearn_class = sklearn_class.__module__
|
|
58
|
+
assert sklearn_class is None or sklearn_class.startswith(
|
|
59
|
+
"sklearn"
|
|
60
|
+
), "Unpatching has completed with error."
|
|
61
|
+
|
|
62
|
+
finally:
|
|
63
|
+
sklearnex.unpatch_sklearn()
|
|
64
|
+
|
|
65
|
+
try:
|
|
66
|
+
for i, _ in enumerate(_tokens):
|
|
67
|
+
t = _tokens[i]
|
|
68
|
+
p = _classes[i][0]
|
|
69
|
+
n = _classes[i][1]
|
|
70
|
+
|
|
71
|
+
sklearn_class = getattr(p, n, None)
|
|
72
|
+
if sklearn_class is not None:
|
|
73
|
+
sklearn_class = sklearn_class.__module__
|
|
74
|
+
assert sklearn_class is None or sklearn_class.startswith(
|
|
75
|
+
"sklearn"
|
|
76
|
+
), "Unpatching has completed with error."
|
|
77
|
+
|
|
78
|
+
finally:
|
|
79
|
+
sklearnex.unpatch_sklearn()
|
|
80
|
+
|
|
81
|
+
try:
|
|
82
|
+
for i, _ in enumerate(_tokens):
|
|
83
|
+
t = _tokens[i]
|
|
84
|
+
p = _classes[i][0]
|
|
85
|
+
n = _classes[i][1]
|
|
86
|
+
|
|
87
|
+
sklearnex.patch_sklearn(t)
|
|
88
|
+
|
|
89
|
+
class_module = getattr(p, n).__module__
|
|
90
|
+
assert class_module.startswith("daal4py") or class_module.startswith(
|
|
91
|
+
"sklearnex"
|
|
92
|
+
), "Patching has completed with error."
|
|
93
|
+
finally:
|
|
94
|
+
sklearnex.unpatch_sklearn()
|
|
84
95
|
|
|
85
96
|
|
|
86
97
|
def test_patch_by_list_simple():
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
from sklearn.ensemble import RandomForestRegressor
|
|
90
|
-
from sklearn.linear_model import LogisticRegression
|
|
91
|
-
from sklearn.neighbors import KNeighborsRegressor
|
|
92
|
-
from sklearn.svm import SVC
|
|
98
|
+
try:
|
|
99
|
+
sklearnex.patch_sklearn(["LogisticRegression"])
|
|
93
100
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
else:
|
|
99
|
-
assert LogisticRegression.__module__.startswith("daal4py")
|
|
100
|
-
assert SVC.__module__.startswith("sklearn")
|
|
101
|
+
from sklearn.ensemble import RandomForestRegressor
|
|
102
|
+
from sklearn.linear_model import LogisticRegression
|
|
103
|
+
from sklearn.neighbors import KNeighborsRegressor
|
|
104
|
+
from sklearn.svm import SVC
|
|
101
105
|
|
|
102
|
-
|
|
106
|
+
assert RandomForestRegressor.__module__.startswith("sklearn")
|
|
107
|
+
assert KNeighborsRegressor.__module__.startswith("sklearn")
|
|
108
|
+
if daal_check_version((2024, "P", 1)):
|
|
109
|
+
assert LogisticRegression.__module__.startswith("sklearnex")
|
|
110
|
+
else:
|
|
111
|
+
assert LogisticRegression.__module__.startswith("daal4py")
|
|
112
|
+
assert SVC.__module__.startswith("sklearn")
|
|
113
|
+
finally:
|
|
114
|
+
sklearnex.unpatch_sklearn()
|
|
103
115
|
|
|
104
116
|
|
|
105
117
|
def test_patch_by_list_many_estimators():
|
|
106
|
-
|
|
118
|
+
try:
|
|
119
|
+
sklearnex.patch_sklearn(["LogisticRegression", "SVC"])
|
|
107
120
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
121
|
+
from sklearn.ensemble import RandomForestRegressor
|
|
122
|
+
from sklearn.linear_model import LogisticRegression
|
|
123
|
+
from sklearn.neighbors import KNeighborsRegressor
|
|
124
|
+
from sklearn.svm import SVC
|
|
112
125
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
126
|
+
assert RandomForestRegressor.__module__.startswith("sklearn")
|
|
127
|
+
assert KNeighborsRegressor.__module__.startswith("sklearn")
|
|
128
|
+
if daal_check_version((2024, "P", 1)):
|
|
129
|
+
assert LogisticRegression.__module__.startswith("sklearnex")
|
|
130
|
+
else:
|
|
131
|
+
assert LogisticRegression.__module__.startswith("daal4py")
|
|
132
|
+
assert SVC.__module__.startswith("daal4py") or SVC.__module__.startswith(
|
|
133
|
+
"sklearnex"
|
|
134
|
+
)
|
|
120
135
|
|
|
121
|
-
|
|
136
|
+
finally:
|
|
137
|
+
sklearnex.unpatch_sklearn()
|
|
122
138
|
|
|
123
139
|
|
|
124
140
|
def test_unpatch_by_list_many_estimators():
|
|
125
|
-
|
|
141
|
+
try:
|
|
142
|
+
sklearnex.patch_sklearn()
|
|
126
143
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
144
|
+
from sklearn.ensemble import RandomForestRegressor
|
|
145
|
+
from sklearn.linear_model import LogisticRegression
|
|
146
|
+
from sklearn.neighbors import KNeighborsRegressor
|
|
147
|
+
from sklearn.svm import SVC
|
|
131
148
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
149
|
+
assert RandomForestRegressor.__module__.startswith("sklearnex")
|
|
150
|
+
assert KNeighborsRegressor.__module__.startswith(
|
|
151
|
+
"daal4py"
|
|
152
|
+
) or KNeighborsRegressor.__module__.startswith("sklearnex")
|
|
153
|
+
if daal_check_version((2024, "P", 1)):
|
|
154
|
+
assert LogisticRegression.__module__.startswith("sklearnex")
|
|
155
|
+
else:
|
|
156
|
+
assert LogisticRegression.__module__.startswith("daal4py")
|
|
157
|
+
assert SVC.__module__.startswith("daal4py") or SVC.__module__.startswith(
|
|
158
|
+
"sklearnex"
|
|
159
|
+
)
|
|
141
160
|
|
|
142
|
-
|
|
161
|
+
sklearnex.unpatch_sklearn(["KNeighborsRegressor", "RandomForestRegressor"])
|
|
143
162
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
163
|
+
from sklearn.ensemble import RandomForestRegressor
|
|
164
|
+
from sklearn.linear_model import LogisticRegression
|
|
165
|
+
from sklearn.neighbors import KNeighborsRegressor
|
|
166
|
+
from sklearn.svm import SVC
|
|
148
167
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
168
|
+
assert RandomForestRegressor.__module__.startswith("sklearn")
|
|
169
|
+
assert KNeighborsRegressor.__module__.startswith("sklearn")
|
|
170
|
+
if daal_check_version((2024, "P", 1)):
|
|
171
|
+
assert LogisticRegression.__module__.startswith("sklearnex")
|
|
172
|
+
else:
|
|
173
|
+
assert LogisticRegression.__module__.startswith("daal4py")
|
|
155
174
|
|
|
156
|
-
|
|
175
|
+
assert SVC.__module__.startswith("daal4py") or SVC.__module__.startswith(
|
|
176
|
+
"sklearnex"
|
|
177
|
+
)
|
|
178
|
+
finally:
|
|
179
|
+
sklearnex.unpatch_sklearn()
|
|
157
180
|
|
|
158
181
|
|
|
159
182
|
def test_patching_checker():
|
|
160
183
|
for name in [None, "SVC", "PCA"]:
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
184
|
+
try:
|
|
185
|
+
sklearnex.patch_sklearn(name=name)
|
|
186
|
+
assert sklearnex.sklearn_is_patched(name=name)
|
|
187
|
+
|
|
188
|
+
finally:
|
|
189
|
+
sklearnex.unpatch_sklearn(name=name)
|
|
190
|
+
assert not sklearnex.sklearn_is_patched(name=name)
|
|
191
|
+
try:
|
|
192
|
+
sklearnex.patch_sklearn()
|
|
193
|
+
patching_status_map = sklearnex.sklearn_is_patched(return_map=True)
|
|
194
|
+
assert len(patching_status_map) == len(sklearnex.get_patch_names())
|
|
195
|
+
for status in patching_status_map.values():
|
|
196
|
+
assert status
|
|
197
|
+
finally:
|
|
198
|
+
sklearnex.unpatch_sklearn()
|
|
166
199
|
|
|
167
|
-
sklearnex.patch_sklearn()
|
|
168
|
-
patching_status_map = sklearnex.sklearn_is_patched(return_map=True)
|
|
169
|
-
assert len(patching_status_map) == len(sklearnex.get_patch_names())
|
|
170
|
-
for status in patching_status_map.values():
|
|
171
|
-
assert status
|
|
172
|
-
|
|
173
|
-
sklearnex.unpatch_sklearn()
|
|
174
200
|
patching_status_map = sklearnex.sklearn_is_patched(return_map=True)
|
|
175
201
|
assert len(patching_status_map) == len(sklearnex.get_patch_names())
|
|
176
202
|
for status in patching_status_map.values():
|
|
@@ -193,27 +219,27 @@ def test_preview_namespace():
|
|
|
193
219
|
RandomForestClassifier(),
|
|
194
220
|
)
|
|
195
221
|
|
|
196
|
-
# BUG: previous patching tests force PCA to be patched with daal4py.
|
|
197
|
-
# This unpatching returns behavior to expected
|
|
198
|
-
sklearnex.unpatch_sklearn()
|
|
199
|
-
# behavior with enabled preview
|
|
200
|
-
sklearnex.patch_sklearn(preview=True)
|
|
201
222
|
from sklearnex.dispatcher import _is_preview_enabled
|
|
202
223
|
|
|
203
|
-
|
|
224
|
+
try:
|
|
225
|
+
sklearnex.patch_sklearn(preview=True)
|
|
204
226
|
|
|
205
|
-
|
|
206
|
-
|
|
227
|
+
assert _is_preview_enabled()
|
|
228
|
+
|
|
229
|
+
lr, pca, dbscan, svc, rfc = get_estimators()
|
|
230
|
+
assert "sklearnex" in rfc.__module__
|
|
207
231
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
232
|
+
if daal_check_version((2023, "P", 100)):
|
|
233
|
+
assert "sklearnex" in lr.__module__
|
|
234
|
+
else:
|
|
235
|
+
assert "daal4py" in lr.__module__
|
|
212
236
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
237
|
+
assert "sklearnex" in pca.__module__
|
|
238
|
+
assert "sklearnex" in dbscan.__module__
|
|
239
|
+
assert "sklearnex" in svc.__module__
|
|
240
|
+
|
|
241
|
+
finally:
|
|
242
|
+
sklearnex.unpatch_sklearn()
|
|
217
243
|
|
|
218
244
|
# no patching behavior
|
|
219
245
|
lr, pca, dbscan, svc, rfc = get_estimators()
|
|
@@ -224,17 +250,19 @@ def test_preview_namespace():
|
|
|
224
250
|
assert "sklearn." in rfc.__module__ and "daal4py" not in rfc.__module__
|
|
225
251
|
|
|
226
252
|
# default patching behavior
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
253
|
+
try:
|
|
254
|
+
sklearnex.patch_sklearn()
|
|
255
|
+
assert not _is_preview_enabled()
|
|
256
|
+
|
|
257
|
+
lr, pca, dbscan, svc, rfc = get_estimators()
|
|
258
|
+
if daal_check_version((2023, "P", 100)):
|
|
259
|
+
assert "sklearnex" in lr.__module__
|
|
260
|
+
else:
|
|
261
|
+
assert "daal4py" in lr.__module__
|
|
262
|
+
|
|
263
|
+
assert "sklearnex" in pca.__module__
|
|
264
|
+
assert "sklearnex" in rfc.__module__
|
|
265
|
+
assert "sklearnex" in dbscan.__module__
|
|
266
|
+
assert "sklearnex" in svc.__module__
|
|
267
|
+
finally:
|
|
268
|
+
sklearnex.unpatch_sklearn()
|
sklearnex/tests/test_parallel.py
CHANGED
|
@@ -15,13 +15,7 @@
|
|
|
15
15
|
# ==============================================================================
|
|
16
16
|
import pytest
|
|
17
17
|
|
|
18
|
-
from sklearnex import config_context
|
|
19
|
-
|
|
20
|
-
patch_sklearn()
|
|
21
|
-
|
|
22
|
-
from sklearn.datasets import make_classification
|
|
23
|
-
from sklearn.ensemble import BaggingClassifier
|
|
24
|
-
from sklearn.svm import SVC
|
|
18
|
+
from sklearnex import config_context
|
|
25
19
|
|
|
26
20
|
try:
|
|
27
21
|
import dpctl
|
|
@@ -38,7 +32,11 @@ except (ImportError, ModuleNotFoundError):
|
|
|
38
32
|
"to see raised 'SyclQueueCreationError'. "
|
|
39
33
|
"'dpctl' module is required for test.",
|
|
40
34
|
)
|
|
41
|
-
def test_config_context_in_parallel():
|
|
35
|
+
def test_config_context_in_parallel(with_sklearnex):
|
|
36
|
+
from sklearn.datasets import make_classification
|
|
37
|
+
from sklearn.ensemble import BaggingClassifier
|
|
38
|
+
from sklearn.svm import SVC
|
|
39
|
+
|
|
42
40
|
x, y = make_classification(random_state=42)
|
|
43
41
|
try:
|
|
44
42
|
with config_context(target_offload="gpu", allow_fallback_to_host=False):
|