# Deep Graph Library (DGL) [![Build Status](http://ci.dgl.ai:80/buildStatus/icon?job=DGL/master)](http://ci.dgl.ai:80/job/DGL/job/master/) [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](./LICENSE) | [Documentation](https://docs.dgl.ai) | [DGL at a glance](https://docs.dgl.ai/tutorials/basics/1_first.html#sphx-glr-tutorials-basics-1-first-py) | [Model Tutorials](https://docs.dgl.ai/tutorials/models/index.html) | [Discussion Forum](https://discuss.dgl.ai) DGL is an easy-to-use and high performance Python package for deep learning on graphs, e.g. social networks, knowledge graphs, molecules, and biological networks. DGL makes implementing graph neural networks(GNN), e.g. including Graph Convolutional Networks, TreeLSTM, and many others, as easy as a few lines of codes. Below is *everything* to implement a single layer for Graph Convolutional Network with DGL and PyTorch: ```python import dgl.function as fn import torch.nn as nn import torch.nn.functional as F from dgl import DGLGraph msg_func = fn.copy_src(src='h', out='m') reduce_func = fn.sum(msg='m', out='h') class GCNLayer(nn.Module): def __init__(self, in_feats, out_feats): super(GCNLayer, self).__init__() self.linear = nn.Linear(in_feats, out_feats) def apply(self, nodes): return {'h': F.relu(self.linear(nodes.data['h']))} def forward(self, g, feature): g.ndata['h'] = feature g.update_all(msg_func, reduce_func) g.apply_nodes(func=self.apply) return g.ndata.pop('h') ``` Users can also use pre-implemented and ready-to-use GCN modules of DGL. The same function above can be implemented with just one line of code: ``` model = dgl.nn.pytorch.conv.GraphConv(in_feats, out_feats, activation=torch.nn.function.relu) ``` DGL has implemented a set of higher level APIs, which will save tons of efforts for researchers and users. The full list of APIs can be found at [DGL API reference](https://docs.dgl.ai/api/python/graph.html). ## Performance Comparison DGL has outperformed existing graph deep learning libraries, e.g. PyG(PyTorch Geometric), in terms of runtime and memory consumption. Below list a few results of comparison. ![](https://i.imgur.com/UehMpur.png) | ![](https://i.imgur.com/CvXc9Uu.png) | ![](https://i.imgur.com/HnCfJyU.png) | | -------- | -------- | Detailed performance comparison of DGL and other Graph alternatives can be found [here](https://arxiv.org/abs/1909.01315). ## Model Zoos: [Chemistry](https://github.com/dmlc/dgl/tree/master/examples/pytorch/model_zoo/chem) | [Citation Networks](https://github.com/dmlc/dgl/tree/master/examples/pytorch/model_zoo/citation_network) A varity of GNN examples were implemented by the DGL team. They can be found [here](https://github.com/dmlc/dgl/tree/master/examples). ### Implemented Models A summary of part of the model accuracy and training speed with the Pytorch backend (on Amazon EC2 p3.2x instance (w/ V100 GPU)), as compared with the best open-source implementations: | Model | Reported <br> Accuracy | DGL <br> Accuracy | Author's training speed (epoch time) | DGL speed (epoch time) | Improvement | | ---------------------------------------------------------------- | ---------------------- | ----------------- | ----------------------------------------------------------------------------- | ---------------------- | ----------- | | [GCN](https://arxiv.org/abs/1609.02907) | 81.5% | 81.0% | [0.0051s (TF)](https://github.com/tkipf/gcn) | 0.0031s | 1.64x | | [GAT](https://arxiv.org/abs/1710.10903) | 83.0% | 83.9% | [0.0982s (TF)](https://github.com/PetarV-/GAT) | 0.0113s | 8.69x | | [SGC](https://arxiv.org/abs/1902.07153) | 81.0% | 81.9% | n/a | 0.0008s | n/a | | [TreeLSTM](http://arxiv.org/abs/1503.00075) | 51.0% | 51.72% | [14.02s (DyNet)](https://github.com/clab/dynet/tree/master/examples/treelstm) | 3.18s | 4.3x | | [R-GCN <br> (classification)](https://arxiv.org/abs/1703.06103) | 73.23% | 73.53% | [0.2853s (Theano)](https://github.com/tkipf/relational-gcn) | 0.0075s | 38.2x | | [R-GCN <br> (link prediction)](https://arxiv.org/abs/1703.06103) | 0.158 | 0.151 | [2.204s (TF)](https://github.com/MichSchli/RelationPrediction) | 0.453s | 4.86x | | [JTNN](https://arxiv.org/abs/1802.04364) | 96.44% | 96.44% | [1826s (Pytorch)](https://github.com/wengong-jin/icml18-jtnn) | 743s | 2.5x | | [LGNN](https://arxiv.org/abs/1705.08415) | 94% | 94% | n/a | 1.45s | n/a | | [DGMG](https://arxiv.org/pdf/1803.03324.pdf) | 84% | 90% | n/a | 238s | n/a | | [GraphWriter](https://www.aclweb.org/anthology/N19-1238.pdf) | 14.3(BLEU) | 14.31(BLEU) | [1970s (PyTorch)](https://github.com/rikdz/GraphWriter) | 1192s | 1.65x | ### Scalability With the MXNet/Gluon backend , we scaled a graph of 50M nodes and 150M edges on a P3.8xlarge instance, with 160s per epoch, on SSE ([Stochastic Steady-state Embedding](https://www.cc.gatech.edu/~hdai8/pdf/equilibrium_embedding.pdf)), a model similar to GCN. ## List of Works using DGL *to be filled* ## News v0.4 has just been released! DGL now support **heterogeneous graphs**, and comeswith a subpackage **DGL-KE** that computes embeddings for large knowledge graphs such as Freebase (1.9 billion triplets). See release note [here](https://github.com/dmlc/dgl/releases/tag/v0.4). Hands-on tutorials: * [WWW 2020](https://www2020.thewebconf.org/program#tutorials), Taipei | [Contents](https://github.com/dglai/WWW20-Hands-on-Tutorial) * [KDD 2019](https://www.kdd.org/kdd2019/hands-on-tutorials), Anchorage | [Contents](https://github.com/dglai/KDD-2019-Hands-on) * [GTC 2019](https://www.nvidia.com/en-us/gtc/), San Jose | [Contents](https://github.com/dglai/DGL-GTC2019) ## Get Started Please refer to [Get Started](https://www.dgl.ai/pages/start.html ) for detailed system requirements, installation guides and build methods. In general DGL should work on Ubuntu 16.04 or later version, macOS X, and Windows 10, with Python 3.5 or later. Right now, DGL works on [PyTorch](https://pytorch.org) 0.4.1+ and [MXNet](https://mxnet.apache.org) nightly build as its backend. ## New to Deep Learning and Graph Deep Learning? Check out the open source book [*Dive into Deep Learning*](http://gluon.ai/). For those who are new to graph nerual network, please see the basic of DGL [DGL basics](https://docs.dgl.ai/tutorials/basics/index.html). For audience who are looking for more advanced, realistic, and end-to-end examples, please see [model tutorials](https://docs.dgl.ai/tutorials/models/index.html). ## Contributing Please let us know if you encounter a bug or have any suggestions by [filing an issue](https://github.com/dmlc/dgl/issues). We are currently in beta stage, so we welcome all contributions from bug fixes to new features and extensions. We expect all contributions discussed in the issue tracker and going through PRs. Please refer to our [contribution guide](https://docs.dgl.ai/contribute.html). ## Cite If you use DGL in a scientific publication, we would appreciate citations to the following paper: ``` @article{wang2019dgl, title={Deep Graph Library: Towards Efficient and Scalable Deep Learning on Graphs}, url={https://arxiv.org/abs/1909.01315}, author={Wang, Minjie and Yu, Lingfan and Zheng, Da and Gan, Quan and Gai, Yu and Ye, Zihao and Li, Mufei and Zhou, Jinjing and Huang, Qi and Ma, Chao and Huang, Ziyue and Guo, Qipeng and Zhang, Hao and Lin, Haibin and Zhao, Junbo and Li, Jinyang and Smola, Alexander J and Zhang, Zheng}, journal={ICLR Workshop on Representation Learning on Graphs and Manifolds}, year={2019} } ``` ## The Team DGL is developed and maintained by [NYU, NYU Shanghai, AWS Shanghai AI Lab, and AWS MXNet Science Team](https://www.dgl.ai/pages/about.html). ## License DGL uses Apache License 2.0.