第十一周.01.GNN sampling

Posted oldmao_2001

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了第十一周.01.GNN sampling相关的知识,希望对你有一定的参考价值。


本文内容整理自深度之眼《GNN核心能力培养计划》
公式输入请参考: 在线Latex公式

Cluster-GCN: An Efficient Algorithm for Training Deep and large graph Convolutional Networks
作者:Wei-Lin Chiang、 Xuanging liu、 SiSi、Yang li、 Samy bengio、 Cho-Jui Hsieh
出处:KDD 2019
原文代码
还有一篇额外参考,清华大学的VRGCN

摘要

先讲现状和现有的问题
现状:GCN很不错
Graph convolutional network (GCN) has been successfully applied to many graph-based applications;

转折:大规模节点的图不好弄
however, training a large-scale GCN remains challenging.

现有的SGD算法计算成本很大
Current SGD-based algorithms suffer from either a high computational cost that exponentially grows with number of GCN layers, or a large space requirement for keeping the entire graph and the embedding of each node in memory.

本文提出了Cluster-GCN。。。。
In this paper, we propose Cluster-GCN, a novel GCN algorithm that is suitable for SGD-based training by exploiting the graph clustering structure.

Cluster-GCN的工作原理是。。。。
Cluster-GCN works as the following: at each step, it samples a block of nodes that associate with a dense subgraph identified by a graph clustering algorithm, and restricts the neighborhood search within this subgraph.

这样做的好处是。。。。
This simple but effective strategy leads to significantly improved memory and computational efficiency while being able to achieve comparable test accuracy with previous algorithms.

实验环境咋整的
To test the scalability of our algorithm, we create a new Amazon2M data with 2 million nodes and 61 million edges which is more than 5 times larger than the previous largest publicly available dataset (Reddit).

3层效果是SOTA的
For training a 3-layer GCN on this data, Cluster-GCN is faster than the previous state-of-the-art VR-GCN (1523 seconds vs 1961 seconds) and using much less memory (2.2GB vs 11.2GB).

SOTA还不够,还要秀一把别的模型都玩不起(out-of-memory)的玩法4层
Furthermore, for training 4 layer GCN on this data, our algorithm can finish in around 36 minutes while all the existing GCN training algorithms fail to train due to the out-of-memory issue.

4层还不够,5层也玩得飞起,还破了PPI的SOTA
Furthermore, Cluster-GCN allows us to train much deeper GCN without much time and memory overhead, which leads to improved prediction accuracy—using a 5-layer Cluster-GCN, we achieve state-of-the-art test F1 score 99.36 on the PPI dataset, while the previous best result was 98.71 by GaAN

Introduction

这里原文总结了GCN的三个要点,

  1. memory requirement
  2. time per epoch
  3. convergence speed (loss reduction) per epoch.

第一个要点限制算法的扩展性
后两个决定了模型训练的速度

然后给出notation:
b b b表示batch的大小
N N N表示图中的节点数;
F F F表示embedding的维数;
L L L表示GCN的层数

然后给出几个经典算法的复杂度

模型GD算法复杂度内存使用特点收敛速度
GCNFull-batch GD O ( N F L ) O(NFL) O(NFL)所有节点都在内存,需要较多内存所有点的信息都在内存,每个epoch计算比较高效每个epoch只更新一次参数,收敛速度慢
GraphSAGEMini-batch SGD与L有指数关系每次只放一个batch,需要较少内存在获取邻居信息来计算当前节点loss比较麻烦,计算低效一个epoch更新多次,收敛速度快
VR-GCN O ( N F L ) O(NFL) O(NFL)需要存储所有节点的中间的embeddings,需要内存较多高效
Cluster-GCN与L成线性关系 O ( b F L ) O(bFL) O(bFL)高效

最后总结了本文模型的几个优点:
1.内存使用非常nice;
2.计算复杂度与层数L成线性关系;
3.可以构成又深又大规模的网络。

BACKGROUND

不写了,就是GCN公式来一套。

PROPOSED ALGORITHM

这里再次把上面的表格重新展开,逐个分析现有算法的缺点。主要是空间、计算复杂度的比较

原始GCN

Full-batch GD需要存储所有节点的embedding矩阵: { Z ( l ) } l = 1 L \\{Z^{(l)}\\}_{l=1}^L {Z(l)}l=1L
空间复杂度: O ( N F L ) O(NFL) O(NFL)
由于模型在每个epoch才更新一次,所以需要很多个epoch才能收敛。

原始mini-batch SGD

虽然mini-batch SGD在一个epoch会更新多次,所以收敛速度上要快很多。
但是mini-batch SGD计算节点embedding过程会有额外开销。下面以某一个节点 i i i的loss计算为例来说明:
∇ loss ( y i , z i ( L ) ) \\nabla\\text{loss}(y_i,z_i^{(L)}) loss(yi,zi(L))
公式中显示需要节点 i i i的embedding z i z_i zi,而 z i z_i zi的计算依赖于它的邻居的embeddings,然后还有邻居的邻居的embeddings。
假设一个 L L L层GCN网络,每个节点的平均度数为 d d d,为了获得节 i i i的embedding z i z_i zi,需要聚合 O ( d L ) O(d^L) O(dL)个节点的特征,相当于取hop-k跳的邻居信息来进行一次更新。而且每一次 F F F维embedding计算要和 F F F维的参数 W ( l ) W^{(l)} W(l),计算复杂度就是 O ( F 2 ) O(F^2) O(F2),合起来一个节点玩一次梯度计算,时间复杂度是: O ( d L F 2 ) O(d^LF^2) O(dLF2),图中有N个点,那么就是: O ( N d L F 2 ) O(Nd^LF^2) O(NdLF2)

Embedding utilization

这个概念第一次看到,意思是特征的利用率,如果有学过Oracle数据库优化就知道,频繁的从硬盘读取数据是很慢的,要是能把常常查询的数据放到内存中,那么查询效率就会变高,就好比卖衣服的会把最热门的,最流行的衣服放到进门那里,美其名曰:热销爆款。这些个做法就是提高数据或者衣服的利用率或者曝光率,使得用户或者顾客很快拿到数据或衣服。
可以看到,上面的原始mini-batch SGD,Embedding utilization非常差,其正式定义为:
节点 i i i在第 l l l层的embedding: z i z_i zi 在计算第 l + 1 l + 1 l+1层的embeddings时被重用的次数 u u u
mini-batch SGD是随机抽样的,而且图比较大且稀疏,u非常小(很小的常数,代表没有重用),那么mini-batch SGD每个batch需要计算的embedding个数为: O ( b d L ) O(bd^L) O(bdL)
每个batch的时间复杂度为: O ( b d L F 2 ) O(bd^LF^2) O(bdLF2)
整个epoch的时间复杂度是: O ( N d L F 2 ) O(Nd^LF^2) O(NdLF2)

对于Full-batch GD,每个embedding可在 l + 1 l + 1 l+1层重复使用 d d d(平均度数)次
每个epoch需要计算的embedding个数为: O ( N L ) O(NL) O(NL)

Embedding utilization是本文模型思路的核心,务必理解。

改进mini-batch SGD

GraphSAGE就是使用的改进mini-batch SGD,它对邻居的扩展做了限制,每次均匀地采样一个固定大小的邻居集。如果把采样大小记做 r r r,那么:
改进mini-batch SGD每个batch需要计算的embedding个数为: O ( b r L ) O(br^L) O(brL),这样玩会使得loss估计的准确度降低。

3.1 Vanilla Cluster-GCN

模型的目标:设计一个batch和相应的计算子图来最大限度地提高embedding utilization。

左边是GCN,右边是本文模型,可以看到本文模型通过聚类,简化了部分边。

例子:
在每个batch中,计算来自于第1层到第 L L L层的节点集合 B \\mathcal{B} B的embeddings。
取仅由 B \\mathcal{B} B组成的子图,集合 B \\mathcal{B} B之外的点忽略掉: A B , B A_{\\mathcal{B},\\mathcal{B}} AB,B
上面那个 A A A实际上就是 B \\mathcal{B} B组成的子图的邻接矩阵,整个batch的Embedding utilization就是邻接矩阵的非零元素:
∣ ∣ A B , B ∣ ∣ 0 ||A_{\\mathcal{B},\\mathcal{B}}||_0 AB,B0
要想使得Embedding utilization最大,就要使得邻接矩阵里面的边越稠密越好。
就是设计一个batch 节点集合 B \\mathcal{B} B来最大化batch内的边的数量。
有了这个思想,就可以来看Cluster-GCN了。
对于一个图 G G G,可以把它的节点分成 c c c个组: V = [ V 1 , . . . , V c ] V=[V_1,...,V_c] V=[V1,...,Vc],也就是 c c c个子图:
G ˉ = [ G 1 ​ , . . . , G c ​ ] = [ { V 1 ​ , ε 1 ​ } , . . . , { V c ​ , ε c ​ } ] \\bar G=[G_1​ ,...,G_c​ ]=[\\{V_1​ ,\\varepsilon_1​\\},...,\\{V_c​ ,\\varepsilon_c​ \\}] Gˉ=[G1,...,Gc]=[{V1,ε1},...,{Vc,εc}]
其中每个 ε t \\varepsilon_t εt只包含在节点集合 V t V_t Vt中的节点间的边。
表示成数学:
原始的邻接矩阵是 A A A
然后切成 c 2 c^2 c2份:
A = [ A 11 ⋯ A 1 c ⋮ ⋱ ⋮ A c 1 ⋯ A c c ] = A ˉ + Δ = [ A 11 ⋯ 0 ⋮ ⋱ ⋮

以上是关于第十一周.01.GNN sampling的主要内容,如果未能解决你的问题,请参考以下文章

第十一周课程总结

第十一周学习进度

第十一周 继承与多态

第十一周学习进度(补)

每周学习进度第十一周

第十一周