Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Model] Heterogeneous graph support for GNNExplainer #4401

Merged
merged 60 commits into from
Oct 27, 2022
Merged

[Model] Heterogeneous graph support for GNNExplainer #4401

merged 60 commits into from
Oct 27, 2022

Conversation

moeinfinityx
Copy link
Contributor

Description

Add Heterogeneous Graph support for GNNExplainer

Checklist

Please feel free to remove inapplicable items for your PR.

  • The PR title starts with [$CATEGORY] (such as [NN], [Model], [Doc], [Feature]])
  • Changes are complete (i.e. I finished coding on this PR)
  • All changes have test coverage
  • Code is well-documented
  • 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
  • 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.

* add HeteroGNNExplainer

* GNNExplainer for heterogeenous graph

* fix typo

* variable name cleanup
@moeinfinityx moeinfinityx changed the title [Model] Heterogeneous graph support for GNNExplainer (#1) [Model] Heterogeneous graph support for GNNExplainer Aug 16, 2022
@dgl-bot
Copy link
Collaborator

dgl-bot commented Aug 16, 2022

To trigger regression tests:

  • @dgl-bot run [instance-type] [which tests] [compare-with-branch];
    For example: @dgl-bot run g4dn.4xlarge all dmlc/master or @dgl-bot run c5.9xlarge kernel,api dmlc/master

@dgl-bot
Copy link
Collaborator

dgl-bot commented Aug 16, 2022

Commit ID: 164530c

Build ID: 1

Status: ❌ CI test failed in Stage [Lint Check].

Report path: link

Full logs path: link

@dgl-bot
Copy link
Collaborator

dgl-bot commented Aug 16, 2022

Commit ID: fdc3648

Build ID: 2

Status: ❌ CI test failed in Stage [Lint Check].

Report path: link

Full logs path: link

@atmaranto
Copy 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

@dgl-bot
Copy link
Collaborator

dgl-bot commented Aug 19, 2022

Commit ID: d4b33df

Build ID: 3

Status: ❌ CI test failed in Stage [Lint Check].

Report path: link

Full logs path: link


# Extract node-centered k-hop subgraph and
# its associated node and edge features.
sg, inverse_indices = khop_in_subgraph(graph, {ntype: node_id},self.num_hops)
Copy link
Collaborator

@zhjwy9343 zhjwy9343 Aug 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This khop_subgraph operation may not fit all explanation cases. If the model is trained with other sampling methods other than the khop_subgraph, here the explainer may fail to achieve the same model performance, or even broken.

I would suggest to off this workload to the caller of this method, i.e., no matter what "graph" is passed in this function, directly use it as the input of the model without any operation.

Downside of this suggestion is that we need to modify the init_masks() to let it deal with different graph structure.

@mufeili
Copy link
Member

mufeili commented Aug 25, 2022

You will need to fix "This branch is out-of-date with the base branch"

@mufeili
Copy link
Member

mufeili commented Aug 25, 2022

@mufeili
Copy link
Member

mufeili commented Aug 25, 2022

Missing doc indexing here https://github.com/dmlc/dgl/blob/master/docs/source/api/python/nn-pytorch.rst for documentation rendering

@dgl-bot
Copy link
Collaborator

dgl-bot commented Aug 26, 2022

Commit ID: 458db9b

Build ID: 4

Status: ❌ CI test failed in Stage [Lint Check].

Report path: link

Full logs path: link

@dgl-bot
Copy link
Collaborator

dgl-bot commented Sep 6, 2022

Commit ID: None

Build ID: 6

Status: ✅ CI test succeeded

Report path: link

Full logs path: link

@dgl-bot
Copy link
Collaborator

dgl-bot commented Sep 8, 2022

Commit ID: 77811b4067395b930b3360d72492695402000333

Build ID: 7

Status: ❌ CI test failed in Stage [Authentication].

Report path: link

Full logs path: link

@dgl-bot
Copy link
Collaborator

dgl-bot commented Sep 8, 2022

Commit ID: 8ee055c88952b489d25b5613bd1b8dd843039782

Build ID: 8

Status: ❌ CI test failed in Stage [Authentication].

Report path: link

Full logs path: link

@dgl-bot
Copy link
Collaborator

dgl-bot commented Sep 8, 2022

Commit ID: 373ad9d

Build ID: 9

Status: ❌ CI test failed in Stage [Authentication].

Report path: link

Full logs path: link

@mufeili
Copy link
Member

mufeili commented Sep 12, 2022

@Rhett-Ying Is it no longer allowed for community contributors to trigger the CI test? What will be alternatives?

@mufeili
Copy link
Member

mufeili commented Oct 26, 2022

It seems that the test failed for idtype int32 and succeeded for the other idtype int64 on GPU. On CPU, both are succeeded. Did you encounter this issue locally?

@mufeili
Copy link
Member

mufeili commented Oct 26, 2022

@dgl-bot

@dgl-bot
Copy link
Collaborator

dgl-bot commented Oct 26, 2022

Not authorized to trigger CI. Please ask core developer to help trigger via issuing comment:

  • @dgl-bot

@dgl-bot
Copy link
Collaborator

dgl-bot commented Oct 26, 2022

Commit ID: 39f74ef

Build ID: 59

Status: ❌ CI test failed in Stage [Authentication].

Report path: link

Full logs path: link

@dgl-bot
Copy link
Collaborator

dgl-bot commented Oct 26, 2022

Commit ID: 39f74ef

Build ID: 60

Status: ❌ CI test failed in Stage [Torch GPU Unit test].

Report path: link

Full logs path: link

@dgl-bot
Copy link
Collaborator

dgl-bot commented Oct 26, 2022

Not authorized to trigger CI. Please ask core developer to help trigger via issuing comment:

  • @dgl-bot

@dgl-bot
Copy link
Collaborator

dgl-bot commented Oct 26, 2022

Commit ID: 3c653ba

Build ID: 61

Status: ❌ CI test failed in Stage [Authentication].

Report path: link

Full logs path: link

@kunmukh
Copy link
Contributor

kunmukh commented Oct 26, 2022

It seems that the test failed for idtype int32 and succeeded for the other idtype int64 on GPU. On CPU, both are succeeded. Did you encounter this issue locally?

@mufeili no, I did not. I tried reproducing this on my end by could not reproduce it. I ran bash tests/scripts/task_unit_test.sh pytorch gpu one more right now and no test failed. I am attaching a screenshot.

My configuration:

  • GPU Model: Tesla V100-PCIE-16GB GPU
  • Python version: 3.8.10
  • CUDA Version: 11.6
  • Torch Version: 1.10.0+cu111
  • DGL Version: 0.6.1

image

@dgl-bot
Copy link
Collaborator

dgl-bot commented Oct 27, 2022

Not authorized to trigger CI. Please ask core developer to help trigger via issuing comment:

  • @dgl-bot

@dgl-bot
Copy link
Collaborator

dgl-bot commented Oct 27, 2022

Commit ID: d06b54fd17ef2d34f505f396100aea056cc27b78

Build ID: 62

Status: ❌ CI test failed in Stage [Authentication].

Report path: link

Full logs path: link

@dgl-bot
Copy link
Collaborator

dgl-bot commented Oct 27, 2022

Not authorized to trigger CI. Please ask core developer to help trigger via issuing comment:

  • @dgl-bot

@dgl-bot
Copy link
Collaborator

dgl-bot commented Oct 27, 2022

Commit ID: cfc8a3e

Build ID: 63

Status: ❌ CI test failed in Stage [Authentication].

Report path: link

Full logs path: link

@Rhett-Ying
Copy link
Collaborator

@dgl-bot

@dgl-bot
Copy link
Collaborator

dgl-bot commented Oct 27, 2022

Commit ID: cfc8a3e

Build ID: 64

Status: ✅ CI test succeeded

Report path: link

Full logs path: link

@mufeili
Copy link
Member

mufeili commented Oct 27, 2022

@dgl-bot

@dgl-bot
Copy link
Collaborator

dgl-bot commented Oct 27, 2022

Not authorized to trigger CI. Please ask core developer to help trigger via issuing comment:

  • @dgl-bot

@dgl-bot
Copy link
Collaborator

dgl-bot commented Oct 27, 2022

Commit ID: 254048e1790fd106dbc4743fff45c9ecf8e161d1

Build ID: 65

Status: ❌ CI test failed in Stage [Authentication].

Report path: link

Full logs path: link

@dgl-bot
Copy link
Collaborator

dgl-bot commented Oct 27, 2022

Not authorized to trigger CI. Please ask core developer to help trigger via issuing comment:

  • @dgl-bot

@dgl-bot
Copy link
Collaborator

dgl-bot commented Oct 27, 2022

Commit ID: 4672be3

Build ID: 66

Status: ❌ CI test failed in Stage [Authentication].

Report path: link

Full logs path: link

@mufeili
Copy link
Member

mufeili commented Oct 27, 2022

@dgl-bot

@dgl-bot
Copy link
Collaborator

dgl-bot commented Oct 27, 2022

Commit ID: 4672be3

Build ID: 67

Status: ✅ CI test succeeded

Report path: link

Full logs path: link

@mufeili mufeili merged commit 4b1fb68 into dmlc:master Oct 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants