英文:
Does sklearnex (sklearn-intel-extension) really support linear regression?
问题
我尝试使用 sklearnex/scikit-learn-intelex 来进行 GPU 加速。这是我的代码,学习自 'Patching several algorithms:':
try:
from sklearnex import patch_sklearn
patch_sklearn()
except:
pass
patch_sklearn(['PCA','LinearRegression'])
根据官方文档,该包支持线性回归。然而,在我的机器上它返回以下错误:
> Intel(R) Extension for Scikit-learn* enabled (https://github.com/intel/scikit-learn-intelex)
> Traceback (most recent call last):
> File "/home/path/tmp_test.py", line 16, in <module>
> patch_sklearn(['PCA','LinearRegression'])
> File "/usr/local/lib/python3.9/site-packages/sklearnex/dispatcher.py", line 177, in patch_sklearn
> patch_sklearn_orig(algorithm, verbose=False, deprecation=False,
> File "/usr/local/lib/python3.9/site-packages/daal4py/sklearn/monkeypatch/dispatcher.py", line 127, in enable
> do_patch(name, get_map)
> File "/usr/local/lib/python3.9/site-packages/daal4py/sklearn/monkeypatch/dispatcher.py", line 111, in do_patch
> raise ValueError("Has no patch for: " + name)
> ValueError: Has no patch for: LinearRegression
我的代码有什么问题?该文档支持线性回归,并且我按照示例中的方式操作。
当我只对 PCA
进行补丁时,算法正常工作。我正在使用这个包的最新版本。如果我不导入 sklearnex,原始的 sklearn 正常工作。
英文:
I'm trying to use sklearnex/scikit-learn-intelex for GPU accelaration. This is my code, learnt from 'Patching several algorithms:':
try:
from sklearnex import patch_sklearn
patch_sklearn()
except:
pass
patch_sklearn(['PCA','LinearRegression'])
Apparently the package suppports linear regression. However, it returns the following error on my machine:
> Intel(R) Extension for Scikit-learn* enabled (https://github.com/intel/scikit-learn-intelex)
> Traceback (most recent call last):
> File "/home/path/tmp_test.py", line 16, in <module>
> patch_sklearn(['PCA','LinearRegression'])
> File "/usr/local/lib/python3.9/site-packages/sklearnex/dispatcher.py", line 177, in patch_sklearn
> patch_sklearn_orig(algorithm, verbose=False, deprecation=False,
> File "/usr/local/lib/python3.9/site-packages/daal4py/sklearn/monkeypatch/dispatcher.py", line 127, in enable
> do_patch(name, get_map)
> File "/usr/local/lib/python3.9/site-packages/daal4py/sklearn/monkeypatch/dispatcher.py", line 111, in do_patch
> raise ValueError("Has no patch for: " + name)
> ValueError: Has no patch for: LinearRegression
What's wrong with my code? The package supports linear regression and I did exactly the way in the example
When I patch PCA
only, the algo works normaly. I'm using the latest version of this package.. The original sklearn works fine if I don't import sklearnex.
答案1
得分: 0
修复代码本身 - 这会起作用,但这不是清晰的命名,需要修复 - https://github.com/intel/scikit-learn-intelex/pull/1343
patch_sklearn(['PCA', 'Linear'])
patch_sklearn() 仅会影响您的 CPU 代码 - 即常规的 scikit 代码。
在 GPU 的情况下,scikit-learn 本身没有 GPU 支持的概念。
要在 GPU 上运行(注意:仅支持英特尔 GPU ),您需要使用 config_context 进行显式定义,或将 GPU 数据(dpctl 张量)传递给算法
https://intel.github.io/scikit-learn-intelex/oneapi-gpu.html
英文:
Fix for code itself - this would work, but this is not clear naming that would be fixed - https://github.com/intel/scikit-learn-intelex/pull/1343
patch_sklearn(['PCA','Linear'])
patch_sklearn() would affect only your CPU code - i.e. regular scikit code.
In case of GPU there is no notion of GPU support in scikit-learn itself.
To run on GPU (note: only Intel GPUs support ) you ether have to use explicit definition with config_context or pass GPU data(dpctl tensor) to algorithm
https://intel.github.io/scikit-learn-intelex/oneapi-gpu.html
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论