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

Add supported CPU/GPU operators to API docs and update docstrings #5239

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
56 changes: 56 additions & 0 deletions docs/source/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,62 @@ Output Data Type Configuration
.. autofunction:: cuml.internals.memory_utils.set_global_output_type
.. autofunction:: cuml.internals.memory_utils.using_output_type

.. _device-selection:

CPU / GPU Device Selection (Experimental)
-----------------------------------------
cuML provides experimental support for running selected estimators and operators on either the GPU or CPU. This document covers the set of operators for which CPU/GPU device selection capabilities are supported as of the current nightly packages. If an operator isn't listed here, it can only be run on the GPU. Prior versions of cuML may have reduced support compared to the following table.

.. list-table:: Operators Supporting CPU/GPU Device Selection and Execution
:header-rows: 1
:align: center
:widths: auto

* - Category
- Operator
* - Clustering
- HDBSCAN
* - Dimensionality Reduction and Manifold Learning
- PCA
* - Dimensionality Reduction and Manifold Learning
- TruncatedSVD
* - Dimensionality Reduction and Manifold Learning
- UMAP
* - Neighbors
- NearestNeighbors
* - Regression and Classification
- ElasticNet
* - Regression and Classification
- Lasso
* - Regression and Classification
- LinearRegression
* - Regression and Classification
- LogisticRegression
* - Regression and Classification
- Ridge

If a CUDA-enabled GPU is available on the system, cuML will default to using it. Users can configure CPU or GPU execution for supported operators via context managers or global configuration.

.. code-block:: python

from cuml.linear_model import Lasso
from cuml.common.device_selection import using_device_type, set_global_device_type

with using_device_type("CPU"): # Alternatively, using_device_type("GPU")
model = Lasso()
model.fit(X_train, y_train)
predictions = model.predict(X_test)

# All operators supporting CPU execution will run on the CPU after this configuration
set_global_device_type("CPU")

model = Lasso()
model.fit(X_train, y_train)
predictions = model.predict(X_test)

For more detailed examples, please see the `Execution Device
Interoperability Notebook<execution_device_interoperability.ipynb>`_in the User Guide.

.. _verbosity-levels:

Verbosity Levels
Expand Down
4 changes: 4 additions & 0 deletions python/cuml/cluster/hdbscan/hdbscan.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,10 @@ class HDBSCAN(UniversalBase, ClusterMixin, CMajorInputTagMixin):
(and often will) lead to some points being assigned different
cluster labels between the two implementations.

This estimator supports cuML's experimental device selection capabilities.
beckernick marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

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

@beckernick I'll comment again just so it's in my "reviewed" list. Feel free to delete your comment after that.

Should we maybe automatically add this comment via a common decorator? Something like @device_interop_enabled ? This would also allow us to (maybe at a later stage) set some flag that helps with testing. This could of course be done in a follow-up to not block this PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks! I agree. Doc utilities for this kind of behavior is a great idea.

Copy link
Member

Choose a reason for hiding this comment

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

It can be added to https://github.com/rapidsai/cuml/blob/branch-23.04/python/cuml/common/doc_utils.py, @beckernick could you open an issue to do it in a follow up? Thanks!

It can be configured to run on either the CPU or the GPU.
To learn more, please see :ref:`device-selection`.

Parameters
----------
handle : cuml.Handle
Expand Down
4 changes: 4 additions & 0 deletions python/cuml/decomposition/pca.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ class PCA(UniversalBase,
as it iteratively tries to correct the top K eigenvectors, but might be
less accurate.

This estimator supports cuML's experimental device selection capabilities.
It can be configured to run on either the CPU or the GPU.
To learn more, please see :ref:`device-selection`.

Examples
--------

Expand Down
4 changes: 4 additions & 0 deletions python/cuml/decomposition/tsvd.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ class TruncatedSVD(UniversalBase,
faster as it iteratively tries to correct the top K singular vectors, but
might be less accurate.

This estimator supports cuML's experimental device selection capabilities.
It can be configured to run on either the CPU or the GPU.
To learn more, please see :ref:`device-selection`.

Examples
--------

Expand Down
4 changes: 4 additions & 0 deletions python/cuml/linear_model/lasso.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ class Lasso(ElasticNet):
compliant), in addition to cuDF objects. It uses coordinate descent to fit
a linear model.

This estimator supports cuML's experimental device selection capabilities.
It can be configured to run on either the CPU or the GPU.
To learn more, please see :ref:`device-selection`.

Examples
--------

Expand Down
4 changes: 4 additions & 0 deletions python/cuml/linear_model/linear_regression.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ class LinearRegression(LinearPredictMixin,
and provides 2 algorithms SVD and Eig to fit a linear model. SVD is more
stable, but Eig (default) is much faster.

This estimator supports cuML's experimental device selection capabilities.
It can be configured to run on either the CPU or the GPU.
To learn more, please see :ref:`device-selection`.

Examples
--------

Expand Down
4 changes: 4 additions & 0 deletions python/cuml/linear_model/logistic_regression.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ class LogisticRegression(UniversalBase,

Note that, just like in Scikit-learn, the bias will not be regularized.

This estimator supports cuML's experimental device selection capabilities.
It can be configured to run on either the CPU or the GPU.
To learn more, please see :ref:`device-selection`.

Examples
--------

Expand Down
4 changes: 4 additions & 0 deletions python/cuml/manifold/umap.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ class UMAP(UniversalBase,
The UMAP algorithm is outlined in [1]. This implementation follows the
GPU-accelerated version as described in [2].

This estimator supports cuML's experimental device selection capabilities.
It can be configured to run on either the CPU or the GPU.
To learn more, please see :ref:`device-selection`.

Parameters
----------
n_neighbors: float (optional, default 15)
Expand Down
4 changes: 4 additions & 0 deletions python/cuml/neighbors/nearest_neighbors.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ class NearestNeighbors(UniversalBase,
datapoints. Currently, cuML supports k-NN queries, which define
the neighborhood as the closest `k` neighbors to each query point.

This estimator supports cuML's experimental device selection capabilities.
It can be configured to run on either the CPU or the GPU.
To learn more, please see :ref:`device-selection`.

Parameters
----------
n_neighbors : int (default=5)
Expand Down