Scikit-learn 会利用 GPU 吗?

阅读 TensorFlow 中 scikit-learn 的实现: http://learningtensorflow.com/lesson6/和 scikit-learn: http://scikit-learn.org/stable/modules/generated/sklearn.cluster.KMeans.html我正在努力决定使用哪种实现。

Scikit-learn 是作为 tensorflow Docker 容器的一部分安装的,因此可以使用任何一种实现。

使用 scikit-learn 的理由:

Scikit-learn 包含的样板比张量流更少 实施。

使用张量流的理由:

如果在 Nvidia 图形处理器上运行该算法将并行运行 ,我不确定 scikit-learn 是否会利用所有可用的 GPU?

读取 https://www.quora.com/What-are-the-main-differences-between-TensorFlow-and-SciKit-Learn

TensorFlow 更低级; 基本上,乐高积木有所帮助 你实现机器学习算法,而 scikit-learn 提供现成的算法,例如 分类,例如支持向量机、随机森林、 Logit模型和 如果你想实现的话,TensorFlow 会发光 深度学习算法,因为它允许你利用 用于更有效培训的图形处理器。

这个声明强化了我的断言“ scikit-learn 包含比 tensorflow 实现更少的样板”,但也暗示 scikit-learn 将不会利用所有可用的 GPU?

146505 次浏览

Tensorflow only uses GPU if it is built against Cuda and CuDNN. By default it does not use GPU, especially if it is running inside Docker, unless you use nvidia-docker and an image with a built-in support.

Scikit-learn is not intended to be used as a deep-learning framework and it does not provide any GPU support.

Why is there no support for deep or reinforcement learning / Will there be support for deep or reinforcement learning in scikit-learn?

Deep learning and reinforcement learning both require a rich vocabulary to define an architecture, with deep learning additionally requiring GPUs for efficient computing. However, neither of these fit within the design constraints of scikit-learn; as a result, deep learning and reinforcement learning are currently out of scope for what scikit-learn seeks to achieve.

Extracted from http://scikit-learn.org/stable/faq.html#why-is-there-no-support-for-deep-or-reinforcement-learning-will-there-be-support-for-deep-or-reinforcement-learning-in-scikit-learn

Will you add GPU support in scikit-learn?

No, or at least not in the near future. The main reason is that GPU support will introduce many software dependencies and introduce platform specific issues. scikit-learn is designed to be easy to install on a wide variety of platforms. Outside of neural networks, GPUs don’t play a large role in machine learning today, and much larger gains in speed can often be achieved by a careful choice of algorithms.

Extracted from http://scikit-learn.org/stable/faq.html#will-you-add-gpu-support

I'm experimenting with a drop-in solution (h2o4gpu) to take advantage of GPU acceleration in particular for Kmeans:

try this:

from h2o4gpu.solvers import KMeans
#from sklearn.cluster import KMeans

as of now, version 0.3.2 still don't have .inertia_ but I think it's in their TODO list.

EDIT: Haven't tested yet, but scikit-cuda seems to be getting traction.

EDIT: RAPIDS is really the way to go here.

From my experience, I use this package to utilize GPU for some sklearn algorithms in here.

The code I use:

import numpy as np
import dpctl
from sklearnex import patch_sklearn, config_context
patch_sklearn()


from sklearn.cluster import DBSCAN


X = np.array([[1., 2.], [2., 2.], [2., 3.],
[8., 7.], [8., 8.], [25., 80.]], dtype=np.float32)
with config_context(target_offload="gpu:0"):
clustering = DBSCAN(eps=3, min_samples=2).fit(X)


Source: oneAPI and GPU support in Intel(R) Extension for Scikit-learn