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

GNNExplainer migration #5967

Merged
merged 61 commits into from
Nov 25, 2022
Merged

Conversation

dufourc1
Copy link
Member

@dufourc1 dufourc1 commented Nov 13, 2022

  • Implements the GNNExplainer in the new explain module.
  • Add the argument node_index and target_index to the explain.Explainer class to allow for explanations of model with multi-outputs and specify the node.
  • Update the examples of the GNNExplainer (Example of Using the New Explainability Framework #5924)

@codecov
Copy link

codecov bot commented Nov 13, 2022

Codecov Report

Merging #5967 (c2b64e0) into master (d24e8e1) will decrease coverage by 2.17%.
The diff coverage is 93.19%.

@@            Coverage Diff             @@
##           master    #5967      +/-   ##
==========================================
- Coverage   86.44%   84.26%   -2.18%     
==========================================
  Files         361      362       +1     
  Lines       20298    20404     +106     
==========================================
- Hits        17547    17194     -353     
- Misses       2751     3210     +459     
Impacted Files Coverage Δ
...rch_geometric/explain/algorithm/dummy_explainer.py 90.47% <ø> (ø)
torch_geometric/explain/explainer.py 100.00% <ø> (+1.96%) ⬆️
torch_geometric/nn/models/explainer.py 72.33% <ø> (-24.51%) ⬇️
torch_geometric/explain/algorithm/utils.py 78.57% <78.57%> (ø)
torch_geometric/explain/algorithm/gnn_explainer.py 94.47% <94.47%> (ø)
torch_geometric/explain/algorithm/__init__.py 100.00% <100.00%> (ø)
torch_geometric/explain/algorithm/base.py 87.23% <100.00%> (+30.09%) ⬆️
torch_geometric/explain/config.py 100.00% <100.00%> (ø)
torch_geometric/nn/models/__init__.py 100.00% <100.00%> (ø)
torch_geometric/nn/models/dimenet_utils.py 0.00% <0.00%> (-75.52%) ⬇️
... and 25 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@dufourc1
Copy link
Member Author

Not so sure how to deal with multi-outputs for classification (node/graph). Does it even make sens ?

@dufourc1 dufourc1 marked this pull request as ready for review November 13, 2022 15:27
@dufourc1 dufourc1 marked this pull request as draft November 13, 2022 17:51
@dufourc1 dufourc1 marked this pull request as ready for review November 13, 2022 23:20
Copy link
Member

@wsad1 wsad1 left a comment

Choose a reason for hiding this comment

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

Thanks for adding this. Left some initial comments. Will take a look again tomorrow.

torch_geometric/explain/algorithm/base.py Show resolved Hide resolved
torch_geometric/explain/algorithm/gnn_explainer.py Outdated Show resolved Hide resolved
torch_geometric/explain/algorithm/gnn_explainer.py Outdated Show resolved Hide resolved
torch_geometric/explain/algorithm/gnn_explainer.py Outdated Show resolved Hide resolved
Copy link
Member

@wsad1 wsad1 left a comment

Choose a reason for hiding this comment

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

The GNNExplainer part looks good. Will review the test and examples next.

torch_geometric/explain/algorithm/gnn_explainer.py Outdated Show resolved Hide resolved
torch_geometric/explain/algorithm/gnn_explainer.py Outdated Show resolved Hide resolved
torch_geometric/explain/algorithm/gnn_explainer.py Outdated Show resolved Hide resolved
torch_geometric/explain/algorithm/gnn_explainer.py Outdated Show resolved Hide resolved
@rusty1s rusty1s changed the title GNNExplainer migration GNNExplainer migration Nov 15, 2022
- add test for `shared_mask=False`
- rename function only used internally
CHANGELOG.md Outdated Show resolved Hide resolved
torch_geometric/explain/algorithm/__init__.py Outdated Show resolved Hide resolved
torch_geometric/explain/algorithm/base.py Show resolved Hide resolved
torch_geometric/explain/algorithm/base.py Outdated Show resolved Hide resolved
torch_geometric/explain/algorithm/gnn_explainer.py Outdated Show resolved Hide resolved
torch_geometric/explain/algorithm/gnn_explainer.py Outdated Show resolved Hide resolved
torch_geometric/explain/algorithm/gnn_explainer.py Outdated Show resolved Hide resolved
torch_geometric/explain/algorithm/utils.py Show resolved Hide resolved
torch_geometric/nn/models/__init__.py Show resolved Hide resolved
- add new MaskType
- add better information for user in `supports`
- typos
- change `index` to `node_index`
@rusty1s rusty1s mentioned this pull request Nov 22, 2022
3 tasks
Copy link
Contributor

@avgupta456 avgupta456 left a comment

Choose a reason for hiding this comment

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

Some small testing bugs

test/explain/algorithm/test_gnn_explainer.py Show resolved Hide resolved
test/explain/algorithm/test_gnn_explainer.py Outdated Show resolved Hide resolved
test/explain/algorithm/test_gnn_explainer.py Outdated Show resolved Hide resolved
test/explain/algorithm/test_gnn_explainer.py Outdated Show resolved Hide resolved
test/explain/algorithm/test_gnn_explainer.py Outdated Show resolved Hide resolved
test/explain/algorithm/test_gnn_explainer.py Outdated Show resolved Hide resolved
Copy link
Contributor

@avgupta456 avgupta456 left a comment

Choose a reason for hiding this comment

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

Mostly stylistic requests for tests

test/explain/algorithm/test_gnn_explainer.py Outdated Show resolved Hide resolved
test/explain/algorithm/test_gnn_explainer.py Outdated Show resolved Hide resolved
test/explain/algorithm/test_gnn_explainer.py Outdated Show resolved Hide resolved
test/explain/algorithm/test_gnn_explainer.py Outdated Show resolved Hide resolved
test/explain/algorithm/test_gnn_explainer.py Show resolved Hide resolved
test/explain/algorithm/test_gnn_explainer.py Outdated Show resolved Hide resolved
Copy link
Member

@wsad1 wsad1 left a comment

Choose a reason for hiding this comment

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

Looks good. Thanks again for building this.
Lets address batch support in another PR because i don't think its too trivial.

torch_geometric/explain/algorithm/gnn_explainer.py Outdated Show resolved Hide resolved
Copy link
Member

@rusty1s rusty1s left a comment

Choose a reason for hiding this comment

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

Thank you! Overall, this looks great. I made some small adjustments (e.g., check_explanation was never called), and there was a bug with masks not being put on the correct device. Fixed now :)

@rusty1s rusty1s merged commit 744fcee into pyg-team:master Nov 25, 2022
@dufourc1 dufourc1 deleted the gnn_explainer_migration branch November 25, 2022 08:50
JakubPietrakIntel pushed a commit to JakubPietrakIntel/pytorch_geometric that referenced this pull request Nov 25, 2022
- Implements the `GNNExplainer` in the new `explain` module.
- Add the argument `node_index` and `target_index` to the
`explain.Explainer` class to allow for explanations of model with
multi-outputs and specify the node.
- Update the examples of the `GNNExplainer` (pyg-team#5924)

Co-authored-by: Jinu Sunil <jinu.sunil@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: rusty1s <matthias.fey@tu-dortmund.de>
Co-authored-by: Abhijit Gupta <avgupta456@gmail.com>
@ZeynepP
Copy link
Contributor

ZeynepP commented Nov 25, 2022

Hi,
a small question : why _get_masks does not return edge_feat_mask ?

@rusty1s
Copy link
Member

rusty1s commented Nov 26, 2022

GNNExplainer does not support edge_feat_mask :(

rusty1s added a commit that referenced this pull request Nov 29, 2022
This PR extends the recent `GNNExplainer` work (#5967) to edge
classification and edge regression (including link prediction). Draft
until the main `GNNExplainer` PR is merged. Progress towards #5925.

**Done**
- Adds tests for the `subgraph` function in `base.py`. Uses
`subgraph([node_idx_1, node_idx_2])` to get the edge k-hop subgraph.
- Implements the edge classification and edge regression tasks.
Currently only supports a single index into the edge_index.
- Adds tests for the edge predictions, similar to the node/graph task
tests.

**Todo**
- Support multiple indexes into the edge_index and/or passing a separate
edge_label_index to explain edges not in the graph (ex. negative link
prediction).
- Create examples to demonstrate edge level explanations. Are there
specific datasets/tasks that would be interesting to look at.

I would like some preliminary feedback before attempting the above two
tasks. I'm also unsure if these additions should be in this PR or a
separate one.

Co-authored-by: Charles Dufour <dufourc115@gmail.com>
Co-authored-by: Charles Dufour <34485907+dufourc1@users.noreply.github.com>
Co-authored-by: Jinu Sunil <jinu.sunil@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: rusty1s <matthias.fey@tu-dortmund.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants