Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions GNNLux/src/layers/conv.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions GNNLux/test/layers/conv.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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