Debian Codegraph @

docs/source/gpu.rst

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 GPUs
2 ====
3
4 Dask works with GPUs in a few ways.
5
6
7 Custom Computations
8 -------------------
9
10 Many people use Dask alongside GPU-accelerated libraries like PyTorch and
11 TensorFlow to manage workloads across several machines. They typically use
12 Dask's custom APIs, notably :doc:`Delayed <delayed>` and :doc:`Futures
13 <futures>`.
14
15 Dask doesn't need to know that these functions use GPUs. It just runs Python
16 functions. Whether or not those Python functions use a GPU is orthogonal to
17 Dask. It will work regardless.
18
19 As a worked example, you may want to view this talk:
20
21 .. raw:: html
22
23 <video width="560" height="315" controls>
24 <source src="https://developer.download.nvidia.com/video/gputechconf/gtc/2019/video/S9198/s9198-dask-and-v100s-for-fast-distributed-batch-scoring-of-computer-vision-workloads.mp4"
25 type="video/mp4">
26 </video>
27
28 High Level Collections
29 ----------------------
30
31 Dask can also help to scale out large array and dataframe computations by
32 combining the Dask Array and DataFrame collections with a GPU-accelerated
33 array or dataframe library.
34
35 Recall that :doc:`Dask Array <array>` creates a large array out of many NumPy
36 arrays and :doc:`Dask DataFrame <dataframe>` creates a large dataframe out of
37 many Pandas dataframes. We can use these same systems with GPUs if we swap out
38 the NumPy/Pandas components with GPU-accelerated versions of those same
39 libraries, as long as the GPU accelerated version looks enough like
40 NumPy/Pandas in order to interoperate with Dask.
41
42 Fortunately, libraries that mimic NumPy, Pandas, and Scikit-Learn on the GPU do
43 exist.
44
45
46 DataFrames
47 ~~~~~~~~~~
48
49 The `RAPIDS <https://rapids.ai>`_ libraries provide a GPU accelerated
50 Pandas-like library,
51 `cuDF <https://github.com/rapidsai/cudf>`_,
52 which interoperates well and is tested against Dask DataFrame.
53
54 If you have cuDF installed then you should be able to convert a Pandas-backed
55 Dask DataFrame to a cuDF-backed Dask DataFrame as follows:
56
57 .. code-block:: python
58
59 import cudf
60
61 df = df.map_partitions(cudf.from_pandas) # convert pandas partitions into cudf partitions
62
63 However, cuDF does not support the entire Pandas interface, and so a variety of
64 Dask DataFrame operations will not function properly. Check the
65 `cuDF API Reference <https://docs.rapids.ai/api/cudf/stable/>`_
66 for currently supported interface.
67
68
69 Arrays
70 ~~~~~~
71
72 .. note:: Dask's integration with CuPy relies on features recently added to
73 NumPy and CuPy, particularly in version ``numpy>=1.17`` and ``cupy>=6``
74
75 `Chainer's CuPy <https://cupy.chainer.org/>`_ library provides a GPU
76 accelerated NumPy-like library that interoperates nicely with Dask Array.
77
78 If you have CuPy installed then you should be able to convert a NumPy-backed
79 Dask Array into a CuPy backed Dask Array as follows:
80
81 .. code-block:: python
82
83 import cupy
84
85 x = x.map_blocks(cupy.asarray)
86
87 CuPy is fairly mature and adheres closely to the NumPy API. However, small
88 differences do exist and these can cause Dask Array operations to function
89 improperly. Check the
90 `CuPy Reference Manual <https://docs-cupy.chainer.org/en/stable/reference/index.html>`_
91 for API compatibility.
92
93
94 Scikit-Learn
95 ~~~~~~~~~~~~
96
97 There are a variety of GPU accelerated machine learning libraries that follow
98 the Scikit-Learn Estimator API of fit, transform, and predict. These can
99 generally be used within `Dask-ML's <https://ml.dask.org>`_ meta estimators,
100 such as `hyper parameter optimization <https://ml.dask.org/hyper-parameter-search.html>`_.
101
102 Some of these include:
103
104 - `Skorch <https://skorch.readthedocs.io/>`_
105 - `cuML <https://rapidsai.github.io/projects/cuml/en/latest/>`_
106 - `LightGBM <https://github.com/Microsoft/LightGBM>`_
107 - `XGBoost <https://xgboost.readthedocs.io/en/latest/>`_
108 - `Thunder SVM <https://github.com/Xtra-Computing/thundersvm>`_
109 - `Thunder GBM <https://github.com/Xtra-Computing/thundergbm>`_
110
111
112 Setup
113 -----
114
115 From the examples above we can see that the user experience of using Dask with
116 GPU-backed libraries isn't very different from using it with CPU-backed
117 libraries. However, there are some changes you might consider making when
118 setting up your cluster.
119
120 Restricting Work
121 ~~~~~~~~~~~~~~~~
122
123 By default Dask allows as many tasks as you have CPU cores to run concurrently.
124 However if your tasks primarily use a GPU then you probably want far fewer
125 tasks running at once. There are a few ways to limit parallelism here:
126
127 - Limit the number of threads explicitly on your workers using the
128 ``--nthreads`` keyword in the CLI or the ``ncores=`` keyword the
129 Cluster constructor.
130 - Use `worker resources <https://distributed.dask.org/en/latest/resources.html>`_ and tag certain
131 tasks as GPU tasks so that the scheduler will limit them, while leaving the
132 rest of your CPU cores for other work
133
134 Specifying GPUs per Machine
135 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
136
137 Some configurations may have many GPU devices per node. Dask is often used to
138 balance and coordinate work between these devices.
139
140 In these situations it is common to start one Dask worker per device, and use
141 the CUDA environment variable ``CUDA_VISIBLE_DEVICES`` to pin each worker to
142 prefer one device.
143
144 .. code-block:: bash
145
146 # If we have four GPUs on one machine
147 CUDA_VISIBLE_DEVICES=0 dask-worker ...
148 CUDA_VISIBLE_DEVICES=1 dask-worker ...
149 CUDA_VISIBLE_DEVICES=2 dask-worker ...
150 CUDA_VISIBLE_DEVICES=3 dask-worker ...
151
152 The `Dask CUDA <https://github.com/rapidsai/dask-cuda>`_ project contains some
153 convenience CLI and Python utilities to automate this process.
154
155 Work in Progress
156 ----------------
157
158 GPU computing is a quickly moving field today and as a result the information
159 in this page is likely to go out of date quickly. We encourage interested
160 readers to check out `Dask's Blog <https://blog.dask.org>`_ which has more
161 timely updates on ongoing work.