I followed the instructions from the error:
AssertionError: The HeteroNodeDataView has only one node type. please pass a tensor directly
Therefore, I changed
node_features = graph.nodes[node_type].data['feature']
labels = graph.edges[target_edge].data['label']
train_mask = graph.edges[target_edge].data['train_mask']
feats = {'node': node_features}
opt = torch.optim.Adam(model.parameters())
for epoch in range(100):
model.train()
pred = model(graph, feats, target_edge)
# pred = model(graph, node_features, target_edge)
loss = ((pred[train_mask] - labels[train_mask]) ** 2).mean()
opt.zero_grad()
loss.backward()
opt.step()
print(loss.item())
to
node_features = graph.nodes[node_type].data['feature']
labels = graph.edges[target_edge].data['label']
train_mask = graph.edges[target_edge].data['train_mask']
opt = torch.optim.Adam(model.parameters())
for epoch in range(100):
model.train()
pred = model(graph, node_features, target_edge)
loss = ((pred[train_mask] - labels[train_mask]) ** 2).mean()
opt.zero_grad()
loss.backward()
opt.step()
print(loss.item())
But now I get the following error
RuntimeError: Tensor.__contains__ only supports Tensor or scalar, but you passed in a <class 'str'>.
This is caused by
def __contains__(self, element):
r"""Check if `element` is present in tensor
Args:
element (Tensor or scalar): element to be checked
for presence in current tensor"
"""
if has_torch_function_unary(self):
return handle_torch_function(Tensor.__contains__, (self,), self, element)
if isinstance(element, (torch.Tensor, Number)):
# type hint doesn't understand the __contains__ result array
return (element == self).any().item() # type: ignore[union-attr]
raise RuntimeError(
"Tensor.__contains__ only supports Tensor or scalar, but you passed in a %s." %
type(element)
)
where element is ‘node’
This is triggered by the fact that the code executes the second part of the if.
if isinstance(inputs, tuple) or g.is_block:
if isinstance(inputs, tuple):
src_inputs, dst_inputs = inputs
else:
src_inputs = inputs
dst_inputs = {k: v[:g.number_of_dst_nodes(k)] for k, v in inputs.items()}
for stype, etype, dtype in g.canonical_etypes:
rel_graph = g[stype, etype, dtype]
if rel_graph.number_of_edges() == 0:
continue
if stype not in src_inputs or dtype not in dst_inputs:
continue
dstdata = self.mods[etype](
rel_graph,
(src_inputs[stype], dst_inputs[dtype]),
*mod_args.get(etype, ()),
**mod_kwargs.get(etype, {}))
outputs[dtype].append(dstdata)
else:
for stype, etype, dtype in g.canonical_etypes:
rel_graph = g[stype, etype, dtype]
if rel_graph.number_of_edges() == 0:
continue
if stype not in inputs: # <--- error from the stacktrace
continue
dstdata = self.mods[etype](
rel_graph,
(inputs[stype], inputs[dtype]),
*mod_args.get(etype, ()),
**mod_kwargs.get(etype, {}))
outputs[dtype].append(dstdata)
How should I format my input
, which is a Tensor of shape(no_nodes, no_features) to be a tuple?