From 3927b2609ef61821f52427fc26615f416d3c7947 Mon Sep 17 00:00:00 2001 From: Simone Carlo Surace Date: Thu, 29 Oct 2026 21:13:40 +0100 Subject: [PATCH 1/2] Pass the edge weights in the GPU `w_mul_xj` fallback --- CHANGELOG.md | 1 + GNNlib/ext/GNNlibAMDGPUExt.jl | 6 ++++-- GNNlib/ext/GNNlibCUDAExt.jl | 6 ++++-- GNNlib/test/msgpass.jl | 2 +- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 00c82f322..6e6013c26 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ Entries link to the pull request that introduced them. ## GNNlib.jl — Unreleased (towards 1.4.1) **Fixed** +- Fixed `propagate(w_mul_xj, g, +)` ignoring the edge weights on CUDA and AMDGPU: the GPU fallback passed no weights to `w_mul_xj`, so layers using edge weights (e.g. `GCNConv` with `use_edge_weight = true`) computed unweighted messages on the GPU. - Fixed `Enzyme.gradient` failing when differentiating `GCNConv`, `SGConv` and `TAGConv` on `:dense`/`:sparse` adjacency graphs: their adjacency-matrix fallbacks now convert via the Enzyme-differentiable `GNNGraphs._to_coo_graph` instead of the keyword `GNNGraph` constructor. Requires GNNGraphs ≥ 1.5.2 and, for Enzyme, Enzyme ≥ 0.13.197 ([#703]). ## GraphNeuralNetworks.jl — Unreleased (towards 1.1.1) diff --git a/GNNlib/ext/GNNlibAMDGPUExt.jl b/GNNlib/ext/GNNlibAMDGPUExt.jl index 83a4591c4..97f0fa416 100644 --- a/GNNlib/ext/GNNlibAMDGPUExt.jl +++ b/GNNlib/ext/GNNlibAMDGPUExt.jl @@ -3,7 +3,7 @@ module GNNlibAMDGPUExt using AMDGPU: AnyROCMatrix using Random, Statistics, LinearAlgebra using GNNlib: GNNlib, propagate, copy_xj, e_mul_xj, w_mul_xj -using GNNGraphs: GNNGraph, COO_T, SPARSE_T +using GNNGraphs: GNNGraph, COO_T, SPARSE_T, get_edge_weight ###### PROPAGATE SPECIALIZATIONS #################### @@ -28,7 +28,9 @@ end ## avoid the fast path on gpu until we have better support function GNNlib.propagate(::typeof(w_mul_xj), g::GNNGraph{<:Union{COO_T, SPARSE_T}}, ::typeof(+), xi, xj::AnyROCMatrix, e::Nothing) - propagate((xi, xj, e) -> w_mul_xj(xi, xj, e), g, +, xi, xj, e) + # The weights come from the graph here, so they have to be passed on explicitly: + # `w_mul_xj` with `e = nothing` would return unweighted messages. + propagate((xi, xj, e) -> w_mul_xj(xi, xj, e), g, +, xi, xj, get_edge_weight(g)) end end #module diff --git a/GNNlib/ext/GNNlibCUDAExt.jl b/GNNlib/ext/GNNlibCUDAExt.jl index 8a231c768..610a38eb4 100644 --- a/GNNlib/ext/GNNlibCUDAExt.jl +++ b/GNNlib/ext/GNNlibCUDAExt.jl @@ -3,7 +3,7 @@ module GNNlibCUDAExt using CUDA using Random, Statistics, LinearAlgebra using GNNlib: GNNlib, propagate, copy_xj, e_mul_xj, w_mul_xj -using GNNGraphs: GNNGraph, COO_T, SPARSE_T, to_dense, to_sparse, adjacency_matrix +using GNNGraphs: GNNGraph, COO_T, SPARSE_T, to_dense, to_sparse, adjacency_matrix, get_edge_weight using ChainRulesCore: @non_differentiable const CUDA_COO_T = Tuple{T, T, V} where {T <: AnyCuArray{<:Integer}, V <: Union{Nothing, AnyCuArray}} @@ -40,7 +40,9 @@ end ## avoid the fast path on gpu until we have better cuda support function GNNlib.propagate(::typeof(w_mul_xj), g::GNNGraph{<:COO_T}, ::typeof(+), xi, xj::AnyCuMatrix, e::Nothing) - propagate((xi, xj, e) -> w_mul_xj(xi, xj, e), g, +, xi, xj, e) + # The weights come from the graph here, so they have to be passed on explicitly: + # `w_mul_xj` with `e = nothing` would return unweighted messages. + propagate((xi, xj, e) -> w_mul_xj(xi, xj, e), g, +, xi, xj, get_edge_weight(g)) end # function GNNlib.propagate(::typeof(copy_xj), g::GNNGraph, ::typeof(mean), xi, xj::AbstractMatrix, e) diff --git a/GNNlib/test/msgpass.jl b/GNNlib/test/msgpass.jl index 12c207507..33cefc65c 100644 --- a/GNNlib/test/msgpass.jl +++ b/GNNlib/test/msgpass.jl @@ -219,7 +219,7 @@ end end # @show get_graph_type(g) has_isolated_nodes(g) # broken = get_graph_type(g) == :sparse - broken = true + broken = false @test test_gradients( f, g, g.x, w; test_gpu=true, test_grad_f=false ) broken=broken From 01979bd0ad332b7f378cd0ab80847c7ac1f6cd20 Mon Sep 17 00:00:00 2001 From: Simone Carlo Surace Date: Thu, 29 Oct 2026 21:35:53 +0100 Subject: [PATCH 2/2] Link the changelog entry to #718 --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e6013c26..192441ab4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,7 +28,7 @@ Entries link to the pull request that introduced them. ## GNNlib.jl — Unreleased (towards 1.4.1) **Fixed** -- Fixed `propagate(w_mul_xj, g, +)` ignoring the edge weights on CUDA and AMDGPU: the GPU fallback passed no weights to `w_mul_xj`, so layers using edge weights (e.g. `GCNConv` with `use_edge_weight = true`) computed unweighted messages on the GPU. +- Fixed `propagate(w_mul_xj, g, +)` ignoring the edge weights on CUDA and AMDGPU: the GPU fallback passed no weights to `w_mul_xj`, so layers using edge weights (e.g. `GCNConv` with `use_edge_weight = true`) computed unweighted messages on the GPU ([#718]). - Fixed `Enzyme.gradient` failing when differentiating `GCNConv`, `SGConv` and `TAGConv` on `:dense`/`:sparse` adjacency graphs: their adjacency-matrix fallbacks now convert via the Enzyme-differentiable `GNNGraphs._to_coo_graph` instead of the keyword `GNNGraph` constructor. Requires GNNGraphs ≥ 1.5.2 and, for Enzyme, Enzyme ≥ 0.13.197 ([#703]). ## GraphNeuralNetworks.jl — Unreleased (towards 1.1.1) @@ -246,4 +246,5 @@ Lux implementations of the graph convolutional, pooling, and temporal layers [#707]: https://github.com/JuliaGraphs/GraphNeuralNetworks.jl/pull/707 [#706]: https://github.com/JuliaGraphs/GraphNeuralNetworks.jl/pull/706 [#722]: https://github.com/JuliaGraphs/GraphNeuralNetworks.jl/pull/722 +[#718]: https://github.com/JuliaGraphs/GraphNeuralNetworks.jl/pull/718 [FluxML/Zygote.jl#1662]: https://github.com/FluxML/Zygote.jl/issues/1662