Skip to content

Commit 76280d0

Browse files
Work around Julia 1.12 Zygote codegen segfault in CGConv/GMMConv (#695)
* Work around Julia 1.12 Zygote codegen segfault in CGConv/GMMConv A `@warn`/`@info` logging macro inside a Zygote-differentiated branch triggers an LLVM codegen segfault on Julia 1.12 (reported upstream as FluxML/Zygote.jl#1662). `cg_conv` and `gmm_conv` each had a `@warn` in their residual branch, which crashed their gradients and forced the CGConv/GMMConv gradient tests to be disabled (#623). Wrap those `@warn` calls in `ignore_derivatives` so the logging macro stays out of the AD-differentiated code path. The warning still fires in the forward pass and the primal value is unchanged. Re-enable the disabled CGConv/GMMConv test items in both frontends. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * Link PR #695 in changelog entry Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent cc24c19 commit 76280d0

5 files changed

Lines changed: 70 additions & 56 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
1010
and the packages adhere to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
1111
Entries link to the pull request that introduced them.
1212

13+
## GNNlib.jl — Unreleased (towards 1.3.1)
14+
15+
**Fixed**
16+
- Worked around a Julia 1.12 code-generation segfault that crashed `CGConv` and `GMMConv` gradients: the layers' `@warn` (in the residual branch) is now wrapped in `ignore_derivatives` to keep the logging macro out of the AD-differentiated code path. Root cause reported upstream as [FluxML/Zygote.jl#1662]; re-enables the previously disabled `CGConv`/`GMMConv` gradient tests ([#695]).
17+
1318
## GNNLux.jl — Unreleased (towards 0.2.0)
1419

1520
**Added**
@@ -198,3 +203,6 @@ Lux implementations of the graph convolutional, pooling, and temporal layers
198203
[#687]: https://github.com/JuliaGraphs/GraphNeuralNetworks.jl/pull/687
199204
[#690]: https://github.com/JuliaGraphs/GraphNeuralNetworks.jl/pull/690
200205
[#691]: https://github.com/JuliaGraphs/GraphNeuralNetworks.jl/pull/691
206+
[#623]: https://github.com/JuliaGraphs/GraphNeuralNetworks.jl/issues/623
207+
[#695]: https://github.com/JuliaGraphs/GraphNeuralNetworks.jl/pull/695
208+
[FluxML/Zygote.jl#1662]: https://github.com/FluxML/Zygote.jl/issues/1662

‎GNNLux/test/layers/conv.jl‎

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,10 @@
3333
test_lux_layer(rng, l, g, x, sizey=(out_dims,10), container=true)
3434
end
3535

36-
## TODO SEGFAULT on julia 1.12
37-
# @testset "CGConv" begin
38-
# l = CGConv(in_dims => in_dims, residual = true)
39-
# test_lux_layer(rng, l, g, x, outputsize=(in_dims,), container=true)
40-
# end
36+
@testset "CGConv" begin
37+
l = CGConv(in_dims => in_dims, residual = true)
38+
test_lux_layer(rng, l, g, x, outputsize=(in_dims,), container=true)
39+
end
4140

4241
@testset "DConv" begin
4342
l = DConv(in_dims => out_dims, 2)
@@ -126,13 +125,12 @@
126125
test_lux_layer(rng, l, g2, x; outputsize=(n_out,), e, container=true)
127126
end
128127

129-
## TODO SEGFAULT on julia 1.12
130-
# @testset "GMMConv" begin
131-
# ein_dims = 4
132-
# e = randn(rng, Float32, ein_dims, g.num_edges)
133-
# l = GMMConv((in_dims, ein_dims) => out_dims, tanh; K = 2, residual = false)
134-
# test_lux_layer(rng, l, g, x; outputsize=(out_dims,), e)
135-
# end
128+
@testset "GMMConv" begin
129+
ein_dims = 4
130+
e = randn(rng, Float32, ein_dims, g.num_edges)
131+
l = GMMConv((in_dims, ein_dims) => out_dims, tanh; K = 2, residual = false)
132+
test_lux_layer(rng, l, g, x; outputsize=(out_dims,), e)
133+
end
136134

137135
@testset "ResGatedGraphConv" begin
138136
l = ResGatedGraphConv(in_dims => out_dims, tanh)

‎GNNlib/Project.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "GNNlib"
22
uuid = "a6a84749-d869-43f8-aacc-be26a1996e48"
33
authors = ["Carlo Lucibello and contributors"]
4-
version = "1.3.0"
4+
version = "1.3.1-DEV"
55

66
[workspace]
77
projects = ["test", "docs", "../GNNGraphs"]

‎GNNlib/src/layers/conv.jl‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,13 @@ function cg_conv(l, g::AbstractGNNGraph, x, e::Union{Nothing, AbstractMatrix} =
316316
if size(x, 1) == size(m, 1)
317317
m += x
318318
else
319-
@warn "number of output features different from number of input features, residual not applied."
319+
# `@warn` is wrapped in `ignore_derivatives` to keep the logging
320+
# macro out of the AD-differentiated code path: a `@warn`/`@info`
321+
# inside a Zygote-differentiated branch segfaults on Julia 1.12
322+
# (FluxML/Zygote.jl#1662, GraphNeuralNetworks.jl#623).
323+
ignore_derivatives() do
324+
@warn "number of output features different from number of input features, residual not applied."
325+
end
320326
end
321327
end
322328

@@ -393,7 +399,11 @@ function gmm_conv(l, g::GNNGraph, x::AbstractMatrix, e::AbstractMatrix)
393399
if size(x, 1) == size(m, 1)
394400
m += x
395401
else
396-
@warn "Residual not applied : output feature is not equal to input_feature"
402+
# see the note in `cg_conv`: keep `@warn` out of the AD path to
403+
# avoid the Julia 1.12 codegen segfault (FluxML/Zygote.jl#1662).
404+
ignore_derivatives() do
405+
@warn "Residual not applied : output feature is not equal to input_feature"
406+
end
397407
end
398408
end
399409

‎GraphNeuralNetworks/test/layers/conv.jl‎

Lines changed: 39 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -365,24 +365,23 @@ end
365365
end
366366
end
367367

368-
## TODO segfault on julia v1.12
369-
# @testitem "CGConv" setup=[TolSnippet, TestModule] begin
370-
# using .TestModule
368+
@testitem "CGConv" setup=[TolSnippet, TestModule] begin
369+
using .TestModule
371370

372-
# edim = 10
373-
# l = CGConv((D_IN, edim) => D_OUT, tanh, residual = false, bias = true)
374-
# for g in TEST_GRAPHS
375-
# g = GNNGraph(g, edata = rand(Float32, edim, g.num_edges))
376-
# @test size(l(g, g.x, g.e)) == (D_OUT, g.num_nodes)
377-
# test_gradients(l, g, g.x, g.e, rtol = RTOL_HIGH)
378-
# end
379-
380-
# # no edge features
381-
# l1 = CGConv(D_IN => D_OUT, tanh, residual = false, bias = true)
382-
# g1 = TEST_GRAPHS[1]
383-
# @test l1(g1, g1.ndata.x) == l1(g1).ndata.x
384-
# @test l1(g1, g1.ndata.x, nothing) == l1(g1).ndata.x
385-
# end
371+
edim = 10
372+
l = CGConv((D_IN, edim) => D_OUT, tanh, residual = false, bias = true)
373+
for g in TEST_GRAPHS
374+
g = GNNGraph(g, edata = rand(Float32, edim, g.num_edges))
375+
@test size(l(g, g.x, g.e)) == (D_OUT, g.num_nodes)
376+
test_gradients(l, g, g.x, g.e, rtol = RTOL_HIGH)
377+
end
378+
379+
# no edge features
380+
l1 = CGConv(D_IN => D_OUT, tanh, residual = false, bias = true)
381+
g1 = TEST_GRAPHS[1]
382+
@test l1(g1, g1.ndata.x) == l1(g1).ndata.x
383+
@test l1(g1, g1.ndata.x, nothing) == l1(g1).ndata.x
384+
end
386385

387386
# @testitem "CGConv GPU" setup=[TolSnippet, TestModule] tags=[:gpu] begin
388387
# using .TestModule
@@ -458,31 +457,30 @@ end
458457
end
459458
end
460459

461-
## TODO segfault on julia v1.12
462-
# @testitem "GMMConv" setup=[TolSnippet, TestModule] begin
463-
# using .TestModule
464-
# ein_channel = 10
465-
# K = 5
466-
# l = GMMConv((D_IN, ein_channel) => D_OUT, K = K)
467-
# for g in TEST_GRAPHS
468-
# g = GNNGraph(g, edata = rand(Float32, ein_channel, g.num_edges))
469-
# y = l(g, g.x, g.e)
470-
# test_gradients(l, g, g.x, g.e, rtol = RTOL_HIGH)
471-
# end
472-
# end
460+
@testitem "GMMConv" setup=[TolSnippet, TestModule] begin
461+
using .TestModule
462+
ein_channel = 10
463+
K = 5
464+
l = GMMConv((D_IN, ein_channel) => D_OUT, K = K)
465+
for g in TEST_GRAPHS
466+
g = GNNGraph(g, edata = rand(Float32, ein_channel, g.num_edges))
467+
y = l(g, g.x, g.e)
468+
test_gradients(l, g, g.x, g.e, rtol = RTOL_HIGH)
469+
end
470+
end
473471

474-
# @testitem "GMMConv GPU" setup=[TolSnippet, TestModule] tags=[:gpu] begin
475-
# using .TestModule
476-
# ein_channel = 10
477-
# K = 5
478-
# l = GMMConv((D_IN, ein_channel) => D_OUT, K = K)
479-
# for g in TEST_GRAPHS
480-
# g.graph isa AbstractSparseMatrix && continue
481-
# g = GNNGraph(g, edata = rand(Float32, ein_channel, g.num_edges))
482-
# y = l(g, g.x, g.e)
483-
# test_gradients(l, g, g.x, g.e, rtol = RTOL_HIGH, test_gpu = true)
484-
# end
485-
# end
472+
@testitem "GMMConv GPU" setup=[TolSnippet, TestModule] tags=[:gpu] begin
473+
using .TestModule
474+
ein_channel = 10
475+
K = 5
476+
l = GMMConv((D_IN, ein_channel) => D_OUT, K = K)
477+
for g in TEST_GRAPHS
478+
g.graph isa AbstractSparseMatrix && continue
479+
g = GNNGraph(g, edata = rand(Float32, ein_channel, g.num_edges))
480+
y = l(g, g.x, g.e)
481+
test_gradients(l, g, g.x, g.e, rtol = RTOL_HIGH, test_gpu = true)
482+
end
483+
end
486484

487485
@testitem "SGConv" setup=[TolSnippet, TestModule] begin
488486
using .TestModule

0 commit comments

Comments
 (0)