|
24 | 24 | from daal4py.sklearn.monkeypatch.dispatcher import PatchMap |
25 | 25 |
|
26 | 26 |
|
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 | | - |
33 | 27 | def _is_preview_enabled() -> bool: |
34 | 28 | return "SKLEARNEX_PREVIEW" in os.environ |
35 | 29 |
|
@@ -58,68 +52,54 @@ def get_patch_map_core(preview: bool = False) -> PatchMap: |
58 | 52 | if preview: |
59 | 53 | mapping = get_patch_map_core(preview=False) |
60 | 54 |
|
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, |
66 | 94 | ) |
67 | | - from sklearn.decomposition import IncrementalPCA as IncrementalPCA_sklearn |
68 | 95 |
|
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, |
72 | 101 | ) |
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 |
123 | 103 |
|
124 | 104 | # Scikit-learn* modules |
125 | 105 | import sklearn as base_module |
@@ -515,7 +495,7 @@ def patch_sklearn( |
515 | 495 |
|
516 | 496 | patch_map: PatchMap = get_patch_map() |
517 | 497 |
|
518 | | - if name is not None and _is_new_patching_available(): |
| 498 | + if name is not None: |
519 | 499 | names_mandatory = [ |
520 | 500 | "sklearn.set_config", |
521 | 501 | "sklearn.get_config", |
|
0 commit comments