My Problem
I’ve been working from the stochastic training example we all know and love. As such, I have a block generated by this little number. The train_graph is a hetero graph, two node types (a,b) and one connection type (link).
sampler = MultiLayerFullNeighborSampler(2)
trainloader = NodeDataLoader(train_graph, train_nodes, sampler, batch_size=b_size, shuffle=False, drop_last=False, device=device)
My goal
What I’m wanting to do is load a feature (let’s call it feat) from all the neighbours of a given destination node in a given block. This is ultimately so I can apply a weighting to my custom loss function based the variation of the feat between the given nodes neighbors. The function I need is something along the lines of:
def my_dream_func(block,feat,(dst_id:ntype)):
magic
return({'neigh_feat':[horizon_feats]})
My attempt
The code below, works for one sample(if I just look at one block from the data loader). However, when I iterate over it. Boom Win Error. As you can no doubt see, it seems really inefficent, get a block, then turn it into a graph, then get a subgraph, then make a block…
for _,_,blocks in trainloader:
b_graph = dgl.block_to_graph(blocks[-1]).cpu()
for dtype in ['a_dst','b_dst']:
if b_graph.num_nodes(dtype)!=0:
weights = []
for id in b_graph.nodes[dtype].data['_ID']:
frontier = dgl.in_subgraph(b_graph, {dtype:id})
block_copy = dgl.to_block(frontier, {dtype:id})
src_data = block_copy.srcdata
for n_type in src_data['feat'].keys():
type_labels = src_data['feat'][n_type].detach().numpy()
My Question
Is there an easy obvious way to get a feature from all neighbors of a given node, from a block, generated from a heterograph?
Notes
- I can provide details of the error but I suspect I’m just missing a more obvious solution.
- I was previously working with GPU, but I’ve tested on just the cpu and it didn’t resolve my issue.