Skip to content

Commit 74804ba

Browse files
clarify details on gpu support, remove references to dpctl arrays
1 parent 3d86aeb commit 74804ba

File tree

8 files changed

+282
-163
lines changed

8 files changed

+282
-163
lines changed

doc/sources/array_api.rst

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@ Overview
2323

2424
Many estimators from the |sklearnex| support passing data classes that conform to the
2525
`Array API <https://data-apis.org/array-api/>`_ specification as inputs to methods like ``.fit()``
26-
and ``.predict()``, such as :external+dpnp:doc:`dpnp.ndarray <reference/ndarray>` or
27-
`torch.tensor <https://docs.pytorch.org/docs/stable/tensors.html>`__. This is particularly
28-
useful for GPU computations, as it allows performing operations on inputs that are already
26+
and ``.predict()``, such as |dpnp_array| or `torch.tensor <https://docs.pytorch.org/docs/stable/tensors.html>`__.
27+
This is particularly useful for GPU computations, as it allows performing operations on inputs that are already
2928
on GPU without moving the data from host to device.
3029

3130
.. important::
@@ -80,6 +79,7 @@ in many cases they are.
8079
classes that have :external+dpctl:doc:`USM data <api_reference/dpctl/memory>`. In order to ensure that computations
8180
happen on the intended device under array API, make sure that the data is already on the desired device.
8281

82+
.. _array_api_estimators:
8383

8484
Supported classes
8585
=================
@@ -98,11 +98,10 @@ The following patched classes have support for array API inputs:
9898
- :obj:`sklearnex.linear_model.IncrementalRidge`
9999

100100
.. note::
101-
While full array API support is currently not implemented for all classes, :external+dpnp:doc:`dpnp.ndarray <reference/ndarray>`
102-
and :external+dpctl:doc:`dpctl.tensor <api_reference/dpctl/tensor>` inputs are supported by all the classes
103-
that have :ref:`GPU support <oneapi_gpu>`. Note however that if array API support is not enabled in |sklearn|,
104-
when passing these classes as inputs, data will be transferred to host and then back to device instead of being
105-
used directly.
101+
While full array API support is currently not implemented for all classes, |dpnp_array| inputs are supported
102+
by all the classes that have :ref:`GPU support <oneapi_gpu>`. Note however that if array API support is not
103+
enabled in |sklearn|, when passing these classes as inputs, data will be transferred to host and then back to
104+
device instead of being used directly.
106105

107106

108107
Example usage

doc/sources/config-contexts.rst

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
.. Copyright contributors to the oneDAL project
2+
..
3+
.. Licensed under the Apache License, Version 2.0 (the "License");
4+
.. you may not use this file except in compliance with the License.
5+
.. You may obtain a copy of the License at
6+
..
7+
.. http://www.apache.org/licenses/LICENSE-2.0
8+
..
9+
.. Unless required by applicable law or agreed to in writing, software
10+
.. distributed under the License is distributed on an "AS IS" BASIS,
11+
.. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
.. See the License for the specific language governing permissions and
13+
.. limitations under the License.
14+
.. include:: substitutions.rst
15+
.. _config_contexts:
16+
17+
=========================================
18+
Configuration Contexts and Global Options
19+
=========================================
20+
21+
Overview
22+
========
23+
24+
Just like |sklearn|, the |sklearnex| offers configurable options which can be managed
25+
locally through a configuration context, or globally through process-wide settings,
26+
by extending the configuration-related functions from |sklearn| (see :obj:`sklearn.config_context`
27+
for details).
28+
29+
Configurations in the |sklearnex| are particularly useful for :ref:`GPU functionalities <oneapi_gpu>`
30+
and :ref:`SMPD mode <distributed>`, and are necessary to modify for enabling :ref:`array API <array_api>`.
31+
32+
Configuration context and global options manager for the |sklearnex| can either be imported directly
33+
from the module ``sklearnex``, or can be imported from the ``sklearn`` module after applying patching.
34+
35+
Note that options in the |sklearnex| are a superset of options from |sklearn|, and options passed to
36+
the configuration contexts and global settings of the |sklearnex| will also affect |sklearn| if the
37+
option is supported by it - meaning: the same context manager or global option setter is used for
38+
both libraries.
39+
40+
Example usage
41+
=============
42+
43+
Example using the ``target_offload`` option to make computations run on a GPU:
44+
45+
With a local context
46+
--------------------
47+
48+
Here, only the operations from |sklearn| and from the |sklearnex| that happen within the 'with'
49+
block will be affected by the options:
50+
51+
.. code:: python
52+
53+
import numpy as np
54+
from sklearnex import config_context
55+
from sklearnex.cluster import DBSCAN
56+
57+
X = np.array([[1., 2.], [2., 2.], [2., 3.],
58+
[8., 7.], [8., 8.], [25., 80.]], dtype=np.float32)
59+
with config_context(target_offload="gpu"):
60+
clustering = DBSCAN(eps=3, min_samples=2).fit(X)
61+
62+
As a global option
63+
------------------
64+
65+
Here, all computations from |sklearn| and from the |sklearnex| that happen after the option
66+
is modified are affected:
67+
68+
.. code:: python
69+
70+
import numpy as np
71+
from sklearnex import set_config
72+
from sklearnex.cluster import DBSCAN
73+
74+
X = np.array([[1., 2.], [2., 2.], [2., 3.],
75+
[8., 7.], [8., 8.], [25., 80.]], dtype=np.float32)
76+
77+
set_config(target_offload="gpu") # set it globally
78+
clustering = DBSCAN(eps=3, min_samples=2).fit(X)
79+
set_config(target_offload="auto") # restore it back
80+
81+
API Reference
82+
=============
83+
84+
Note that all of the options accepted by these functions in |sklearn| are also accepted
85+
here - these just list the additional options offered by the |sklearnex|.
86+
87+
.. autofunction:: sklearnex.config_context
88+
89+
.. autofunction:: sklearnex.get_config
90+
91+
.. autofunction:: sklearnex.set_config

doc/sources/distributed-mode.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ data on device without this may lead to a runtime error): ::
8585
export I_MPI_OFFLOAD=1
8686

8787
SMPD-aware versions of estimators can be imported from the ``sklearnex.spmd`` module. Data should be distributed across multiple nodes as
88-
desired, and should be transferred to a |dpctl| or `dpnp <https://github.com/IntelPython/dpnp>`__ array before being passed to the estimator.
88+
desired, and should be transferred to a |dpnp_array| before being passed to the estimator.
8989

9090
Note that SPMD estimators allow an additional argument ``queue`` in their ``.fit`` / ``.predict`` methods, which accept :obj:`dpctl.SyclQueue` objects. For example, while the signature for :obj:`sklearn.linear_model.LinearRegression.predict` would be
9191

doc/sources/index.rst

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,16 @@ These performance charts use benchmarks that you can find in the `scikit-learn b
4141

4242

4343
Supported Algorithms
44-
---------------------
44+
--------------------
4545

4646
See all of the :ref:`sklearn_algorithms`.
4747

4848

4949
Optimizations
50-
----------------------------------
50+
-------------
5151

5252
Enable CPU Optimizations
53-
*********************************
53+
************************
5454

5555
.. tabs::
5656
.. tab:: By patching
@@ -78,7 +78,7 @@ Enable CPU Optimizations
7878
7979
8080
Enable GPU optimizations
81-
*********************************
81+
************************
8282

8383
Note: executing on GPU has `additional system software requirements <https://www.intel.com/content/www/us/en/developer/articles/system-requirements/intel-oneapi-dpcpp-system-requirements.html>`__ - see :doc:`oneapi-gpu`.
8484

@@ -168,14 +168,15 @@ See :ref:`oneapi_gpu` for other ways of executing on GPU.
168168

169169
algorithms.rst
170170
oneapi-gpu.rst
171+
config-contexts.rst
172+
array_api.rst
171173
distributed-mode.rst
172174
distributed_daal4py.rst
173175
non-scikit-algorithms.rst
174176
non_sklearn_d4p.rst
175177
model_builders.rst
176178
logistic_model_builder.rst
177179
input-types.rst
178-
array_api.rst
179180
verbose.rst
180181
preview.rst
181182
deprecation.rst

doc/sources/input-types.rst

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,7 @@ and work with different classes of input data, including:
2929
- SciPy :external+scipy:doc:`sparse arrays and sparse matrices <tutorial/sparse>` (depending on the estimator).
3030
- Pandas :external+pandas:doc:`DataFrame and Series <user_guide/dsintro>` classes.
3131

32-
In addition, |sklearnex| also supports:
33-
34-
- :external+dpnp:doc:`dpnp.ndarray <reference/ndarray>`.
35-
- :external+dpctl:doc:`dpctl.tensor <api_reference/dpctl/tensor>`.
32+
In addition, |sklearnex| also supports |dpnp_array| arrays, which are particularly useful for GPU computations.
3633

3734
Stock Scikit-Learn estimators, depending on the version, might offer support for additional
3835
input types beyond this list, such as ``DataFrame`` and ``Series`` classes from other libraries
@@ -50,8 +47,9 @@ enabled the input is unsupported).
5047
The affected cases are listed below.
5148

5249
- Non-contiguous NumPy array - i.e. where strides are wider than one element across both rows and columns
53-
- For SciPy CSR matrix / array, index arrays are always copied.
50+
- For SciPy CSR matrix / array, index arrays are always copied. Note that sparse matrices in formats other than CSR
51+
will be converted to CSR, which implies more than just data copying.
5452
- Heterogeneous NumPy array
55-
- If SYCL queue is provided for device without ``float64`` support but data are ``float64``, data are copied with reduced precision.
53+
- If SyCL queue is provided for device without ``float64`` support but data are ``float64``, data are copied with reduced precision.
5654
- If :ref:`Array API <array_api>` is not enabled then data from GPU devices are always copied to the host device and then result table
5755
(for applicable methods) is copied to the source device.

0 commit comments

Comments
 (0)