IndexError: index out of range in self in gnn

Joshua_Jenny_Sibbu: <pre><code class="lang-auto">IndexError Traceback (most recent call last)
/tmp/ipykernel_4126/534676331.py in
1 for i in loader:
----&gt; 2 output=model(i['x_s'],i['x_t'],i['edge_index'])

/home/ubuntu/anaconda3/lib/python3.9/site-packages/torch/nn/modules/module.py in _call_impl(self, *input, **kwargs)
1108 if not (self._backward_hooks or self._forward_hooks or self._forward_pre_hooks or _global_backward_hooks
1109 or _global_forward_hooks or _global_forward_pre_hooks):
-&gt; 1110 return forward_call(*input, **kwargs)
1111 # Do not call functions when jit is used
1112 full_backward_hooks, non_full_backward_hooks = [], []

/tmp/ipykernel_4126/502885603.py in forward(self, source, target, edge_index)
27 edge_index_=edge_index_.to(torch.long)
28
---&gt; 29 x = self.conv1(source_R,edge_index_)
30
31 return x

/home/ubuntu/anaconda3/lib/python3.9/site-packages/torch/nn/modules/module.py in _call_impl(self, *input, **kwargs)
1108 if not (self._backward_hooks or self._forward_hooks or self._forward_pre_hooks or _global_backward_hooks
1109 or _global_forward_hooks or _global_forward_pre_hooks):
-&gt; 1110 return forward_call(*input, **kwargs)
1111 # Do not call functions when jit is used
1112 full_backward_hooks, non_full_backward_hooks = [], []

/home/ubuntu/anaconda3/lib/python3.9/site-packages/torch_geometric/nn/conv/sage_conv.py in forward(self, x, edge_index, size)
78
79 # propagate_type: (x: OptPairTensor)
---&gt; 80 out = self.propagate(edge_index, x=x, size=size)
81 out = self.lin_l(out)
82

/home/ubuntu/anaconda3/lib/python3.9/site-packages/torch_geometric/nn/conv/message_passing.py in propagate(self, edge_index, size, **kwargs)
307 kwargs[arg] = decomp_kwargs[arg][i]
308
--&gt; 309 coll_dict = self.collect(self.user_args, edge_index,
310 size, kwargs)
311

/home/ubuntu/anaconda3/lib/python3.9/site-packages/torch_geometric/nn/conv/message_passing.py in collect(self, args, edge_index, size, kwargs)
200 if isinstance(data, Tensor):
201 self.set_size(size, dim, data)
--&gt; 202 data = self.lift(data, edge_index, dim)
203
204 out[arg] = data

/home/ubuntu/anaconda3/lib/python3.9/site-packages/torch_geometric/nn/conv/message_passing.py in lift(self, src, edge_index, dim)
170 if isinstance(edge_index, Tensor):
171 index = edge_index[dim]
--&gt; 172 return src.index_select(self.node_dim, index)
173 elif isinstance(edge_index, SparseTensor):
174 if dim == 1:

IndexError: index out of range in self
</code></pre>
<p>I’m working in bipartite graph.<br>
shapes:<br>
source - torch.Size([3, 32]) [features,nodes]<br>
target - torch.Size([3, 100])[features,nodes]<br>
edge_index - torch.Size([2, 745])</p>
<pre><code class="lang-auto">class GNN(torch.nn.Module):
       def init(self, hidden_channels, out_channels):
       super().init()
       self.conv1 = SAGEConv((-1, -1), hidden_channels,normalize=True)
       self.conv2 = SAGEConv((-1, -1), out_channels,normalize=True)

def forward(self, source,target, edge_index):
    source_,target_,edge_index_=torch.tensor(source),torch.tensor(target),torch.tensor(edge_index)

    print('I_shape',source_.shape)
    print('I_shape',target_.shape)
    print('I_shape',edge_index_.shape)
    
    source_R=source_.reshape(3,32)
    target_R=target_.reshape(3,100)
    edge_index_=edge_index_.reshape(2,745)
    
    print('shape',source_R.shape)
    print('shape',target_R.shape)
    print('shape',edge_index_.shape)
    
    edge_index_=edge_index_.to(torch.long)
    
    x = self.conv1(source_R,edge_index_)
    
    return x```</code></pre>