DGL v0.3 版本今天正式發布啦!其中囊括了不少重大更新。

  • 首先是消息融合優化正式上線。該優化使得DGL能更快(比v0.2快了至多19倍),並在更大的圖上進行神經網路訓練(在單GPU上能訓練至多8倍大的圖)。有興趣的同學可以閱讀我們之前對於這一優化的詳細介紹。
  • 對於在巨圖上訓練神經網路有了更好的支持。同時我們發布了怎樣搭建分散式訓練的示例教程。
  • 更多新模型和神經網路模塊的實現。
  • 更多更好的圖結構操作的支持。

由於更新很多,所以在使用上也有了如下修改。

安裝

DGL仍然支持之前的pip和conda安裝方式,但會安裝僅有CPU環境的DGL。

pip install dgl
conda install -c dglteam dgl

使用Pip安裝CUDA環境DGL

請根據CUDA版本和系統環境選擇以下安裝命令:

(由於知乎不支持表格,想要複製粘貼的同學可以訪問我們的英文博客)

使用Conda安裝CUDA環境DGL

conda install -c dglteam dgl-cuda9.0 # For CUDA 9.0
conda install -c dglteam dgl-cuda10.0 # For CUDA 10.0

DGL目前支持CUDA 9.0和10.0。使用nvcc --version來檢測你的CUDA環境。對於想從源碼編譯安裝的同學,可以參考我們的安裝說明。

更多內建消息和累和函數

為了更好地支持消息融合優化,我們增加了許多新的內建消息函數(builtin message function)和累和函數(builtin reduce function)。DGL v0.2只支持copy_src, copy_edge, src_mul_edge等幾種。DGL v0.3仍然支持這些並擴展了更多組合。以下是一個簡單的示例代碼。

import dgl
import dgl.function as fn
import torch as th
g = ... # create a DGLGraph
g.ndata[h] = th.randn((g.number_of_nodes(), 10)) # each node has feature size 10
g.edata[w] = th.randn((g.number_of_edges(), 1)) # each edge has feature size 1
# collect features from source nodes and aggregate them in destination nodes
g.update_all(fn.copy_u(h, m), fn.sum(m, h_sum))
# multiply source node features with edge weights and aggregate them in destination nodes
g.update_all(fn.u_mul_e(h, w, m), fn.max(m, h_max))
# compute edge embedding by multiplying source and destination node embeddings
g.apply_edges(fn.u_mul_v(h, h, w_new))

可以看到,整體語法是非常直觀的。比如u_mul_e表示將起始節點的數據和邊上的數據乘在一起作為消息,u_mul_v代表將起始節點和目標節點的數據相乘,以此類推。每一個內建函數的組合都對應了一個CPU/CUDA kernel。同時還支持求導和broadcasting等常用的語義。詳情請參考我們的文檔。

巨圖訓練

添加了兩個針對巨圖訓練的新組建:基於共享內存(shared-memory)的DGLGraph以及分散式圖採樣模塊。同時,我們發布了兩篇教程:

  • 使用圖採樣訓練神經網路(鏈接)。
  • 使用分散式圖存儲模塊訓練巨圖神經網路(鏈接)。

此外,我們提供了搭建這一分散式環境的腳本和示例代碼 (鏈接)。

其他更新和Bugfix

  • NN modules
    • dgl.nn.[mxnet|pytorch].edge_softmax now directly returns the normalized scores on edges.
    • Fix a memory leak bug when graph is passed as the input.
  • Graph
    • DGLGraph now supports direct conversion from scipy csr matrix rather than conversion to coo matrix first.
    • Readonly graph can now be batched via dgl.batch.
    • DGLGraph now supports node/edge removal via DGLGraph.remove_nodes and DGLGraph.remove_edges (doc).
    • A new API DGLGraph.to(device) that can move all node/edge data to the given device.
    • A new API dgl.to_simple that can convert a graph to a simple graph with no multi-edges.
    • A new API dgl.to_bidirected that can convert a graph to a bidirectional graph.
    • A new API dgl.contrib.sampling.random_walk that can generate random walks from a graph.
    • Allow DGLGraph to be constructed from another DGLGraph.
  • New model examples
    • APPNP
    • GIN
    • PinSage (slow version)
    • DGI
  • Bugfix
    • Fix a bug where numpy integer is passed in as the argument.
    • Fix a bug when constructing from a networkx graph that has no edge.
    • Fix a bug in nodeflow where id is not correctly converted sometimes.
    • Fix a bug in MiniGC dataset where the number of nodes is not consistent.
    • Fix a bug in RGCN example when bfs_level=0.
    • Fix a bug where DLContext is not correctly exposed in CFFI.
    • Fix a crash during Cython build.
    • Fix a bug in send when the given message function is a builtin.

希望大家更多關注DGL。社區的反饋能更好地幫助DGL進步!

推薦閱讀:

相关文章