[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)
Model Zoos: [Chemistry](https://github.com/dmlc/dgl/tree/master/examples/pytorch/model_zoo) | [Citation Networks](https://github.com/dmlc/dgl/tree/master/examples/pytorch/model_zoo/citation_network)
DGL is a Python package that interfaces between existing tensor libraries and data being expressed as
graphs.
DGL is an easy-to-use, high performance and scalable Python package for deep learning on graphs. DGL is framework agnostic, meaning if a deep graph model is a component of an end-to-end application, the rest of the logics can be implemented in any major frameworks, such as PyTorch, Apache MXNet or TensorFlow.
It makes implementing graph neural networks (including Graph Convolution Networks, TreeLSTM, and many others) easy while
All model examples can be found [here](https://github.com/dmlc/dgl/tree/master/examples).
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:
**A data scientist** may want to apply a pre-trained model to your data right away. For this you can use DGL's [Application packages, formally *Model Zoo*](https://github.com/dmlc/dgl/tree/master/apps). Application packages are developed for domain applications, as is the case for [DGL-LifeScience](https://github.com/dmlc/dgl/tree/master/apps/life_sci). We will soon add model zoo for knowledge graph embedding learning and recommender systems. Here's how you will use a pretrained model:
model=model_zoo.chem.load_pretrained('GCN_Tox21')# Pretrained model loaded
model.eval()
smiles,g,label,mask=dataset[0]
feats=g.ndata.pop('h')
label_pred=model(g,feats)
```
We are currently in Beta stage. More features and improvements are coming.
**Further reading**: DGL is released as a managed service on AWS SageMaker, see the medium posts for an easy trip to DGL on SageMaker([part1](https://medium.com/@julsimon/a-primer-on-graph-neural-networks-with-amazon-neptune-and-the-deep-graph-library-5ce64984a276) and [part2](https://medium.com/@julsimon/deep-graph-library-part-2-training-on-amazon-sagemaker-54d318dfc814)).
**Researchers** can start from the growing list of [models implemented in DGL](https://github.com/dmlc/dgl/tree/master/examples). Developing new models does not mean that you have to start from scratch. Instead, you can reuse many [pre-built modules](https://docs.dgl.ai/api/python/nn.html). Here is how to get a standard two-layer graph convolutional model with a pre-built GraphConv module:
```python
fromdgl.nn.pytorchimportGraphConv
importtorch.nn.functionalasF
# build a two-layer GCN with ReLU as the activation in between
classGCN(nn.Module):
def__init__(self,in_feats,h_feats,num_classes):
super(GCN,self).__init__()
self.gcn_layer1=GraphConv(in_feats,h_feats)
self.gcn_layer2=GraphConv(h_feats,num_classes)
defforward(self,graph,inputs):
h=self.gcn_layer1(graph,inputs)
h=F.relu(h)
h=self.gcn_layer2(graph,h)
returnh
```
Next level down, you may want to innovate your own module. DGL offers a succinct message-passing interface (see tutorial [here](https://docs.dgl.ai/tutorials/basics/3_pagerank.html)). Here is how Graph Attention Network (GAT) is implemented ([complete codes](https://docs.dgl.ai/api/python/nn.pytorch.html#gatconv)). Of course, you can also find GAT as a module [GATConv](https://docs.dgl.ai/api/python/nn.pytorch.html#gatconv):
**Microbenchmark on speed and memory usage**: While leaving tensor and autograd functions to backend frameworks (e.g. PyTorch, MXNet, and TensorFlow), DGL aggressively optimizes storage and computation with its own kernels. Here's a comparison to another pupular package -- PyG. The short story is that raw speed is similar, but DGL has much better memory management.
| Dataset | Model | Accuracy | Time <br> PyG    DGL | Memory <br> PyG    DGL |
**Scalability**: DGL has fully leveraged multiple GPUs in both one machine and clusters for increasing training speed, and has better performance than alternatives, as seen in below images.
v0.4 has just been released! DGL now support **heterogeneous graphs**, and comes
with 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).
We are currently in Beta stage. More features and improvements are coming.
## Installation
DGL should work on
...
...
@@ -56,12 +145,10 @@ DGL should work on
* macOS X
* Windows 10
DGL also requires Python 3.5 or later. Python 2 support is coming.
DGL requires 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.
Right now, DGL works on [PyTorch](https://pytorch.org) 1.1.0+, [MXNet](https://mxnet.apache.org) nightly build, and [TensorFlow](https://tensorflow.org) 2.0+.
# You only need to deal with the case where all nodes have the same number
# of incoming messages.
q=nodes.data['q'][:,None]
k=nodes.mailbox['k']
v=nodes.mailbox['v']
s=F.softmax((q*k).sum(-1),1)[:,:,None]
return{'v':th.sum(s*v,1)}
classGATLayer(nn.Module):
def__init__(self,in_feats,out_feats):
super(GATLayer,self).__init__()
self.Q=nn.Linear(in_feats,out_feats)
self.K=nn.Linear(in_feats,out_feats)
self.V=nn.Linear(in_feats,out_feats)
defapply(self,nodes):
return{'v':F.relu(self.linear(nodes.data['v']))}
defforward(self,g,feature):
g.ndata['v']=self.V(feature)
g.ndata['q']=self.Q(feature)
g.ndata['k']=self.K(feature)
g.update_all(msg_func,reduce_func)
g.apply_nodes(func=self.apply)
returng.ndata['v']
```
For the basics of coding with DGL, please see [DGL basics](https://docs.dgl.ai/tutorials/basics/index.html).
For more realistic, end-to-end examples, please see [model tutorials](https://docs.dgl.ai/tutorials/models/index.html).
## New to Deep Learning and Graph Deep Learning?
Check out the open source book [*Dive into Deep Learning*](http://gluon.ai/).
## New to Deep Learning?
For those who are new to graph nerual network, please see the [basic of DGL](https://docs.dgl.ai/tutorials/basics/index.html).
Check out the open source book [*Dive into Deep Learning*](http://gluon.ai/).
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
...
...
@@ -183,6 +199,7 @@ Check out the open source book [*Dive into Deep Learning*](http://gluon.ai/).
Please let us know if you encounter a bug or have any suggestions by [filing an issue](https://github.com/dmlc/dgl/issues).
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).