Skip to content

Conversation

@jeffguy
Copy link
Contributor

@jeffguy jeffguy commented May 7, 2025

Here's an example test program

from torch_geometric.explain.algorithm.gnn_explainer import GNNExplainer
summing_explainer = GNNExplainer(edge_reduction='sum')
multiplying_explainer = GNNExplainer(edge_reduction='prod')
print(summing_explainer.coeffs['edge_reduction'])

Without the bugfix, this prints "prod" even though it's printing the edge_reduction for the summing_explainer. This is because GNNExplainer.coeffs is a class-level variable. When we instantiate multiplying_explainer, it overwrites GNNExplainer.coeffs['edge_reduction'] which is the same dictionary item summing_explainer uses.

The bugfix renames GNNExplainer.coeffs to GNNExplainer.default_coeffs, and each GNNExplainer instance gets its own copy of the coeffs dict, so they don't step on one another.

@rusty1s rusty1s merged commit ee2b33d into pyg-team:master May 20, 2025
3 checks passed
chrisn-pik pushed a commit to chrisn-pik/pytorch_geometric that referenced this pull request Jun 30, 2025
…team#10257)

Here's an example test program
``` python
from torch_geometric.explain.algorithm.gnn_explainer import GNNExplainer
summing_explainer = GNNExplainer(edge_reduction='sum')
multiplying_explainer = GNNExplainer(edge_reduction='prod')
print(summing_explainer.coeffs['edge_reduction'])
```

Without the bugfix, this prints "prod" even though it's printing the
edge_reduction for the **summing_explainer**. This is because
`GNNExplainer.coeffs` is a class-level variable. When we instantiate
multiplying_explainer, it overwrites
GNNExplainer.coeffs['edge_reduction'] which is the same dictionary item
summing_explainer uses.

The bugfix renames GNNExplainer.coeffs to GNNExplainer.default_coeffs,
and each GNNExplainer instance gets its own copy of the coeffs dict, so
they don't step on one another.
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.

2 participants