index.rst 6.27 KB
Newer Older
1
2
Install and Setup
=================
Minjie Wang's avatar
Minjie Wang committed
3

Gan Quan's avatar
Gan Quan committed
4
5
System requirements
-------------------
6
DGL works with the following operating systems:
Gan Quan's avatar
Gan Quan committed
7

8
9
10
* Ubuntu 20.04+
* CentOS 8+
* RHEL 8+
Gan Quan's avatar
Gan Quan committed
11
* macOS X
12
* Windows 10
Gan Quan's avatar
Gan Quan committed
13

14
DGL requires Python version 3.7, 3.8, 3.9, 3.10, 3.11.
Gan Quan's avatar
Gan Quan committed
15

16
DGL supports multiple tensor libraries as backends, e.g., PyTorch, MXNet. For requirements on backends and how to select one, see :ref:`backends`.
Gan Quan's avatar
Gan Quan committed
17

18
19
20
Starting at version 0.3, DGL is separated into CPU and CUDA builds.  The builds share the
same Python package name. If you install DGL with a CUDA 9 build after you install the
CPU build, then the CPU build is overwritten.
21

Minjie Wang's avatar
Minjie Wang committed
22
23
Install from Conda or Pip
-------------------------
24

25
26
We recommend installing DGL by ``conda`` or ``pip``.
Check out the instructions on the `Get Started page <https://www.dgl.ai/pages/start.html>`_.
Gan Quan's avatar
Gan Quan committed
27

28
29
30
31
.. note::

   For Windows users: you will need to install `Visual C++ 2015 Redistributable <https://www.microsoft.com/en-us/download/details.aspx?id=48145>`_.

32
33
.. _install-from-source:

Gan Quan's avatar
Gan Quan committed
34
35
Install from source
-------------------
36
Download the source files from GitHub.
Gan Quan's avatar
Gan Quan committed
37
38

.. code:: bash
Minjie Wang's avatar
Minjie Wang committed
39

40
   git clone --recurse-submodules https://github.com/dmlc/dgl.git
Minjie Wang's avatar
Minjie Wang committed
41

42
(Optional) Clone the repository first, and then run the following:
Minjie Wang's avatar
Minjie Wang committed
43
44
45

.. code:: bash

46
   git submodule update --init --recursive
Gan Quan's avatar
Gan Quan committed
47
48
49

Linux
`````
Minjie Wang's avatar
Minjie Wang committed
50

51
Install the system packages for building the shared library. For Debian and Ubuntu
Gan Quan's avatar
Gan Quan committed
52
users, run:
Minjie Wang's avatar
Minjie Wang committed
53
54
55

.. code:: bash

Gan Quan's avatar
Gan Quan committed
56
   sudo apt-get update
Da Zheng's avatar
Da Zheng committed
57
   sudo apt-get install -y build-essential python3-dev make cmake
Minjie Wang's avatar
Minjie Wang committed
58

Gan Quan's avatar
Gan Quan committed
59
For Fedora/RHEL/CentOS users, run:
Minjie Wang's avatar
Minjie Wang committed
60

Gan Quan's avatar
Gan Quan committed
61
62
63
.. code:: bash

   sudo yum install -y gcc-c++ python3-devel make cmake
Minjie Wang's avatar
Minjie Wang committed
64

65
66
67
68
69
70
71
72
73
74
75
76
77
78
To create a Conda environment for CPU development, run:

.. code:: bash

   bash script/create_dev_conda_env.sh -c

To create a Conda environment for GPU development, run:

.. code:: bash

   bash script/create_dev_conda_env.sh -g 11.7


To further configure the conda environment, run the following command for more details:
79

80
81
82
.. code:: bash

   bash script/create_dev_conda_env.sh -h
83

84
85
86
87
88
89
90
91
92
93
94
95
96
To build the shared library for CPU development, run:

.. code:: bash

   bash script/build_dgl.sh -c

To build the shared library for GPU development, run:

.. code:: bash

   bash script/build_dgl.sh -g

To further build the shared library, run the following command for more details:
97

98
.. code:: bash
99

100
   bash script/build_dgl.sh -h
101
102

Finally, install the Python binding.
Minjie Wang's avatar
Minjie Wang committed
103
104
105

.. code:: bash

106
   cd python
Gan Quan's avatar
Gan Quan committed
107
   python setup.py install
108
   # Build Cython extension
109
   python setup.py build_ext --inplace
Gan Quan's avatar
Gan Quan committed
110
111
112
113

macOS
`````

114
Installation on macOS is similar to Linux. But macOS users need to install build tools like clang, GNU Make, and cmake first. These installation steps were tested on macOS X with clang 10.0.0, GNU Make 3.81, and cmake 3.13.1.
Minjie Wang's avatar
Minjie Wang committed
115

Gan Quan's avatar
Gan Quan committed
116
Tools like clang and GNU Make are packaged in **Command Line Tools** for macOS. To
117
install, run the following:
Minjie Wang's avatar
Minjie Wang committed
118
119
120

.. code:: bash

Gan Quan's avatar
Gan Quan committed
121
   xcode-select --install
Minjie Wang's avatar
Minjie Wang committed
122

Gan Quan's avatar
Gan Quan committed
123
To install other needed packages like cmake, we recommend first installing
124
**Homebrew**, which is a popular package manager for macOS. To learn more, see the `Homebrew website <https://brew.sh/>`_.
Gan Quan's avatar
Gan Quan committed
125

126
After you install Homebrew, install cmake.
Minjie Wang's avatar
Minjie Wang committed
127
128
129

.. code:: bash

Gan Quan's avatar
Gan Quan committed
130
   brew install cmake
Minjie Wang's avatar
Minjie Wang committed
131

132
133
Go to root directory of the DGL repository, build a shared library, and
install the Python binding for DGL.
Gan Quan's avatar
Gan Quan committed
134
135

.. code:: bash
Minjie Wang's avatar
Minjie Wang committed
136

Gan Quan's avatar
Gan Quan committed
137
138
   mkdir build
   cd build
139
   cmake -DUSE_OPENMP=off -DUSE_LIBXSMM=OFF ..
Gan Quan's avatar
Gan Quan committed
140
141
142
   make -j4
   cd ../python
   python setup.py install
143
   # Build Cython extension
144
   python setup.py build_ext --inplace
Minjie Wang's avatar
Minjie Wang committed
145

Gan Quan's avatar
Gan Quan committed
146
147
Windows
```````
Minjie Wang's avatar
Minjie Wang committed
148

149
150
151
You can build DGL with MSBuild.  With `MS Build Tools <https://go.microsoft.com/fwlink/?linkid=840931>`_
and `CMake on Windows <https://cmake.org/download/>`_ installed, run the following
in VS2019 x64 Native tools command prompt.
Gan Quan's avatar
Gan Quan committed
152

153
* CPU only build::
Gan Quan's avatar
Gan Quan committed
154

155
156
157
158
159
160
     MD build
     CD build
     cmake -DCMAKE_CXX_FLAGS="/DDGL_EXPORTS" -DCMAKE_CONFIGURATION_TYPES="Release" -DDMLC_FORCE_SHARED_CRT=ON .. -G "Visual Studio 16 2019"
     msbuild dgl.sln /m
     CD ..\python
     python setup.py install
161
162

* CUDA build::
Quan (Andy) Gan's avatar
Quan (Andy) Gan committed
163

164
165
166
167
168
169
     MD build
     CD build
     cmake -DCMAKE_CXX_FLAGS="/DDGL_EXPORTS" -DCMAKE_CONFIGURATION_TYPES="Release" -DDMLC_FORCE_SHARED_CRT=ON -DUSE_CUDA=ON .. -G "Visual Studio 16 2019"
     msbuild dgl.sln /m
     CD ..\python
     python setup.py install
Quan (Andy) Gan's avatar
Quan (Andy) Gan committed
170

171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194

.. _backends:

Working with different backends
-------------------------------

DGL supports PyTorch, MXNet and Tensorflow backends. 
DGL will choose the backend on the following options (high priority to low priority)

* Use the ``DGLBACKEND`` environment variable:

   - You can use ``DGLBACKEND=[BACKEND] python gcn.py ...`` to specify the backend
   - Or ``export DGLBACKEND=[BACKEND]`` to set the global environment variable 

* Modify the ``config.json`` file under "~/.dgl":

   - You can use ``python -m dgl.backend.set_default_backend [BACKEND]`` to set the default backend

Currently BACKEND can be chosen from mxnet, pytorch, tensorflow.

PyTorch backend
```````````````

Export ``DGLBACKEND`` as ``pytorch`` to specify PyTorch backend. The required PyTorch
Quan (Andy) Gan's avatar
Quan (Andy) Gan committed
195
version is 1.12.0 or later. See `pytorch.org <https://pytorch.org>`_ for installation instructions.
196
197
198
199
200

MXNet backend
`````````````

Export ``DGLBACKEND`` as ``mxnet`` to specify MXNet backend. The required MXNet version is
201
1.6 or later. See `mxnet.apache.org <https://mxnet.apache.org/get_started>`_ for installation
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
instructions.

MXNet uses uint32 as the default data type for integer tensors, which only supports graph of
size smaller than 2^32. To enable large graph training, *build* MXNet with ``USE_INT64_TENSOR_SIZE=1``
flag. See `this FAQ <https://mxnet.apache.org/api/faq/large_tensor_support>`_ for more information.

MXNet 1.5 and later has an option to enable Numpy shape mode for ``NDArray`` objects, some DGL models
need this mode to be enabled to run correctly. However, this mode may not compatible with pretrained
model parameters with this mode disabled, e.g. pretrained models from GluonCV and GluonNLP.
By setting ``DGL_MXNET_SET_NP_SHAPE``, users can switch this mode on or off.

Tensorflow backend
``````````````````

Export ``DGLBACKEND`` as ``tensorflow`` to specify Tensorflow backend. The required Tensorflow
217
version is 2.3.0 or later. See `tensorflow.org <https://www.tensorflow.org/install>`_ for installation
218
219
instructions. In addition, DGL will set ``TF_FORCE_GPU_ALLOW_GROWTH`` to ``true`` to prevent Tensorflow take over the whole GPU memory: