DGL v0.3 版本今天正式發布啦!其中囊括了不少重大更新。
由於更新很多,所以在使用上也有了如下修改。
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以及分散式圖採樣模塊。同時,我們發布了兩篇教程:
此外,我們提供了搭建這一分散式環境的腳本和示例代碼 (鏈接)。
dgl.nn.[mxnet|pytorch].edge_softmax
DGLGraph
dgl.batch
DGLGraph.remove_nodes
DGLGraph.remove_edges
DGLGraph.to(device)
dgl.to_simple
dgl.to_bidirected
dgl.contrib.sampling.random_walk
send
希望大家更多關注DGL。社區的反饋能更好地幫助DGL進步!
推薦閱讀: