Repository navigation
Make add_self_loops differentiable wrt edge weights - #750
Merged
Merged
Conversation
`add_self_loops` was marked non-differentiable, so the gradient of edge weights stored in the graph was silently dropped by layers that add self loops by default (GCNConv, SGConv, TAGConv with `use_edge_weight = true`), for both Zygote and Mooncake. Only the edge index computation is now excluded from AD. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
add_self_loopswas marked@non_differentiable(and had a matching@zero_derivativerule in the Mooncake extension). As a result, layers that add self loops by default (GCNConv,SGConv,TAGConvwithuse_edge_weight = true) silently returned anothinggradient for edge weights stored in the graph, with both Zygote and Mooncake.Now only the edge-index computation (
_add_self_loops_index) is excluded from AD, so gradients reach the edge weights of COO graphs and the adjacency matrix of dense/sparse graphs. For Mooncake,A + Ion adjacency-matrix graphs moves into a helper with its own rules (zero derivative for integer matrices, identity pullback for dense float matrices), since Mooncake can't trace the GPU kernel. TheGNNHeteroGraphmethod stays non-differentiable for now.User-facing change (GNNGraphs):
add_self_loopsis differentiable w.r.t. edge weights, so edge weights stored in the graph can be trained throughGCNConv,SGConvandTAGConvwith the defaultadd_self_loops = true.Tests compare Zygote and Mooncake against finite differences for the three layers, and check
add_self_loopsdirectly on COO and dense graphs, CPU and CUDA. The new tests fail onmaster.Supersedes #738. Related to #443.
🧔♂️🤖 Assisted by Claude Sonnet 5.5