[Model] Heterogeneous graph support for GNNExplainer
Description
Add Heterogeneous Graph support for GNNExplainer
Checklist
Please feel free to remove inapplicable items for your PR.
- [x] The PR title starts with [$CATEGORY] (such as [NN], [Model], [Doc], [Feature]])
- [x] Changes are complete (i.e. I finished coding on this PR)
- [x] All changes have test coverage
- [x] Code is well-documented
- [x] To the best of my knowledge, examples are either not affected by this change, or have been fixed to be compatible with this change
- [ ] Related issue is referred in this PR
- [x] If the PR is for a new model/paper, I've updated the example index here.
Changes
Added a new class HeteroGNNExplainer for Heterogeneous graph explanation.
The output of the model has been manually verified on MUTAG dataset. Unfortunately there's no ground truth for the explanation, so we cannot quantify the model's performance. Instead, we manually investigated the results and confirms that it aligns well with human intuition.
Link to the MUTAG Hetero GNNExplainer notebook
The code has also been verified on several datasets DGL officially provides, see this repo for details.
Inline documentation is added following the original style, and an example of using the module is included in the documentation.
To trigger regression tests:
-
@dgl-bot run [instance-type] [which tests] [compare-with-branch]; For example:@dgl-bot run g4dn.4xlarge all dmlc/masteror@dgl-bot run c5.9xlarge kernel,api dmlc/master
Commit ID: 164530c55e71ab430ac4cbbc1a0145e978167665
Build ID: 1
Status: ❌ CI test failed in Stage [Lint Check].
Report path: link
Full logs path: link
Commit ID: fdc364824307143dba8d46165a4b619600276b2f
Build ID: 2
Status: ❌ CI test failed in Stage [Lint Check].
Report path: link
Full logs path: link
provng: DGL PR#4401 README
In this PR, we created a new class HeteroGNNExplainer which is the heterogeneous version of the GNNExplainer class. HeteroGNNExplainer takes a Heterogeneous GNN classification model and its input graph as parameters and generates an explanation in a similar form to GNNExplainer.
The main difference between a homogenous graph and a heterogeneous graph is that a heterogeneous graph can have multiple edge types and node types. Therefore, we changed the input data structure from a tensor of values to a dictionary mapping a type to a tensor of values. To enable compatibility with heterogeneous graphs, we changed every instance that the explainer assumes the graph data is a tensor to instead assume that it is a dictionary of tensors.
The HeteroGNNExplainer is implemented similarly in structure to the homogenous implementation. We had to adjust each function in the explainer framework that used input data to ensure compatibility with the new input format. Additionally, changes had to be made to the masks’ initializations to ensure they were also initialized as dictionaries. For instance, from __init_masks() method, you can see the following code.
# Simplifed version of edge mask initalization
edge_mask = {}
for canonical_etype in graph.canonical_etypes:
num_edges = graph.number_of_edges(canonical_etype)
edge_mask[canonical_etype] = torch.randn(num_edges)
The GNNExplainer requires the model being explained to accept an eweight parameter in the forward function. For HeteroGNNExplainer, this parameter also becomes a dictionary (of canonical_etypes). An example is provided in the inline documentation following the same style of the original GNNExplainer class.
In summary, the HeteroGNNExplainer is similar in structure to the homogenous GNNExplainer. Our main contribution is to accomodate the input data format of a heterogeneous graph.
tags: provng,dgl,ahad
Commit ID: d4b33dfe2fd8f15e2562af50d7447ccda17e0871
Build ID: 3
Status: ❌ CI test failed in Stage [Lint Check].
Report path: link
Full logs path: link
You will need to fix "This branch is out-of-date with the base branch"
Missing unit test in https://github.com/dmlc/dgl/blob/master/tests/pytorch/test_nn.py
Missing doc indexing here https://github.com/dmlc/dgl/blob/master/docs/source/api/python/nn-pytorch.rst for documentation rendering
Commit ID: 458db9b538731fd30eb2d4cd201478fd4e8d52ba
Build ID: 4
Status: ❌ CI test failed in Stage [Lint Check].
Report path: link
Full logs path: link
Commit ID: 77811b4067395b930b3360d72492695402000333
Build ID: 7
Status: ❌ CI test failed in Stage [Authentication].
Report path: link
Full logs path: link
Commit ID: 8ee055c88952b489d25b5613bd1b8dd843039782
Build ID: 8
Status: ❌ CI test failed in Stage [Authentication].
Report path: link
Full logs path: link
Commit ID: 373ad9d5d835371120181c2995c73c6730de4a65
Build ID: 9
Status: ❌ CI test failed in Stage [Authentication].
Report path: link
Full logs path: link
@Rhett-Ying Is it no longer allowed for community contributors to trigger the CI test? What will be alternatives?
@Rhett-Ying Is it no longer allowed for community contributors to trigger the CI test? What will be alternatives?
Yes, only the core developers are allowed. You could help trigger via making below comments here: @dgl-bot.
@dgl-bot
@Rhett-Ying Is it no longer allowed for community contributors to trigger the CI test? What will be alternatives?
Yes, only the core developers are allowed. You could help trigger via making below comments here:
@dgl-bot.
Got it. Thanks! Perhaps then we should disable the auto trigger of CI as the community contributors can be confused with Authentication.
Commit ID: 373ad9d5d835371120181c2995c73c6730de4a65
Build ID: 10
Status: ❌ CI test failed in Stage [Regression Test].
Report path: link
Full logs path: link
Commit ID: fd01972707d8165092575b01b90992cf69b8fee4
Build ID: 13
Status: ❌ CI test failed in Stage [Authentication].
Report path: link
Full logs path: link
Commit ID: c9e25603b118ec7cb3a2c9fe18672baa24f440d6
Build ID: 14
Status: ❌ CI test failed in Stage [Authentication].
Report path: link
Full logs path: link