Unable to use EdgeDataLoader with GraphConvolution

I get the following error:

Traceback (most recent call last):
  File "/home/tudor/projects/xtailab/task2_graph_attention/link-prediction-sampler.py", line 64, in <module>
    pos_score, neg_score = model(positive_graph, negative_graph, blocks, node_feats, node_type)
  File "/home/tudor/.miniconda3/envs/xtailab/lib/python3.9/site-packages/torch/nn/modules/module.py", line 889, in _call_impl
    result = self.forward(*input, **kwargs)
  File "/home/tudor/projects/xtailab/task2_graph_attention/model_multi.py", line 249, in forward
    h = self.rgcn(blocks, x)
  File "/home/tudor/.miniconda3/envs/xtailab/lib/python3.9/site-packages/torch/nn/modules/module.py", line 889, in _call_impl
    result = self.forward(*input, **kwargs)
  File "/home/tudor/projects/xtailab/task2_graph_attention/model_multi.py", line 212, in forward
    x = self.conv1(blocks[0], x)
  File "/home/tudor/.miniconda3/envs/xtailab/lib/python3.9/site-packages/torch/nn/modules/module.py", line 889, in _call_impl
    result = self.forward(*input, **kwargs)
  File "/home/tudor/.miniconda3/envs/xtailab/lib/python3.9/site-packages/dgl/nn/pytorch/hetero.py", line 176, in forward
    dstdata = self.mods[etype](
  File "/home/tudor/.miniconda3/envs/xtailab/lib/python3.9/site-packages/torch/nn/modules/module.py", line 889, in _call_impl
    result = self.forward(*input, **kwargs)
  File "/home/tudor/.miniconda3/envs/xtailab/lib/python3.9/site-packages/dgl/nn/pytorch/conv/graphconv.py", line 417, in forward
    graph.srcdata['h'] = feat_src
  File "/home/tudor/.miniconda3/envs/xtailab/lib/python3.9/site-packages/dgl/view.py", line 81, in __setitem__
    self._graph._set_n_repr(self._ntid, self._nodes, {key : val})
  File "/home/tudor/.miniconda3/envs/xtailab/lib/python3.9/site-packages/dgl/heterograph.py", line 3992, in _set_n_repr
    raise DGLError('Expect number of features to match number of nodes (len(u)).'
dgl._ffi.base.DGLError: Expect number of features to match number of nodes (len(u)). Got 1893 and 349 instead.

Process finished with exit code 1

This happends because in the GraphConv Layer the following update is being made

                graph.srcdata['h'] = feat_src

Here graph is a block.

I think I know what my issue could be, here

    def forward(self, blocks, x):
        x = self.conv1(blocks[0], x)
        x = self.conv2(blocks[1], x)
        return 

I send for the first conv1 all the node features, while blocks[0] doesnt’ have all of them. so the feat_src ends up being(len(nodes), hid_feat), so 1893, while it’s supposed to have 349.

Edit: the mistake was that the input wasnt take from the first block, but from the whole graph.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.