I am trying to implement simple DiffPooling style network but with pre-defined clusters and layers. I am having trouble calling conv layers on subgraphs of batched heterographs.
The setup:
data_dict[('A', 'AA0', 'A')] = ([0,1,2,3],[1,0,3,2])
data_dict[('A', 'AB0', 'B')] = ([0,1],[0,0])
data_dict[('A', 'AB1', 'B')] = ([2,3],[1,1])
data_dict[('B', 'BC0', 'C')] = ([0,1],[0,0])
num_nodes_dict = {'A':4, 'B': 2, 'C':1}
base_graph = dgl.heterograph(data_dict, num_nodes_dict)
The graph is like a tree with the leaf nodes being type A, the middle nodes type B, and the root type C. I want to preform a series of convolutions on a batch of these graphs. Note these batched graphs are instance attributes to the model. The data coming in is a batch of A type features. Here is what I have so far:
Build Batched Subgraphs by Type
from copy import copy
batch_size = 2
aa_subgraph = dgl.batch([copy(base_graph.edge_type_subgraph(['AA0'])) for _ in range(batch_size)])
ab_subgraph = dgl.batch([copy(base_graph.edge_type_subgraph(['AB0','AB1'])) for _ in range(batch_size)])
bc_subgraph = dgl.batch([copy(base_graph.edge_type_subgraph(['BC0'])) for _ in range(batch_size)])
Build Conv Layers
aa_conv = dgl.nn.HeteroGraphConv({'AA0':dgl.nn.GraphConv(2,4,allow_zero_in_degree=True)})
ab_conv = dgl.nn.HeteroGraphConv({etype:dgl.nn.GATConv((4,8),8,1) for etype in ['AB0','AB1']})
bc_conv = dgl.nn.HeteroGraphConv({'BC0':dgl.nn.GATConv((8,16),16,1)})
Data Comes in
Features are the features of ntype A
a_feats = torch.randn((2,4,2))
Forward
a_feats = aa_conv(aa_subgraph, {'A':a_feats})['A']
# ERROR ON THE ABOVE LINE
b_feats = ab_conv(ab_subgraph, ({'A':a_feats, },{'B':torch.zeros((2,2,8))}))['B']
c_feats = bc_conv(bc_subgraph, ({'B':b_feats},{'C':torch.zeros((2,1,16))}))['C']
return c_feats
Error
The size of tensor a (2) must match the size of tensor b (8) at non-singleton dimension 0
While I put more info here needed than it takes to replicate the problem, I mostly wanted to ask if this was the recommended approach to a problem like this? Are there better ways to subgraph a batch of heterographs? Why is my conv_layer splitting up my batch internally? I am splitting my tree graph into a cascade of bipartite graphs. Is there a native way to do this or am I doing it correct by going step by step?
Thank you all in advance