|
12 | 12 | .. See the License for the specific language governing permissions and |
13 | 13 | .. limitations under the License. |
14 | 14 |
|
| 15 | +.. include:: substitutions.rst |
| 16 | + |
15 | 17 | .. _distributed: |
16 | 18 |
|
17 | | -Distributed Mode |
18 | | -================ |
| 19 | +Distributed Mode (SPMD) |
| 20 | +======================= |
19 | 21 |
|
20 | 22 | |intelex| offers Single Program, Multiple Data (SPMD) supported interfaces for distributed computing. |
21 | | -Several `GPU-supported algorithms <https://uxlfoundation.github.io/scikit-learn-intelex/latest/oneapi-gpu.html#>`_ |
22 | | -also provide distributed, multi-GPU computing capabilities via integration with ``mpi4py``. The prerequisites |
| 23 | +Several :doc:`GPU-supported algorithms <oneapi-gpu>` |
| 24 | +also provide distributed, multi-GPU computing capabilities via integration with |mpi4py|. The prerequisites |
23 | 25 | match those of GPU computing, along with an MPI backend of your choice (`Intel MPI recommended |
24 | 26 | <https://www.intel.com/content/www/us/en/developer/tools/oneapi/mpi-library.html#gs.dcan6r>`_, available |
25 | | -via ``impi-devel`` python package) and the ``mpi4py`` python package. If using |intelex| |
| 27 | +via ``impi_rt`` python package) and the |mpi4py| python package. If using |intelex| |
26 | 28 | `installed from sources <https://github.com/uxlfoundation/scikit-learn-intelex/blob/main/INSTALL.md#build-from-sources>`_, |
27 | 29 | ensure that the spmd_backend is built. |
28 | 30 |
|
29 | | -Note that |intelex| now supports GPU offloading to speed up MPI operations. This is supported automatically with |
30 | | -some MPI backends, but in order to use GPU offloading with Intel MPI, set the following environment variable (providing |
| 31 | +.. important:: |
| 32 | + SMPD mode requires the |mpi4py| package used at runtime to be compiled with the same MPI backend as the |intelex|. The PyPI and Conda distributions of |intelex| both use Intel's MPI as backend, and hence require an |mpi4py| also built with Intel's MPI - it can be easily installed from Intel's conda channel as follows:: |
| 33 | + |
| 34 | + conda install -c https://software.repos.intel.com/python/conda/ mpi4py |
| 35 | + |
| 36 | + It also requires the MPI runtime executable (``mpiexec`` / ``mpirun``) to be from the same library that was used to compile the |intelex| - Intel's MPI runtime library is offered as a Python package ``impi_rt`` and will be installed together with the ``mpi4py`` package if executing the command above, but otherwise, it can be installed separately from different distribution channels: |
| 37 | + |
| 38 | + - Intel's conda channel (recommended):: |
| 39 | + |
| 40 | + conda install -c https://software.repos.intel.com/python/conda/ impi_rt |
| 41 | + |
| 42 | + - Conda-Forge:: |
| 43 | + |
| 44 | + conda install -c conda-forge impi_rt |
| 45 | + |
| 46 | + - PyPI (not recommended, might require setting additional environment variables):: |
| 47 | + |
| 48 | + pip install impi_rt |
| 49 | + |
| 50 | + Using other MPI backends (e.g. OpenMPI) requires building |intelex| from source with that backend. |
| 51 | + |
| 52 | +Note that |intelex| supports GPU offloading to speed up MPI operations. This is supported automatically with |
| 53 | +some MPI backends, but in order to use GPU offloading with Intel MPI, it is required to set the environment variable ``I_MPI_OFFLOAD`` to ``1`` (providing |
31 | 54 | data on device without this may lead to a runtime error): |
32 | 55 |
|
33 | | -:: |
| 56 | +- On Linux*:: |
| 57 | + |
| 58 | + export I_MPI_OFFLOAD=1 |
| 59 | + |
| 60 | +- On Windows*:: |
| 61 | + |
| 62 | + set I_MPI_OFFLOAD=1 |
| 63 | + |
| 64 | +SMPD-aware versions of estimators can be imported from the ``sklearnex.spmd`` module. Data should be distributed across multiple nodes as |
| 65 | +desired, and should be transfered to a |dpctl| or `dpnp <https://github.com/IntelPython/dpnp>`__ array before being passed to the estimator. |
| 66 | + |
| 67 | +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 |
| 68 | + |
| 69 | +.. code-block:: python |
| 70 | +
|
| 71 | + def predict(self, X): ... |
| 72 | +
|
| 73 | +The signature for the corresponding predict method in ``sklearnex.spmd.linear_model.LinearRegression.predict`` is: |
| 74 | + |
| 75 | +.. code-block:: python |
| 76 | +
|
| 77 | + def predict(self, X, queue=None): ... |
| 78 | +
|
| 79 | +Examples of SPMD usage can be found in the GitHub repository for the |intelex| under `examples/sklearnex <https://github.com/uxlfoundation/scikit-learn-intelex/blob/main/examples/sklearnex>`__. |
34 | 80 |
|
35 | | - export I_MPI_OFFLOAD=1 |
| 81 | +To run on SPMD mode, first create a python file using SPMD estimators from ``sklearnex.spmd``, such as `linear_regression_spmd.py <https://github.com/uxlfoundation/scikit-learn-intelex/blob/main/examples/sklearnex/linear_regression_spmd.py>`__. |
36 | 82 |
|
37 | | -Estimators can be imported from the ``sklearnex.spmd`` module. Data should be distributed across multiple nodes as |
38 | | -desired, and should be transfered to a dpctl or dpnp array before being passed to the estimator. View a full |
39 | | -example of this process in the |intelex| repository, where many examples of our SPMD-supported estimators are |
40 | | -available: https://github.com/uxlfoundation/scikit-learn-intelex/blob/main/examples/sklearnex/. To run: |
| 83 | +Then, execute the file through MPI under multiple ranks - for example: |
41 | 84 |
|
42 | | -:: |
| 85 | +- On Linux*:: |
| 86 | + |
| 87 | + mpirun -n 4 python linear_regression_spmd.py |
43 | 88 |
|
44 | | - mpirun -n 4 python linear_regression_spmd.py |
| 89 | +- On Windows*:: |
| 90 | + |
| 91 | + mpiexec -n 4 python linear_regression_spmd.py |
45 | 92 |
|
46 | | -Note that additional mpirun arguments can be added as desired. SPMD-supported estimators are listed in the |
47 | | -`algorithms support documentation <https://uxlfoundation.github.io/scikit-learn-intelex/latest/algorithms.html#spmd-support>`_. |
| 93 | +Note that additional ``mpirun`` arguments can be added as desired. SPMD-supported estimators are listed in the :ref:`spmd-support` section. |
48 | 94 |
|
49 | | -Additionally, daal4py offers some distributed functionality, see |
| 95 | +Additionally, ``daal4py`` (previously a separate package, now an importable module within ``scikit-learn-intelex``) offers some distributed functionality, see |
50 | 96 | `documentation <https://intelpython.github.io/daal4py/scaling.html>`_ for further details. |
0 commit comments