PyTorch implementation中的挫折
PyTorch implement Color-GCN中的挫折
Dropout & Long
用Pytorch Implement GCN的时候,有一个error卡了我一天,google也没相关的答案:
1 | fused_dropout not implemented for 'long' |
自己找了会才发现不是dropout这个value的问题,而是input feature是 long。。。原来torch.Tensor([integer])会默认给int64(Long)而不是int32.。。真是奇怪的feature呢。
Cuda device
1 | RuntimeError: Expected object of device type cuda but got device type cpu for argument #2 'mat2' in call to _th_mm |
data,features,model全部都cuda()了,结果还是有问题。一个小时后的思索后。本侦探再次破案:
model.cuda() 这个func应该是把所有model中的Tensor 调用一遍 cuda(),大概伪代码就是:
1 | for Var in model: |
但是问题在于!
如果Var不是Tensor 而是一个list(别问为啥会是list,菜鸡最喜欢的就是list)
那么Var.cuda()就失效了,这样就需要在initilize的时候就遍历list里面所有的tensor,并调用tensor.to(‘device’)
Floating point exception (core dumped)
1 | Floating point exception (core dumped) |
网上查了下 这个就是某一步计算分母为0的error。
但是蛋疼的是 没有指示哪一行有错。而且python(或者说dgl还是pytorch)有个蛋疼的feature是这个exception在还没来得及print的时候就会直接跳出程序。(也就是说还不能用简单的print来定位)
最后用IPython embed()很蠢的一步一步。。发现问题是 如果dgl.Graph没有边(G.number_of_edges == 0),那么dgl自己的GATConv (Graph Attention Convolution会有问题),因此加了个dirty code判断这个情况,如果属实就直接生成一个zero vector(其实按道理应该是一个input feature itself,但是在这个work里面(graph color)反正没有边的图就没有利用价值,所以直接变成0)
DGL: Trying to create tensor with negative dimension
一步一步抽丝剥茧发现:
当pytorch的unique函数为gpu版本时,最后结果居然是一个dim=-251的vec(但问题在哪并不知道)。
奇怪的是单独写一个py文件用gpu调用这个函数并没有问题,同样的input同样的设备只有放到这个project里面才会return负数dim的vec。
暂时解决方法,将调用这个函数的func(in /dgl/core.py)改到cpu上:
1 | unique_val = F.asnumpy(F.unique(sorted_val)) |
魔幻的2020
国史大纲
最近读了钱穆先生的国史大纲。
其实是抱着拜读加兴趣的想法看的,但是却出乎我的意料:本来以为国史大纲是一本和三国志,史记类似的“史书”,谁知道,竟然真的是“大纲”,像是钱穆先生从文化、政治、经济、社会等各领域出发做的一篇篇演讲稿。又或者像是一篇涵盖computer science所有内容paper里面中的introduction板块。
内容不是很多,几晚上就读完了,恕我愚钝,对于这些领域的研究并不是很感冒,譬如。。。
(wait,刚刚意识到我下的国史大纲只有引论哈哈哈哈哈不行 我说怎么这么短呢哈哈哈哈哈哈哈哈 不行等我下个完整版看完再说)
Graph Isomorphsim Network Illustration
Graph Isomorphism Network 从数学理论的角度证明了,在验证graph是否同构(isomorphism)上,aggregation based gcn的能力不可能超过WL test。并以此提出了一个简单的graph isomorphism network,实现了能力范围内的最大效果。
本文是对知乎大佬论文解析的补充。
WL test
- The initial label of each node also influences the isomorphism. For example, $G_1$ and $G_2$ are graphs with same structure while $v^i_1,v^i_2$ has different labels, then the two graphs should be determined as non-isomorphism.
Lemma 2
若aggregation based gcn将异构两图map到不同的embedding(即成功分辨为不同构),则WL test也一定可以将该两图判定为不同构。
该定理为了证明aggregation based gcn的能力不可能超过WL test,其实还有一个是
若aggregation based gcn将同构两图map到相同的embedding(即成功分辨为同构),则WL test也一定可以将该两图判定为同构。
但这个是obvious的。。。
大概证明思路。
想象存在这样的两个异构图,使得gcn的embedding不一样,而WL test最后也无法判定(即最后output node label multiset 也一样)。
那么我们可以从WL无法判定的方向证明:
证明若WL 第i层node label一样,则gcn 第i层 node feature也肯定一样。
这个证明通过归纳法推得。
attention
和yuzhe讨论了下一个我看来奇怪的attention公式
$e_{ij}= a^T * [h_i||h_j]$
这里的$e_{ij}$ 代表the importance between meta-path based node pairs (即两点i对j的重要性), $||$是concat符号。$h_i$代表点i的feature,$a$即为 attention vector (trainable)
但是这样的e能代表的重要性关系其实为:
- $a_0 * h_i$ 越大,代表点i“重要性”越大,即不分相对关系,不管你是j1,j2还是j3,对于i1,i2,只要$a_0 * h_{i1}>a_0 * h_{i2}$,,则 $e_{i1j} > e_{i2j}$。不论j是哪个点。但这真的能代表某些网络间的attention关系吗?
后面又看了google的那篇 what you need is attention,明显可解释性就强多了。
UPDATE:
DAmn, 这个bug被比我聪明的人发paper了
HOW ATTENTIVE ARE GRAPH ATTENTION NETWORKS?
年末随笔
一下子第二个十年就过去了,一下子自己也不是那个可以什么都不顾的少年了。照例,记录下自己现在的思想。
离异
小时候,每次别人问起我,我都是面无表情地告诉他们我爸妈在我很小的时候就离婚了。而往往他们会给我一个惊讶转而同情的表情或言论,而我都是以一句“没关系”结束这个对话。
因为我是真的觉得爸妈离婚对孩子,至少对我来说,是没有什么大的影响的。我爱历史爱读书,所以读到了那么多可以为榜样的人物,那么多荡气回肠的人生故事,对我来说,爸妈离婚真算不了什么大事,古往今来挫折失败实在太多太多,人生就应像我的偶像苏东坡一样,活得率性就足够了。
可是这段时间我才觉着我错了。爸妈的离婚不是什么挫折,而是一个洞,一个精神我中的一个洞(物理我的洞就是。。。比克大魔王死的时候那样?哈哈哈哈哈哈)。虽然朋友知道的我是个大大咧咧率性乐观的人,但是我知道,这样的我,是初中以来自己慢慢调整过来的我。其实初中以前,我一直都是一个比较内敛感性的人,而最近的时间我才发现其实初中那个沉闷的小男孩还一直活在我心里,那个渴望疼爱、但是又战战兢兢不敢表露自己的小男孩一如既往,希望有个人能理解,能疼爱。
很早明白人生是一个人的旅程,但是看着别人,似乎觉得这句话不太对,别人的爸妈那么恩爱,和爸妈就像朋友一样,也有一个精神同样强大的伴侣互相扶持。所以其实,应该是我的人生,是一个人的旅程。从小学到中学,到大学,到现在,甚至到未来的博士,一想到这就好难受好难受,爸妈离婚了,他们有各自的家庭,我属于他们各自的家庭,也可以说我不属于任何一个家庭。朋友很多,但是曾经自以为的知心好友并不觉得我是什么好相处的人。而也太难有一个愿意去美国的对象,就算有也太难有一个能填补我这个洞的人了。
明白了这些,越来越对婚姻产生恐惧。害怕自己找不到对象,害怕找到对象后一直吵架然后离婚,又对自己的孩子挖了一个洞。。。从来没有享受过一个和谐温暖的家,我都不知道我有什么想象力和能力去propose一个那样的家。。。
油腻
这是一个很严肃的话题。我发现我开始变得油腻:一个油腻中年人的样子。
这次去南科大早说约好请明远一顿海底捞,路上碰到几个南科大同组的本科生于是邀约一起海底捞,最后他们要给我钱的时候,我拒绝了,嚷嚷着什么没事我请了。
拒绝完没觉得怎么样,但是晚上想到这件事,不知怎得就觉得自己是第三视角的一个路人,在冷眼看着一个油腻的中年大叔上演着那熟悉的套路:以钱财请客来彰显自己的能力。不觉一阵干呕。我试着缕清自己的行为为什么违背了自己的理想状态, 这件事上,我对“大方”产生了误解,人要大方要舍得,有舍才有得,但是大方不是通过不讲道理的请客来彰显自己的“大方”的,这样的行为,扪心自问,是想做一个大方的人吗,呵呵,只是像那些中年人一样,以此想彰显自己的能力,满足自己的虚荣心罢了。所以何为我们应该做的大方?当理应你请客,比如明远这个,大大方方,别扭扭捏捏就好,抑或是日常的小事物,或者朋友主动找上你需要你帮忙,这些东西便是大方的时候。
不仅仅是这件事。最近的许多事,都让我觉得我在渐渐从那个执剑的勇士,变成那条自己厌恶的恶龙。这样的反省肯定来得及,愿我出走半生,归来仍是少年。真的希望自己过了半辈子的时候,还保持着现在这样的少年感。
选择
最近看一位高中老师讲话的视频深有感触。
老师说,他羡慕孩子们,不是羡慕多年轻不是羡慕高中多美好,而是羡慕他们还有选择人生的机会。对啊,不是说现在的我们就不能选择自己人生了,只是说比起高中刚毕业还没选专业的时候,放弃自己现在的人生去做自己喜欢的事,代价太大,难度也太大了。不过我也不是那种不幸的人,至少现在的路我觉得挺好的,人生在世,大不了以后去当个高中老师,照样是教书育人,岂不美哉。
只是也可以感慨一下,如果没来中大学计算机,应该就是在上交当记者了。其实想想,记者/主持人这样的职业也是很适合我的。我一直自诩是一个正义积极、乐意为民请命的人。不过可能真当了记者,面对的冲突会比起现在仍然“象牙塔”般的研究来的大得多,另一个平行时空的我,希望别成为那个恶魔。。
2020
2019就这样过去了,遗憾就如太阳升起一样,照例还有。
2020最大的希望,是自己还是那个率性的少年,真诚待人,不要,一定不要成为自己厌恶的人。
然后就是继续加油,沉下心来学东西,做东西。晚上也早点睡,注意一下饮食,多吃点水果,多玩玩健身环,毕竟身体真的是革命的本钱哪。
医闹
很小的时候,我妈工作的医院经常有人闹事。每次家属把棺材摆在医院门口,横幅也是贴的“张灯结彩”,严重的几次我妈也要暂时回老家避避风头。那时没人管这种事,每次医院都是掏钱了事。
但是因为这样按闹分配的处理方式,后来摆棺材的人越来越多。最后一次摆棺材,院长实在受不了了,带上几十位医生和医生家属跟他们打了一架。从那之后,这种为了讹钱的医闹反倒再也没发生过。
就像乔峰聚贤庄被人津津乐道一样,那时在医院家属小朋友的圈子里,也流传着干架那次杨叔杨家拳一干三的神话。逐渐长大才懂得,所谓的神话,其实是医护工作者“被逼上梁山”的无奈。寒窗苦读十几年教的是救人之术,没有哪本书哪门课告诉这些医生怎么对付无赖,怎么保护自己。
医院终究还是充满人生悲喜剧的地方,那样无赖式的讹钱医闹少了,但是这样恶魔式的冲动杀人怎么办呢。为钱的医闹还可以有杨叔这类人来保护,但为命的由谁来保护?或者说索命的当下,谁来得及保护?
就像前段时间沸沸扬扬的pua事件一样,我也不知道怎么回答这个问题。只能希望未来越来越好,也希望各位能保持纯真善良,做一个积极正义的人。共勉。
ML in CPU core management
Overview
The paper explored the feasibility for ML techniques to support resource management algorithms. The main challenges are firstly discussed, then serveral potential remedies are proposed for these challenges, finally a proof-of-concept level experiment is conducted which demonstrates the feasibility.
Adv.
- The paper is well orgnized and the writing is good, especially, the figures and tables in the paper is well designed, which makes me enjoy the reading.
- The discussion of the feasibility by IL (imitation learning) and RL (Reinforcement learning) is impressive and the disadvantages of these methods hit the point (in my opinion)
- The usage of domain knowledge is well surveyed, the challenges and corresponding proposed remedies are inspiring and the tricks for solving realistic constraints can be also used in other projects.
Drawbacks
- Though RL is hard to formulate a reward function, RL is still can be adopted in this direction and deserves a deeper discussion in the future.
- Fig 5 is not neccesary since the result table does not belong to this work.
Writing mistakes
- page1. reached reached -> reached
- page4. inference time, performance and energy -> inference time, power and energy (It I understand it correctly)
- page6. The second challenge are model -> The second challenge is model
Heterogenous Graph Neural Network
For More information on GNN, please refer to here
General GNN
No normalization:
$$ {w}
H^{(k+1)} = activation((A+I)H^kW) \A = adjacent \ matrix \H^0 = features \ of \ graph \ nodes \W = trainable \ variables
$$
GCN can be also explained in a message-passing way where the intermediate representations can be viewed as messages.
The aggregation is the actual message-passing phase and each node passes its message to its neighbors along the edge ($X = (A+I)H^k$).
The encoder is served as the integration phase, in which each node integrates received the message and reduces it into its new message ($activation(XW)$).
Each message-pass and integration phase formulate one GCN layer.
The representation after the final layer is called the node embedding of each node and the graph embedding by GCN is usually obtained by a summation or mean operation using node embeddings.
How about HetGNN?
What is Het Graph?
Multiple kinds of edges, multiple kinds of nodes.

meta-path
- composed of edge types. e.t. author-paper-author
- meta-path indicates some sematic information. e.t. author-paper-author = co-author relationship/ paper contribution relationship
- multiple meta-paths (actually exponential to edge types ). (author-paper,author-paper-author,author-paper-venue,author-paper-venue-paper-author…)
IF we use general GNN to Het Graph…
- How to decide $A$, the adjacent matrix (there are multiple adjacent matrices for multiple types of edges)
- How to decide $H^0$, the input features of graph nodes. Different kinds of nodes have different kinds of features.
Also, there are some special points to be noted in Het Graph
- The number of direct neighbors are significantly unbalanced in some cases. (academic graph for example)
- The format of input feature may be different ( image, video, text… )
How to solve the problem?
Some more/modified steps are introduced:
[new] Reduce input content to vector feature
[modified] Decide neighbors (proper adjacent matrix $A$) to aggregate and aggregate neighbor features by different types (node type/edge type/meta path type)
[modified] encode new features by aggregated neighbor features
[new] encode new node feature by the generated new features of different types
| Input | Output | RGCN | HetGNN(KDD 19) | HetGAN(WWW 19) | GTN(NIPS 19) | General GCN | |
|---|---|---|---|---|---|---|---|
| [new] Reduce input content to vector feature of node | Input contents of each node (figs, texts…) | vector feature of each node | NA | contents->content features->node features(by biLSTM) | NA | NA | NA |
| [modified] Decide neighbors (proper adjacent matrix $A$) to aggregate and aggregate neighbor features by different types (node type/edge type/meta path type) | the graph | for each node $v$, tell him which nodes should be selected to receive there messages? | Direct neighbor, | select type-based neighbors with fixed size by random walk, | Manually selected meta-path neighbors | attention based meta-path(meta path is represented as a weighed multiplication of different edge type’s $A$) | Direct neighbor, |
| [modified] encode new features by aggregated neighbor features | Received messages of different type. | Encoded message of corresponding type | linear transformation | BiLSTM | attention sum with activation | linear transformation | linear transformation |
| [new] encode new node feature by the generated new features of different types | Encoded messages of different types | Final new feature(message) of this node $v$ | sum | attention sum | attention sum with activation | concat | NA |
| neighbor type | NA | NA | edge type | node type | meta path type | meta path type | NA |
Performance comparison
- [new] Reduce input content to vector feature
- biLSTM(0.67) > fc (0.65) [HetGNN]
- [modified] Decide neighbors (proper adjacent matrix $A$) to aggregate and aggregate neighbor features by different types (node type/edge type/meta path type)
- [modified] encode new features by aggregated neighbor features
- [new] encode new node feature by the generated new features of different types
- attention sum(0.768) > fc (0.763) [HetGNN]
- One more attention is always better… (icluding GTN)