I do think that all the edge types have edges. But correct me if I’m wrong here -
The full graph and the block on which it errors is -
Graph(num_nodes={'image': 3, 'tag': 2},
num_edges={('image', 'hasTag', 'tag'): 4, ('image', 'similarTo', 'image'): 6, ('tag', 'hasImage', 'image'): 4},
metagraph=[('image', 'tag', 'hasTag'), ('image', 'image', 'similarTo'), ('tag', 'image', 'hasImage')])
Block(num_src_nodes={'image': 3, 'tag': 2},
num_dst_nodes={'image': 3, 'tag': 2},
num_edges={('image', 'hasTag', 'tag'): 4, ('image', 'similarTo', 'image'): 5, ('tag', 'hasImage', 'image'): 4},
metagraph=[('image', 'tag', 'hasTag'), ('image', 'image', 'similarTo'), ('tag', 'image', 'hasImage')])
I have attached the code for context. Let me know if you need more details and I’ll prepare and upload a small example file. I’m not sure how to proceed from this point.
Thanks a lot for helping!
Warm regards,
Sachin.
Code for context
Graph and features -
graph_data = {
('image', 'similarTo', 'image'): (th.tensor([0, 1, 2, 1, 0, 0]), th.tensor([1, 0, 0, 0, 1, 2])),
('image', 'hasTag', 'tag'): (th.tensor([0, 1, 2, 2]), th.tensor([0, 1, 0, 1])),
('tag', 'hasImage', 'image'): (th.tensor([0, 1, 0, 1]), th.tensor([0, 1, 2, 2]))
}
g = dgl.heterograph(graph_data)
inputs = {}
inputs['image'] = th.rand(3, 3)
inputs['tag'] = th.rand(2, 3)
Dataloader and training -
train_seeds = {
'similarTo': th.arange(6),
'hasTag': th.arange(4),
'hasImage': th.arange(4)
}
sampler = dgl.dataloading.MultiLayerNeighborSampler(
[2, 2])
train_dataloader = dgl.dataloading.EdgeDataLoader(
g, train_seeds, sampler,
negative_sampler=dgl.dataloading.negative_sampler.Uniform(2),
batch_size=2,
shuffle=True,
drop_last=False,
pin_memory=True,
num_workers=1)
for step, (input_nodes, pos_graph, neg_graph, blocks) in enumerate(train_dataloader):
batch_inputs = {x: inputs[x][input_nodes[x]] for x in input_nodes}
pos_graph = pos_graph
neg_graph = neg_graph
blocks = [block.int() for block in blocks]
# Compute loss and prediction
batch_pred = model(blocks, batch_inputs)
# Loss, backprop, etc.
forward()
function for my NN HeteroSAGE
(my above forward()
was for the layer HeteroSAGEConv
) -
def forward(self, blocks, x):
h_dict = x
for l, (layer, block) in enumerate(zip(self.layers, blocks)):
h_dict = layer(block, h_dict) # Error happens while this is executing
if l != len(self.layers) - 1:
h_dict = {k : self.activation(h) for k, h in h_dict.items()}
return h_dict