From fba8acc13b62f785bd213d63b7dfe24f25a0d0f6 Mon Sep 17 00:00:00 2001 From: parth-patel010 Date: Wed, 4 Nov 2026 20:43:31 +0530 Subject: [PATCH] Return the NNConv state with the nn wrapper in GNNLux --- CHANGELOG.md | 2 ++ GNNLux/src/layers/conv.jl | 2 +- GNNLux/test/layers/conv.jl | 11 +++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 192441ab4..610b89f19 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ Entries link to the pull request that introduced them. **Fixed** - `GNNChain` now returns its state with the same structure it receives, `(; layers = (; layer_1, ...))`, as the Lux layer interface requires. It previously returned the per-layer states without the `layers` wrapper, so feeding the returned state back into the chain (as `Lux.Training.single_train_step!` does) failed with a `FieldError`. This is breaking for code that worked around the bug by re-wrapping the state as `(; layers = st)`, as the docs examples did: drop the wrapper. +- `NNConv` now returns its state as `(; nn = ...)`, the same structure it receives. It previously returned the inner network's state without the `nn` wrapper, so passing the returned state back into the layer (e.g. on the second step of `Lux.Training.single_train_step!`) failed with a `FieldError` ([#728]). ## GNNlib.jl — Unreleased (towards 1.4.1) @@ -247,4 +248,5 @@ Lux implementations of the graph convolutional, pooling, and temporal layers [#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 +[#728]: https://github.com/JuliaGraphs/GraphNeuralNetworks.jl/pull/728 [FluxML/Zygote.jl#1662]: https://github.com/FluxML/Zygote.jl/issues/1662 diff --git a/GNNLux/src/layers/conv.jl b/GNNLux/src/layers/conv.jl index f67e54381..236b9dfc6 100644 --- a/GNNLux/src/layers/conv.jl +++ b/GNNLux/src/layers/conv.jl @@ -1670,7 +1670,7 @@ function (l::NNConv)(g, x, e, ps, st) nn = StatefulLuxLayer{true}(l.nn, ps.nn, st.nn) m = (; nn, l.aggr, ps.weight, bias = _getbias(ps), l.σ) y = GNNlib.nn_conv(m, g, x, e) - stnew = _getstate(nn) + stnew = (; nn = _getstate(nn)) return y, stnew end diff --git a/GNNLux/test/layers/conv.jl b/GNNLux/test/layers/conv.jl index 5bfb01825..e9a93cfb6 100644 --- a/GNNLux/test/layers/conv.jl +++ b/GNNLux/test/layers/conv.jl @@ -123,6 +123,17 @@ x = randn(Float32, n_in, g2.num_nodes) e = randn(Float32, n_in_edge, g2.num_edges) test_lux_layer(rng, l, g2, x; outputsize=(n_out,), e, container=true) + + # The returned state has the same structure as the input state, + # so it can be fed back into the layer (as in a training loop). + nn = Chain(Dense(n_in_edge => n_out * n_in), BatchNorm(n_out * n_in)) + l = NNConv(n_in => n_out, nn, tanh, aggr = +) + ps, st = LuxCore.setup(rng, l) + y, st′ = l(g2, x, e, ps, st) + @test typeof(st′) == typeof(st) + @test st′.nn.layer_2.running_mean != st.nn.layer_2.running_mean + y′, st″ = l(g2, x, e, ps, st′) + @test typeof(st″) == typeof(st) end @testset "GMMConv" begin