uxlfoundation/scikit-learn-intelex

Not able to reproduce PCA optimization using sklearn

Closed this issue · 3 comments

I am not able to PCA optimization using scikit-learn-intelex.

To Reproduce
python=3.9.0, scikit-learn-intelex=2024.3.0, scikit-learn=1.4.2 and numpy=1.26.4

export SKLEARNEX_VERBOSE=INFO
from sklearn import datasets, decomposition
import numpy as np
from sklearnex import patch_sklearn
patch_sklearn()

np.random.seed(5)

X=np.random.rand(1000000, 4000)
print(X)
import time
t0=time.time()
pca = decomposition.PCA(n_components=50)
pca.fit(X)
X = pca.transform(X)
print("pca time:",time.time()-t0) 

Screenshot (489)

The above code falling back to original scikit-learn. I am getting better runtime with old setup

python=3.8.0,scikit-learn=1.0.2,scikit-learn-intelex=2023.0.1 and numpy=1.24.4

Screenshot (488)

Sklearn 1.1 version changed auto solver selection rules so patched solver is not used for this data shape starting from this version.
You can explicitly request patched solver by using svd_solver parameter:

decomposition.PCA(svd_solver="full") # for sklearn < 1.5
decomposition.PCA(svd_solver="covariance_eigh") # for sklearn >= 1.5

@Alexsandruss Thanks for quick reply. Using decomposition.PCA(svd_solver="full"), it takes 20 sec. Which is slower than older version (It was using svd_solver=auto). Is it expected result or am i missing something?

@Alexsandruss Thanks for quick reply. Using decomposition.PCA(svd_solver="full"), it takes 20 sec. Which is slower than older version (It was using svd_solver=auto). Is it expected result or am i missing something?

It is possible because PCA had significant code changes since 2023.0.1 version including backend change and accuracy bugfixes.