diff --git a/GNNLux/src/layers/conv.jl b/GNNLux/src/layers/conv.jl index 7acc31e57..e0b273eed 100644 --- a/GNNLux/src/layers/conv.jl +++ b/GNNLux/src/layers/conv.jl @@ -906,7 +906,18 @@ function GATConv(ch::Pair{NTuple{2, Int}, Int}, σ = identity; end LuxCore.outputsize(l::GATConv) = (l.concat ? l.channel[2]*l.heads : l.channel[2],) -##TODO: parameterlength + +function LuxCore.parameterlength(l::GATConv) + (_, ein), out = l.channel + n = parameterlength(l.dense_x) + (ein > 0 ? 3out : 2out) * l.heads + if ein > 0 + n += parameterlength(l.dense_e) + end + if l.use_bias + n += l.concat ? out * l.heads : out + end + return n +end function LuxCore.initialparameters(rng::AbstractRNG, l::GATConv) (in, ein), out = l.channel @@ -1062,7 +1073,18 @@ end LuxCore.outputsize(l::GATv2Conv) = (l.concat ? l.channel[2]*l.heads : l.channel[2],) -##TODO: parameterlength + +function LuxCore.parameterlength(l::GATv2Conv) + (_, ein), out = l.channel + n = parameterlength(l.dense_i) + parameterlength(l.dense_j) + out * l.heads + if ein > 0 + n += parameterlength(l.dense_e) + end + if l.use_bias + n += l.concat ? out * l.heads : out + end + return n +end function LuxCore.initialparameters(rng::AbstractRNG, l::GATv2Conv) (in, ein), out = l.channel diff --git a/GNNLux/test/layers/conv.jl b/GNNLux/test/layers/conv.jl index 972c9e372..8681aaa91 100644 --- a/GNNLux/test/layers/conv.jl +++ b/GNNLux/test/layers/conv.jl @@ -235,3 +235,16 @@ end test_lux_layer(rng, l, g, x, outputsize=(out_dims,)) end end + +@testitem "GATConv and GATv2Conv parameterlength" setup=[TestModuleLux] begin + using LuxCore + rng = StableRNG(1234) + + for Layer in (GATConv, GATv2Conv), heads in (1, 2), concat in (true, false), + use_bias in (true, false), ein in (0, 4) + + l = Layer((3, ein) => 5; heads, concat, use_bias, add_self_loops = false) + ps = LuxCore.initialparameters(rng, l) + @test LuxCore.parameterlength(l) == LuxCore.parameterlength(ps) + end +end