Hello, when I implemented the R-GCN code, such a problem occurred


optimizer = torch.optim.Adam(model.parameters(), lr=lr, weight_decay=l2norm)

print(“start training…”)
for epoch in range(n_epochs):
logits = model.forward(g).type(torch.uint8)
loss = F.cross_entropy(logits[train_idx], labels[train_idx])



train_acc = torch.sum(logits[train_idx].argmax(dim=1) == labels[train_idx])
train_acc = train_acc.item() / len(train_idx)
val_loss = F.cross_entropy(logits[val_idx], labels[val_idx])
val_acc = torch.sum(logits[val_idx].argmax(dim=1) == labels[val_idx])
val_acc = val_acc.item() / len(val_idx)
print("Epoch {:05d} | ".format(epoch) +

"Train Accuracy: {:.4f} | Train Loss: {:.4f} | ".format(
train_acc, loss.item()) +
“Validation Accuracy: {:.4f} | Validation loss: {:.4f}”.format(
val_acc, val_loss.item()))

As mentioned in the error, you need to check the data type of g[…].edata[‘rel_type’], which must be long, byte or bool tensors.

Thanks for your reply. I saw his prompt, but I don’t know where to change this type.

You may take a look at g.etypes, which will give you the edge types in the graph.

Yes, I saw it. How do I modify him now?

You just need to reset it with

g.edges[etype].data['rel_type'] = g.edges[etype].data['rel_type'].long()

OK, Thank you very much.