dmlc / dmlc/dgl

[RFC] Support for graph level features

Open
#6,942 8 comments 4 reactions 0 assignees View on GitHub
feature request topic: Message Passing API
Dominant language
Python
Stars
14.3k
Forks
3.1k
PR merge metrics
No merged PRs in 30d

Description

## 🚀 Feature
The purpose of this issue is to resume discussion on graph level features from issues #417, #714, #737, #1316, #1449. Implementing support for graph level features for dgl.DGLGraph could be beneficial for various reasons. I will try to soon follow with a PR if this RFC is reviewed positively.

## Motivation

Multiple GNN models are using graph level features or global features not only as constant tensors or numbers included in message passing functions but rather as learnable parameters. Relevant examples were given in above mentioned issues. Additional example could be MEGNet model, described in https://arxiv.org/pdf/1812.05055.pdf. Implementing graph level features into dgl.DGLGraph would surely be convenient for users that are now forced to write their own workarounds.

## Pitch

Graph level features should be easy to set, accessible for all message passing functions and correctly concatenated during dgl.batch() function. Usage of graph level features in DGL could look like this:
```
g.gdata["feat"] = graph_level_features

def edge_udf(self, edges):
graph_level_features = edges._graph.gdata["feat"]

def node_udf(self, nodes):
graph_level_features = edges._graph.gdata["feat"]
```

## Alternatives

Currently, as established in above mentioned issues, DGL doesn't directly support graph level features, neither in singular DGLGraph class nor in batch graphs. Two alternatives have been presented.

1. User can add `gdata` attribute to DGLGraph object using `setattr()` python function
```
setattr(g, "gdata", {})
g.gdata["feat"] = graph_level_features
```
This option is insufficient as `gdata` will be inaccessible in `edge_udf()` or `node_udf()`. Those functions operate on `dgl.udf.EdgeBatch` and `dgl.udf.NodeBatch` objects respectively and although dataset graph can be accessed (by calling `dgl.udf.EdgeBatch._graph` or `dgl.udf.NodeBatch._graph`) `gdata` set by user will not be included in this `_graph` attribute.

2. User can add `gdata` dictionary to his GNN model as class attribute

```
class Model:
def __init__(self):
self.gdata = {}
self.gdata["feat"] = graph_level_features
```
This option allows access to `gdata` in node and edge udf, within this specific class, but user still has to include graph level features into batch of graphs on his own, where it could be done automatically, as it is for edge and node features. It is also more problematic with complex models that use multiple classes and modules, which can modify those graph level features. In such case user needs to include additional parameter in all relevant class constructors and their functions to properly track and update graph level features. Instead, it could be passed with DGLGraph as an attribute.

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.