Skip to content

Test GCN edge weight gradients through GNNChain - #738

Closed
DHAKED440 wants to merge 1 commit into
JuliaGraphs:masterfrom
DHAKED440:pr/issue-443-edge-weight-gradient-test
Closed

DHAKED440 wants to merge 1 commit into
JuliaGraphs:masterfrom
DHAKED440:pr/issue-443-edge-weight-gradient-test

Conversation

@DHAKED440

@DHAKED440 DHAKED440 commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary
Adds regression coverage for trainable edge weights in GCNConv when used through GNNChain.
Changes
Adds a test in GraphNeuralNetworks/test/layers/conv.jl that checks:

  • Gradients are finite and nonzero for edge weights and both GCN weight matrices.
  • Changing edge weights changes the model output.
  • Updating edge weights or network parameters changes the output.
    This is a 43-line test-only change. It does not modify package source code or public APIs.
    Tests
    The existing GCNConv test and the new regression test passed: 89/89 tests. git diff --check also passed. The full package test suite was not run.

@CarloLucibello

Copy link
Copy Markdown
Member

Thanks for working on this! I'm closing this in favor of #750, which fixes the underlying bug and adds tests for it. Review notes on this PR:

  1. The test sidesteps the bug reported in Training edge weights as well as neural network #443. Both layers set add_self_loops = false. With the default add_self_loops = true, the edge-weight gradient was nothing, because add_self_loops was marked @non_differentiable and cut the AD path to the weights stored in the graph. Removing add_self_loops = false from this test makes it fail. Make add_self_loops differentiable wrt edge weights #750 makes add_self_loops differentiable.
  2. The gradient checks don't verify the value. Checking type, size, finiteness and "some entry is nonzero" would also pass for a wrong gradient, e.g. one missing the degree-normalization term. Compare against finite differences instead (finitediff_withgradient is exported by TestModule).
  3. The "output changes after an update" checks can't fail. Any nonzero perturbation changes the output, so a gradient with the wrong sign passes too. Checking that the loss decreases would test something.
  4. Only Zygote is exercised. The rest of the suite also runs Mooncake on Julia ≥ 1.12, through test_gradients.
  5. Minor: any(x -> !iszero(x), ...) shadows the node features x. any(!iszero, ...) avoids that.

🧔‍♂️🤖 Assisted by Claude Sonnet 5.5

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