dmlc / dmlc/dgl

problem in batching wrt schemes and subgraphs

Open
#6,686 3 comments 0 reactions 0 assignees View on GitHub
stale-issue
Dominant language
Python
Stars
14.3k
Forks
3.1k
PR merge metrics
No merged PRs in 30d

Description

## 🐛 Bug

When batching graphs, schemes can be incorrectly checked, in the case were the scheme is present but the number of edge with this scheme is 0

## To Reproduce

1. create two simple hetero graphs
`g1 = dgl.heterograph({("n", "r1", "n"): ([0],[1]), ("n", "r2", "n"):((),())})`
`g2 = dgl.heterograph({("n", "r1", "n"): ([0],[1]), ("n", "r2", "n"):((),())})`

2. add a new edge to g2, with some data
`g2.add_edges([0],[2], etype="r2", data = { "r": torch.tensor([1])})`

3. extract subgraphs , removing completely edge type "r2"
`g3 = dgl.node_subgraph(g1,[0,1])`
`g4 = dgl.node_subgraph(g2,[0,1])`

4. we have that :
`g3.edge_attr_schemes(etype="r2")` gives `{'_ID': Scheme(shape=(), dtype=torch.int64)}`
`g3.num_edges(etype="r2")` gives `0`
`g4.num_edges(etype="r2")` also gives `0` (as node 2 was removed, so was the only edge of type "r2")
BUT
`g4.edge_attr_schemes(etype="r2")` gives `{'r': Scheme(shape=(), dtype=torch.int64), '_ID': Scheme(shape=(), dtype=torch.int64)}`

5. so, when trying to batch this stuff:
`b = dgl.batch([g3,g4])`
we get :
```
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python3.10/dist-packages/dgl/batch.py", line 217, in batch
ret_feat = _batch_feat_dicts(
File "/usr/local/lib/python3.10/dist-packages/dgl/batch.py", line 247, in _batch_feat_dicts
utils.check_all_same_schema(schemas, feat_dict_name)
File "/usr/local/lib/python3.10/dist-packages/dgl/utils/checks.py", line 207, in check_all_same_schema
raise DGLError(
dgl._ffi.base.DGLError: Expect all graphs to have the same schema on edges[('n', 'r2', 'n')].data, but graph 1 got
{'r': Scheme(shape=(), dtype=torch.int64), '_ID': Scheme(shape=(), dtype=torch.int64)}
which is different from
{'_ID': Scheme(shape=(), dtype=torch.int64)}.
```

## Expected behavior

correct batching, either by removing scheme when number of a given edge type becomes 0, or any other mean

## Environment

- DGL Version (e.g., 1.0): 1.1.2
- Backend Library & Version (e.g., PyTorch 0.4.1, MXNet/Gluon 1.3): pytorch 2.1.0
- OS (e.g., Linux): Linux
- How you installed DGL (`conda`, `pip`, source): pip
- Build command you used (if compiling from source):
- Python version: 3.10
- CUDA/cuDNN version (if applicable): 11.7
- GPU models and configuration (e.g. V100):
- Any other relevant information:

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.