-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Conversation
* add HeteroGNNExplainer * GNNExplainer for heterogeenous graph * fix typo * variable name cleanup
To trigger regression tests:
|
provng: DGL PR#4401 READMEIn 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.
The GNNExplainer requires the model being explained to accept an 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:
|
|
||
# 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) |
There was a problem hiding this comment.
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.
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 |
@Rhett-Ying Is it no longer allowed for community contributors to trigger the CI test? What will be alternatives? |
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? |
Not authorized to trigger CI. Please ask core developer to help trigger via issuing comment:
|
Not authorized to trigger CI. Please ask core developer to help trigger via issuing comment:
|
@mufeili no, I did not. I tried reproducing this on my end by could not reproduce it. I ran My configuration:
|
Not authorized to trigger CI. Please ask core developer to help trigger via issuing comment:
|
Not authorized to trigger CI. Please ask core developer to help trigger via issuing comment:
|
Not authorized to trigger CI. Please ask core developer to help trigger via issuing comment:
|
Not authorized to trigger CI. Please ask core developer to help trigger via issuing comment:
|
Description
Add Heterogeneous Graph support for GNNExplainer
Checklist
Please feel free to remove inapplicable items for your PR.
or have been fixed to be compatible with this change
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.