Install and Setup¶
DGL works with the following operating systems:
DGL requires Python version 3.6, 3.7, 3.8 or 3.9.
DGL supports multiple tensor libraries as backends, e.g., PyTorch, MXNet. For requirements on backends and how to select one, see Working with different backends.
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.
Install from Conda or Pip¶
We recommend installing DGL by
Check out the instructions on the Get Started page.
Install from source¶
Download the source files from GitHub.
git clone --recurse-submodules https://github.com/dmlc/dgl.git
(Optional) Clone the repository first, and then run the following:
git submodule update --init --recursive
Install the system packages for building the shared library. For Debian and Ubuntu users, run:
sudo apt-get update sudo apt-get install -y build-essential python3-dev make cmake
For Fedora/RHEL/CentOS users, run:
sudo yum install -y gcc-c++ python3-devel make cmake
Build the shared library. Use the configuration template
Copy it to either the project directory or the build directory and change the
configuration as you wish. For example, change
enable a CUDA build. You could also pass
-DKEY=VALUE to the cmake command
for the same purpose.
mkdir build cd build cmake .. make -j4
mkdir build cd build cmake -DUSE_CUDA=ON .. make -j4
Finally, install the Python binding.
cd ../python python setup.py install
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.
Tools like clang and GNU Make are packaged in Command Line Tools for macOS. To install, run the following:
To install other needed packages like cmake, we recommend first installing Homebrew, which is a popular package manager for macOS. To learn more, see the Homebrew website.
After you install Homebrew, install cmake.
brew install cmake
Go to root directory of the DGL repository, build a shared library, and install the Python binding for DGL.
mkdir build cd build cmake -DUSE_OPENMP=off -DCMAKE_C_FLAGS='-DXBYAK_DONT_USE_MAP_JIT' -DCMAKE_CXX_FLAGS='-DXBYAK_DONT_USE_MAP_JIT' .. make -j4 cd ../python python setup.py install
CPU only build:
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
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
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)
You can use
DGLBACKEND=[BACKEND] python gcn.py ...to specify the backend
export DGLBACKEND=[BACKEND]to set the global environment variable
config.jsonfile 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 to specify PyTorch backend. The required PyTorch
version is 1.5.0 or later. See pytorch.org for installation instructions.
mxnet to specify MXNet backend. The required MXNet version is
1.5 or later. See mxnet.apache.org for installation
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
flag. See this FAQ 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.
DGL_MXNET_SET_NP_SHAPE, users can switch this mode on or off.
tensorflow to specify Tensorflow backend. The required Tensorflow
version is 2.2.0 or later. See tensorflow.org for installation
instructions. In addition, DGL will set
true to prevent Tensorflow take over the whole GPU memory:
pip install "tensorflow>=2.2.0" # when using tensorflow cpu version