Error while iterating through GraphDataLoader

Hi guys.
I’m new to DGL and following the graph classification topic (training loop section) I’m trying to iterate through the dataloader (GraphDataLoader) to train a GNN model, but I’m getting the following error:

DGLError: [15:08:45] /opt/dgl/src/graph/./heterograph.h:34: Check failed: etype < meta_graph_->NumEdges() (53 vs. 53) : Invalid edge type: 53

Stack trace:

[bt] (1) /usr/local/lib/python3.10/dist-packages/dgl/libdgl.so(dgl::HeteroGraph::GetRelationGraph(unsigned long) const+0x14e) [0x7a261097773e] 
[bt] (2) /usr/local/lib/python3.10/dist-packages/dgl/libdgl.so(dgl::DisjointUnionHeteroGraph2(std::shared_ptr<dgl::GraphInterface>, std::vector<std::shared_ptr<dgl::BaseHeteroGraph>, std::allocator<std::shared_ptr<dgl::BaseHeteroGraph> > > const&)+0x2d6) [0x7a2610a60f96] 
[bt] (3) /usr/local/lib/python3.10/dist-packages/dgl/libdgl.so(+0x7893ce) [0x7a26109893ce] 
[bt] (4) /usr/local/lib/python3.10/dist-packages/dgl/libdgl.so(+0x789574) [0x7a2610989574] 
[bt] (5) /usr/local/lib/python3.10/dist-packages/dgl/libdgl.so(DGLFuncCall+0x48) [0x7a261090e558] 
[bt] (6) /usr/local/lib/python3.10/dist-packages/dgl/_ffi/_cy3/core.cpython-310-x86_64-linux-gnu.so(+0x1a2c6) [0x7a25fe01a2c6] 
[bt] (7) /usr/local/lib/python3.10/dist-packages/dgl/_ffi/_cy3/core.cpython-310-x86_64-linux-gnu.so(+0x1ab1f) [0x7a25fe01ab1f] 
[bt] (8) /usr/bin/python3(_PyObject_MakeTpCall+0x25b) [0x59a228e8ea7b]

The piece of code related to the error is:

dataloader = GraphDataLoader(
    d_train,
    batch_size=5,
    drop_last=False,
    shuffle=True)

     12 for epoch in range(20):
-->  13     for batched_graph, labels in dataloader: # line getting error
     14         logits = model(batched_graph)
     15         loss = F.cross_entropy(logits, labels)

The data is composed by multiple heterographs (100 for training), with 1 node type, and 60 edge types. The batch_size=5.

Each graph represents some user’s activities such as downloading some software. The nodes of the graphs are system entities (hosts, processes, files) and the edges are Linux system calls.

Could someone indicate to me what might be triggering this error?
If any more information is required, I’m available :slight_smile: Thanks in advance.

After some tests, I checked that the error happens because some of the graphs have more etypes than others. Because of that I have 2 questions:

  1. Trying to batch only 2 graphs with different sizes of etypes (the set of etypes of the graph with less etypes is fully contained into the set with more etypes) I get the error described above only if the graph with more etypes is placed as first argument of the function, but if it’s placed as second argument, the batch process occurs normally.
    I would like to know why it occurs. Below is an example to illustrate the 2 cases:

    → dgl.batch(g_less_etypes, g_more_etypes) # works perfectly
    → dgl.batch(g_more_etypes, g_less_etypes) # gives error

  2. As I defined all the possible etypes at meta.yaml (I’ve used the ‘Loading data from CSV’ as reference), is it possible to make all the graphs containing all the possible etypes, with empty tuples the graphs that does not contain any edge of that type?

Thanks again for the support :slight_smile:

Hi @Chaves2021, dgl.batch expected all graphs to have the same etypes. Otherwise, it is a undefined behavior.

Hi @czkkkkkk. Sorry for the late response.

Thanks for clarifying about dgl.batch. I would just like to know if it’s possible to define the etypes of all graphs loaded from csv, even though they have empty edges of that etype. Currently, only etypes of existent edges are defined in the graphs.

Thanks again for your answer and availability :slight_smile:

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