Skip to content

Commit c87360f

Browse files
authored
Pass the edge weights in the GPU w_mul_xj fallback (#718)
* Pass the edge weights in the GPU `w_mul_xj` fallback * Link the changelog entry to #718
1 parent 0970953 commit c87360f

4 files changed

Lines changed: 11 additions & 5 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Entries link to the pull request that introduced them.
2828
## GNNlib.jl — Unreleased (towards 1.4.1)
2929

3030
**Fixed**
31+
- 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]).
3132
- 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]).
3233

3334
## GraphNeuralNetworks.jl — Unreleased (towards 1.1.1)
@@ -245,4 +246,5 @@ Lux implementations of the graph convolutional, pooling, and temporal layers
245246
[#707]: https://github.com/JuliaGraphs/GraphNeuralNetworks.jl/pull/707
246247
[#706]: https://github.com/JuliaGraphs/GraphNeuralNetworks.jl/pull/706
247248
[#722]: https://github.com/JuliaGraphs/GraphNeuralNetworks.jl/pull/722
249+
[#718]: https://github.com/JuliaGraphs/GraphNeuralNetworks.jl/pull/718
248250
[FluxML/Zygote.jl#1662]: https://github.com/FluxML/Zygote.jl/issues/1662

‎GNNlib/ext/GNNlibAMDGPUExt.jl‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module GNNlibAMDGPUExt
33
using AMDGPU: AnyROCMatrix
44
using Random, Statistics, LinearAlgebra
55
using GNNlib: GNNlib, propagate, copy_xj, e_mul_xj, w_mul_xj
6-
using GNNGraphs: GNNGraph, COO_T, SPARSE_T
6+
using GNNGraphs: GNNGraph, COO_T, SPARSE_T, get_edge_weight
77

88
###### PROPAGATE SPECIALIZATIONS ####################
99

@@ -28,7 +28,9 @@ end
2828
## avoid the fast path on gpu until we have better support
2929
function GNNlib.propagate(::typeof(w_mul_xj), g::GNNGraph{<:Union{COO_T, SPARSE_T}}, ::typeof(+),
3030
xi, xj::AnyROCMatrix, e::Nothing)
31-
propagate((xi, xj, e) -> w_mul_xj(xi, xj, e), g, +, xi, xj, e)
31+
# The weights come from the graph here, so they have to be passed on explicitly:
32+
# `w_mul_xj` with `e = nothing` would return unweighted messages.
33+
propagate((xi, xj, e) -> w_mul_xj(xi, xj, e), g, +, xi, xj, get_edge_weight(g))
3234
end
3335

3436
end #module

‎GNNlib/ext/GNNlibCUDAExt.jl‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module GNNlibCUDAExt
33
using CUDA
44
using Random, Statistics, LinearAlgebra
55
using GNNlib: GNNlib, propagate, copy_xj, e_mul_xj, w_mul_xj
6-
using GNNGraphs: GNNGraph, COO_T, SPARSE_T, to_dense, to_sparse, adjacency_matrix
6+
using GNNGraphs: GNNGraph, COO_T, SPARSE_T, to_dense, to_sparse, adjacency_matrix, get_edge_weight
77
using ChainRulesCore: @non_differentiable
88

99
const CUDA_COO_T = Tuple{T, T, V} where {T <: AnyCuArray{<:Integer}, V <: Union{Nothing, AnyCuArray}}
@@ -40,7 +40,9 @@ end
4040
## avoid the fast path on gpu until we have better cuda support
4141
function GNNlib.propagate(::typeof(w_mul_xj), g::GNNGraph{<:COO_T}, ::typeof(+),
4242
xi, xj::AnyCuMatrix, e::Nothing)
43-
propagate((xi, xj, e) -> w_mul_xj(xi, xj, e), g, +, xi, xj, e)
43+
# The weights come from the graph here, so they have to be passed on explicitly:
44+
# `w_mul_xj` with `e = nothing` would return unweighted messages.
45+
propagate((xi, xj, e) -> w_mul_xj(xi, xj, e), g, +, xi, xj, get_edge_weight(g))
4446
end
4547

4648
# function GNNlib.propagate(::typeof(copy_xj), g::GNNGraph, ::typeof(mean), xi, xj::AbstractMatrix, e)

‎GNNlib/test/msgpass.jl‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ end
219219
end
220220
# @show get_graph_type(g) has_isolated_nodes(g)
221221
# broken = get_graph_type(g) == :sparse
222-
broken = true
222+
broken = false
223223
@test test_gradients(
224224
f, g, g.x, w; test_gpu=true, test_grad_f=false
225225
) broken=broken

0 commit comments

Comments
 (0)