Heterograph instantiation error on CUDA
- Dominant language
- Python
- Stars
- 14.3k
- Forks
- 3.1k
- PR merge metrics
- No merged PRs in 30d
Description
## 🐛 Bug
Seems like a repeat of https://github.com/dmlc/dgl/issues/3873, but I can't reopen it so adding a new issue. DGL fails to instantiate a heterograph on CUDA with an empty edge list.
## To Reproduce
Steps to reproduce the behavior:
```python
import dgl
import torch
device = "cuda:0"
graph_data = {
("v", "e1", "v"): (torch.tensor([0, 1], device=device), torch.tensor([1, 0], device=device)),
("v", "e2", "v"): ([], []),
}
graph = dgl.heterograph(
graph_data,
device=device,
num_nodes_dict={"v": 2},
)
```
```
Traceback (most recent call last):
File "", line 1, in
File "/home/jovyan/.conda-envs/lib/python3.11/site-packages/dgl/convert.py", line 381, in heterograph
hgidx = heterograph_index.create_heterograph_from_relations(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/jovyan/.conda-envs/lib/python3.11/site-packages/dgl/heterograph_index.py", line 1374, in create_heterograph_from_relations
return _CAPI_DGLHeteroCreateHeteroGraphWithNumNodes(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "dgl/_ffi/_cython/./function.pxi", line 295, in dgl._ffi._cy3.core.FunctionBase.__call__
File "dgl/_ffi/_cython/./function.pxi", line 227, in dgl._ffi._cy3.core.FuncCall
File "dgl/_ffi/_cython/./function.pxi", line 217, in dgl._ffi._cy3.core.FuncCall3
dgl._ffi.base.DGLError: [15:41:48] /opt/dgl/src/graph/heterograph.cc:133: Check failed: rg->Context() == ctx (cpu:0 vs. cuda:0) : Each relation graph must have the same context.
Stack trace:
[bt] (0) /home/jovyan/.conda-envs/lib/python3.11/site-packages/dgl/libdgl.so(+0x93a7e4) [0x7fc57533a7e4]
[bt] (1) /home/jovyan/.conda-envs/lib/python3.11/site-packages/dgl/libdgl.so(dgl::HeteroGraph::HeteroGraph(std::shared_ptr, std::vector, std::allocator > > const&, std::vector > const&)+0x7a3) [0x7fc57533b903]
[bt] (2) /home/jovyan/.conda-envs/lib/python3.11/site-packages/dgl/libdgl.so(dgl::CreateHeteroGraph(std::shared_ptr, std::vector, std::allocator > > const&, std::vector > const&)+0x5a) [0x7fc57530d37a]
[bt] (3) /home/jovyan/.conda-envs/lib/python3.11/site-packages/dgl/libdgl.so(+0x94ba72) [0x7fc57534ba72]
[bt] (4) /home/jovyan/.conda-envs/lib/python3.11/site-packages/dgl/libdgl.so(DGLFuncCall+0x4f) [0x7fc5752da93f]
[bt] (5) /home/jovyan/.conda-envs/lib/python3.11/site-packages/dgl/_ffi/_cy3/core.cpython-311-x86_64-linux-gnu.so(+0x1da07) [0x7fc57421da07]
[bt] (6) /home/jovyan/.conda-envs/lib/python3.11/site-packages/dgl/_ffi/_cy3/core.cpython-311-x86_64-linux-gnu.so(+0x1e260) [0x7fc57421e260]
[bt] (7) python(_PyObject_MakeTpCall+0x29b) [0x5580bf8af75b]
[bt] (8) python(_PyEval_EvalFrameDefault+0x70a) [0x5580bf8bcdda]
```
## Expected behavior
No error
## Environment
- DGL Version (e.g., 1.0): 2.4.0
- Backend Library & Version (e.g., PyTorch 0.4.1, MXNet/Gluon 1.3): PyTorch 2.4.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.11.11
- CUDA/cuDNN version (if applicable):
- 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.