Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[experiment] ENH: using only raw inputs for onedal backend #2153

Open
wants to merge 88 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
daed528
ENH: using only raw inputs for onedal backend
samir-nasibli Nov 5, 2024
1be2ffb
minor fix
samir-nasibli Nov 5, 2024
a23b677
lin
samir-nasibli Nov 5, 2024
664e140
fix usw_raw_input True/False with dpctl tensor on device
ahuber21 Nov 5, 2024
518dceb
Add hacks to kmeans
ahuber21 Nov 5, 2024
df9d930
Basic statistics online
samir-nasibli Nov 5, 2024
2954913
Merge branch 'enh/raw_inputs' of https://github.com/samir-nasibli/sci…
samir-nasibli Nov 5, 2024
3ef345c
Covariance support
ethanglaser Nov 5, 2024
f1c9233
Merge branch 'enh/raw_inputs' of https://github.com/samir-nasibli/sci…
ethanglaser Nov 5, 2024
66d7b2d
DBSCAN support
samir-nasibli Nov 5, 2024
c5d26a4
Merge branch 'enh/raw_inputs' of https://github.com/samir-nasibli/sci…
samir-nasibli Nov 5, 2024
1350c10
minor fix for dbscan
samir-nasibli Nov 5, 2024
8aaaa70
minor fix for DBSCAN
samir-nasibli Nov 5, 2024
f0d92ae
Apply raw input for batch linear and logistic regression
Alexsandruss Nov 5, 2024
3b58beb
Apply linters
Alexsandruss Nov 5, 2024
d7f2c3c
fix for DBSCAN
samir-nasibli Nov 5, 2024
1aca420
support for Random Forest
samir-nasibli Nov 5, 2024
362930a
PCA support (batch)
ethanglaser Nov 5, 2024
bc37391
Merge branch 'enh/raw_inputs' of https://github.com/samir-nasibli/sci…
ethanglaser Nov 5, 2024
102dcae
minor fix for dbscan and rf
samir-nasibli Nov 5, 2024
6edab5b
fully fixed DBSCAN
samir-nasibli Nov 6, 2024
e153a28
Add Incremental Linear Regression
Alexsandruss Nov 6, 2024
37d32c9
Linting
Alexsandruss Nov 6, 2024
71c5135
add modification to knn
ahuber21 Nov 6, 2024
db9f021
minor update for RF
samir-nasibli Nov 6, 2024
bc353da
fix for RandomForestClassifier
samir-nasibli Nov 7, 2024
e873205
minor for RF
samir-nasibli Nov 7, 2024
fe3222a
Update online algos
olegkkruglov Nov 7, 2024
5b3ad17
Merge branch 'enh/raw_inputs' of https://github.com/samir-nasibli/sci…
samir-nasibli Nov 7, 2024
eaaab32
fix for RF regressor
samir-nasibli Nov 7, 2024
a7f0c2d
fix workaround for knn
ahuber21 Nov 7, 2024
d9a2966
kmeans predict support
ethanglaser Nov 12, 2024
3562c69
Merge remote-tracking branch 'origin/main' into enh/raw_inputs
ahuber21 Dec 16, 2024
42c3614
fix merge errors
ahuber21 Dec 16, 2024
53bcc7b
fix some tests
ahuber21 Dec 17, 2024
9964c5a
fixup
ahuber21 Dec 17, 2024
84afb62
undo more changes that broke tests
ahuber21 Dec 17, 2024
cf5b736
format
ahuber21 Dec 17, 2024
92393b9
restore original behavior when running without raw inputs
ahuber21 Dec 18, 2024
13471e5
restore original behavior when running without raw inputs
ahuber21 Dec 18, 2024
a8f3f19
align code
ahuber21 Dec 18, 2024
2b07c00
restore original from_table
ahuber21 Dec 19, 2024
6104736
add use_raw_input tests for incremental covariance
ahuber21 Dec 19, 2024
df03233
Add basic statistics testing
ahuber21 Dec 19, 2024
8a166b7
add incremental basic statistics
ahuber21 Dec 19, 2024
fb5f5fa
add dbscan
ahuber21 Dec 19, 2024
7072041
Merge remote-tracking branch 'origin/main' into dev/ahuber/raw-inputs…
ahuber21 Dec 19, 2024
91384ed
add kmeans
ahuber21 Dec 20, 2024
6dec57d
add covariance
ahuber21 Dec 20, 2024
529a7b8
align get_config() import and use_raw_input retrieval
ahuber21 Dec 20, 2024
9f78cbd
add incremental_pca
ahuber21 Dec 20, 2024
658ccc1
add pca
ahuber21 Dec 20, 2024
5e74a54
add incremental linear
ahuber21 Dec 20, 2024
dfbf223
add linear_model
ahuber21 Dec 22, 2024
c4094fb
Merge branch 'dev/ahuber/raw-inputs-dispatching' into enh/raw_inputs
ahuber21 Dec 22, 2024
bb5206f
raw inputs updates for functional forest predict
ethanglaser Jan 9, 2025
8211a23
fixes for logreg predict_proba, knnreg, inc cov, inc pca
ethanglaser Jan 18, 2025
e3425bf
dbscan + inc linreg changes
ethanglaser Jan 20, 2025
0630bc1
Merge 'upstream/main' into enh/raw_inputs
ethanglaser Jan 20, 2025
52ba18a
black
ethanglaser Jan 20, 2025
90b7175
temporary for CI
ethanglaser Jan 21, 2025
f4d18cd
isorted
ethanglaser Jan 21, 2025
d84a559
tuple indices safeguarding
ethanglaser Jan 22, 2025
2daeeb7
incremental bs fit fixes
ethanglaser Jan 22, 2025
fb3d0bc
dbscan CI fixes
ethanglaser Jan 22, 2025
a7bd2cd
use xp to take samples to avoid data copying
ahuber21 Jan 29, 2025
d64c6fe
align setting of use_raw_input
ethanglaser Feb 4, 2025
7dbf8df
Merge remote-tracking branch 'upstream/main' into enh/raw_inputs
ethanglaser Feb 13, 2025
4e0ec33
isort
ethanglaser Feb 13, 2025
a8c9fe0
unify and clean up onedal4py changes, remove raw ridge
ethanglaser Feb 13, 2025
83342f7
remove unnecessary sklearnex raw inputs, move tests to spmd
ethanglaser Feb 14, 2025
87746b2
minor followup
ethanglaser Feb 14, 2025
12e0f08
cleanup of remaining sklearnex changes
ethanglaser Feb 14, 2025
bb9bdec
oops
ethanglaser Feb 15, 2025
8b7725f
Merge remote-tracking branch 'upstream/main' into enh/raw_inputs
ethanglaser Feb 17, 2025
b84c129
switch to config_context only on spmd estimator in tests
ethanglaser Feb 18, 2025
1249d44
CI fixes for PCA and linreg
ethanglaser Feb 19, 2025
d77a6b2
logistic regression CI fixes
ethanglaser Feb 19, 2025
5f28a69
fix forest CI and unify logreg and forest n_classes_
ethanglaser Feb 20, 2025
7af5977
switch back to dpep for dpnp tests
ethanglaser Feb 20, 2025
e155695
forest cleanup and accuracy issue resolution
ethanglaser Feb 25, 2025
17d152f
add back astype conditions
ethanglaser Feb 25, 2025
e3b09cc
more attempted ci fixes (logreg np and forest)
ethanglaser Feb 25, 2025
5848248
format
ethanglaser Feb 25, 2025
6bdd227
remove unnecessary online attributes
ethanglaser Feb 25, 2025
3a83708
knnreg workaround
ethanglaser Feb 25, 2025
aba7e40
cleanup
ethanglaser Feb 26, 2025
f7f9fe8
add queue setting to rf predict_proba
ethanglaser Feb 26, 2025
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
Prev Previous commit
Next Next commit
DBSCAN support
samir-nasibli committed Nov 5, 2024

Unverified

No user is associated with the committer email.
commit 66d7b2df3e752292cbd9cd6e8776081d249fb2b2
44 changes: 34 additions & 10 deletions onedal/cluster/dbscan.py
Original file line number Diff line number Diff line change
@@ -18,10 +18,12 @@

from daal4py.sklearn._utils import get_dtype, make2d

from .._config import _get_config
from ..common._base import BaseEstimator
from ..common._mixin import ClusterMixin
from ..datatypes import _convert_to_supported, from_table, to_table
from ..utils import _check_array
from ..utils._array_api import _get_sycl_namespace


class BaseDBSCAN(BaseEstimator, ClusterMixin):
@@ -58,26 +60,48 @@ def _get_onedal_params(self, dtype=np.float32):

def _fit(self, X, y, sample_weight, module, queue):
policy = self._get_policy(queue, X)
X = _check_array(X, accept_sparse="csr", dtype=[np.float64, np.float32])
sample_weight = make2d(sample_weight) if sample_weight is not None else None
X = make2d(X)
use_raw_input = _get_config().get("use_raw_input", False) is True
sua_iface, xp, _ = _get_sycl_namespace(X)

# All data should use the same sycl queue
if use_raw_input and sua_iface is not None:
queue = X.sycl_queue

if not use_raw_input:
X = _check_array(X, accept_sparse="csr", dtype=[np.float64, np.float32])
sample_weight = make2d(sample_weight) if sample_weight is not None else None
X = make2d(X)

types = [np.float32, np.float64]
if get_dtype(X) not in types:
X = X.astype(np.float64)
X = _convert_to_supported(policy, X)
dtype = get_dtype(X)
params = self._get_onedal_params(dtype)
result = module.compute(policy, params, to_table(X), to_table(sample_weight))

self.labels_ = from_table(result.responses).ravel()
X_table = to_table(X, sua_iface=sua_iface)
weights_table = to_table(
sample_weight, sua_iface=_get_sycl_namespace(sample_weight)[0]
)

result = module.compute(policy, params, X_table, weights_table)

self.labels_ = xp.reshape(
from_table(result.responses, sua_iface=sua_iface, sycl_queue=queue, xp=xp), -1
)
if result.core_observation_indices is not None:
self.core_sample_indices_ = from_table(
result.core_observation_indices
).ravel()
self.core_sample_indices_ = xp.reshape(
from_table(
result.core_observation_indices,
sua_iface=sua_iface,
sycl_queue=queue,
xp=xp,
),
-1,
)
else:
self.core_sample_indices_ = np.array([], dtype=np.intc)
self.components_ = np.take(X, self.core_sample_indices_, axis=0)
self.core_sample_indices_ = xp.array([], dtype=xp.int32)
self.components_ = xp.take(X, self.core_sample_indices_, axis=0)
self.n_features_in_ = X.shape[1]
return self

13 changes: 9 additions & 4 deletions sklearnex/cluster/dbscan.py
Copy link
Contributor Author

@samir-nasibli samir-nasibli Nov 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sense for dbscan and rf use just onedal4py API only for raw inputs.

Original file line number Diff line number Diff line change
@@ -27,6 +27,7 @@

from .._device_offload import dispatch
from .._utils import PatchingConditionsChain
from ..config import get_config

if sklearn_check_version("1.1") and not sklearn_check_version("1.2"):
from sklearn.utils import check_scalar
@@ -89,8 +90,10 @@ def __init__(
self.n_jobs = n_jobs

def _onedal_fit(self, X, y, sample_weight=None, queue=None):
if sklearn_check_version("1.0"):
X = validate_data(self, X, force_all_finite=False)
use_raw_input = _get_config().get("use_raw_input", False) is True
if use_raw_input:
if sklearn_check_version("1.0"):
X = validate_data(self, X, force_all_finite=False)

onedal_params = {
"eps": self.eps,
@@ -140,6 +143,7 @@ def _onedal_gpu_supported(self, method_name, *data):
return self._onedal_supported(method_name, *data)

def fit(self, X, y=None, sample_weight=None):
use_raw_input = _get_config().get("use_raw_input", False) is True
if sklearn_check_version("1.2"):
self._validate_params()
elif sklearn_check_version("1.1"):
@@ -178,8 +182,9 @@ def fit(self, X, y=None, sample_weight=None):
if self.eps <= 0.0:
raise ValueError(f"eps == {self.eps}, must be > 0.0.")

if sample_weight is not None:
sample_weight = _check_sample_weight(sample_weight, X)
if use_raw_input:
if sample_weight is not None:
sample_weight = _check_sample_weight(sample_weight, X)
dispatch(
self,
"fit",