DGLError Expected data to have %d rows, got %d. occurs at large batch size
- Dominant language
- Python
- Stars
- 14.3k
- Forks
- 3.1k
- PR merge metrics
- No merged PRs in 30d
Description
## 🐛 Bug
DGLError('Expected data to have %d rows, got %d.') occurs at large batch__size, and doesnt occur at smaller batch_size. The larger the batch_size the larger the difference in rows. Feels like a rounding error somewhere.
## To Reproduce
```python
BATCH_SIZE = 1000 # <---- works fine
# BATCH_SIZE = 5000 # <---- DGL errors
sampler = dgl.dataloading.NeighborSampler([4, 4])
_, _, mfgs = sampler.sample_blocks(train_pos_g, seed_ids[:BATCH_SIZE])
print(mfgs[0].srcdata['feat'].shape)
# torch.Size([10239, 128]) <---- works fine
# torch.Size([48913, 128]) <---- DGL errors
model(mfgs, mfgs[0].srcdata['feat']) # <---- errors
```
## Expected behavior
Shouldn't DGLError
## Environment
- DGL 0.8.2
- pytorch 1.11.0+cpu
- python 3.10.5
## Additional context
### model:
```
# model is the default 2 layer graphSage in the tutorials
import torch.nn as nn
import torch.nn.functional as F
from dgl.nn import SAGEConv
class Model(nn.Module):
def __init__(self, in_feats, h_feats):
super(Model, self).__init__()
self.conv1 = SAGEConv(in_feats, h_feats, aggregator_type='mean')
self.conv2 = SAGEConv(h_feats, h_feats, aggregator_type='mean')
self.h_feats = h_feats
def forward(self, mfgs, x):
h_dst = x[:mfgs[0].num_dst_nodes()]
h = self.conv1(mfgs[0], (x, h_dst))
h = F.relu(h)
h_dst = h[:mfgs[1].num_dst_nodes()]
h = self.conv2(mfgs[1], (h, h_dst))
return h
```
### Error stack:
```
---------------------------------------------------------------------------
DGLError Traceback (most recent call last)
Input In [58], in ()
9 print(mfgs[0].srcdata['feat'].shape)
10 # torch.Size([10239, 128]) works fine
11 # torch.Size([48913, 128]) DGL errors
---> 13 model(mfgs, mfgs[0].srcdata['feat'])
File /opt/conda/lib/python3.10/site-packages/torch/nn/modules/module.py:1110, in Module._call_impl(self, *input, **kwargs)
1106 # If we don't have any hooks, we want to skip the rest of the logic in
1107 # this function, and just call forward.
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):
-> 1110 return forward_call(*input, **kwargs)
1111 # Do not call functions when jit is used
1112 full_backward_hooks, non_full_backward_hooks = [], []
Input In [1], in Model.forward(self, mfgs, x)
101 h = F.relu(h)
102 h_dst = h[:mfgs[1].num_dst_nodes()]
--> 103 h = self.conv2(mfgs[1], (h, h_dst))
104 return h
File /opt/conda/lib/python3.10/site-packages/torch/nn/modules/module.py:1110, in Module._call_impl(self, *input, **kwargs)
1106 # If we don't have any hooks, we want to skip the rest of the logic in
1107 # this function, and just call forward.
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):
-> 1110 return forward_call(*input, **kwargs)
1111 # Do not call functions when jit is used
1112 full_backward_hooks, non_full_backward_hooks = [], []
File /opt/conda/lib/python3.10/site-packages/dgl/nn/pytorch/conv/sageconv.py:235, in SAGEConv.forward(self, graph, feat, edge_weight)
233 if self._aggre_type == 'mean':
234 graph.srcdata['h'] = self.fc_neigh(feat_src) if lin_before_mp else feat_src
--> 235 graph.update_all(msg_fn, fn.mean('m', 'neigh'))
236 h_neigh = graph.dstdata['neigh']
237 if not lin_before_mp:
File /opt/conda/lib/python3.10/site-packages/dgl/heterograph.py:4900, in DGLHeteroGraph.update_all(self, message_func, reduce_func, apply_node_func, etype)
4898 key = list(ndata.keys())[0]
4899 ndata[key] = F.replace_inf_with_zero(ndata[key])
-> 4900 self._set_n_repr(dtid, ALL, ndata)
4901 else: # heterogeneous graph with number of relation types > 1
4902 if not core.is_builtin(message_func) or not core.is_builtin(reduce_func):
File /opt/conda/lib/python3.10/site-packages/dgl/heterograph.py:4136, in DGLHeteroGraph._set_n_repr(self, ntid, u, data)
4132 raise DGLError('Pinned graph requires the node data to be pinned as well. '
4133 'Please pin the node data before assignment.')
4135 if is_all(u):
-> 4136 self._node_frames[ntid].update(data)
4137 else:
4138 self._node_frames[ntid].update_row(u, data)
File /opt/conda/lib/python3.10/_collections_abc.py:994, in MutableMapping.update(self, other, **kwds)
992 if isinstance(other, Mapping):
993 for key in other:
--> 994 self[key] = other[key]
995 elif hasattr(other, "keys"):
996 for key in other.keys():
File /opt/conda/lib/python3.10/site-packages/dgl/frame.py:584, in Frame.__setitem__(self, name, data)
574 def __setitem__(self, name, data):
575 """Update the whole column.
576
577 Parameters
(...)
582 The column data.
583 """
--> 584 self.update_column(name, data)
File /opt/conda/lib/python3.10/site-packages/dgl/frame.py:661, in Frame.update_column(self, name, data)
659 col = Column.create(data)
660 if len(col) != self.num_rows:
--> 661 raise DGLError('Expected data to have %d rows, got %d.' %
662 (self.num_rows, len(col)))
663 self._columns[name] = col
DGLError: Expected data to have 5000 rows, got 4998.
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.