diff --git a/GNNLux/Project.toml b/GNNLux/Project.toml index fce31f55d..8ec27b7b1 100644 --- a/GNNLux/Project.toml +++ b/GNNLux/Project.toml @@ -1,6 +1,6 @@ name = "GNNLux" uuid = "e8545f4d-a905-48ac-a8c4-ca114b98986d" -version = "0.3.1-DEV" +version = "0.3.2-DEV" authors = ["Carlo Lucibello and contributors"] [workspace] diff --git a/GNNLux/src/layers/conv.jl b/GNNLux/src/layers/conv.jl index 7acc31e57..7a7f59a9d 100644 --- a/GNNLux/src/layers/conv.jl +++ b/GNNLux/src/layers/conv.jl @@ -1487,7 +1487,7 @@ function GMMConv(ch::Pair{NTuple{2, Int}, Int}, init_weight = glorot_uniform, init_bias = zeros32, use_bias = true) - dense_x = Dense(ch[1][1] => ch[2] * K, use_bias = false) + dense_x = Dense(ch[1][1] => ch[2] * K; use_bias = false, init_weight) return GMMConv(σ, ch, K, residual, init_weight, init_bias, use_bias, dense_x) end diff --git a/GNNLux/test/layers/conv.jl b/GNNLux/test/layers/conv.jl index 972c9e372..d9dd1bf5f 100644 --- a/GNNLux/test/layers/conv.jl +++ b/GNNLux/test/layers/conv.jl @@ -16,6 +16,22 @@ @test all(isone, ps.dense_e.weight) end +@testitem "GMMConv weight initialization" begin + using Lux, Random + + init_weight(rng::AbstractRNG, dims...) = ones(Float32, dims...) + l = GMMConv((4, 2) => 3; K = 2, init_weight) + ps, _ = Lux.setup(Xoshiro(0), l) + @test all(isone, ps.mu) + @test all(isone, ps.sigma_inv) + @test all(isone, ps.dense_x.weight) + + default_l = GMMConv((4, 2) => 3; K = 2) + default_ps, _ = Lux.setup(Xoshiro(0), default_l) + @test size(default_ps.dense_x.weight) == (6, 4) + @test !all(isone, default_ps.dense_x.weight) +end + @testitem "layers/conv" setup=[TestModuleLux] begin using .TestModuleLux diff --git a/GraphNeuralNetworks/Project.toml b/GraphNeuralNetworks/Project.toml index c5c6b1139..5cb4a5a1e 100644 --- a/GraphNeuralNetworks/Project.toml +++ b/GraphNeuralNetworks/Project.toml @@ -1,7 +1,7 @@ name = "GraphNeuralNetworks" uuid = "cffab07f-9bc2-4db1-8861-388f63bf7694" authors = ["Carlo Lucibello and contributors"] -version = "1.2.0-DEV" +version = "1.2.1-DEV" [workspace] projects = ["test", "docs"] diff --git a/GraphNeuralNetworks/src/layers/conv.jl b/GraphNeuralNetworks/src/layers/conv.jl index 7e5d190e5..def511a53 100644 --- a/GraphNeuralNetworks/src/layers/conv.jl +++ b/GraphNeuralNetworks/src/layers/conv.jl @@ -333,8 +333,8 @@ function GATConv(ch::Pair{NTuple{2, Int}, Int}, σ = identity; @assert ein==0 "Using edge features and setting add_self_loops=true at the same time is not yet supported." end - dense_x = Dense(in, out * heads, bias = false) - dense_e = ein > 0 ? Dense(ein, out * heads, bias = false) : nothing + dense_x = Dense(in, out * heads; bias = false, init) + dense_e = ein > 0 ? Dense(ein, out * heads; bias = false, init) : nothing b = bias ? Flux.create_bias(dense_x.weight, true, concat ? out * heads : out) : false a = init(ein > 0 ? 3out : 2out, heads) negative_slope = convert(Float32, negative_slope) @@ -1198,7 +1198,7 @@ function GMMConv(ch::Pair{NTuple{2, Int}, Int}, mu = init(ein, K) sigma_inv = init(ein, K) b = bias ? Flux.create_bias(mu, true, out) : false - dense_x = Dense(nin, out * K, bias = false) + dense_x = Dense(nin, out * K; bias = false, init) GMMConv(mu, sigma_inv, b, σ, ch, K, dense_x, residual) end diff --git a/GraphNeuralNetworks/test/layers/conv.jl b/GraphNeuralNetworks/test/layers/conv.jl index c09fb70ba..466cc7ecb 100644 --- a/GraphNeuralNetworks/test/layers/conv.jl +++ b/GraphNeuralNetworks/test/layers/conv.jl @@ -207,6 +207,24 @@ end end end +@testitem "GATConv custom initializer" setup=[TestModule] begin + using .TestModule + l = GATConv(4 => 3; init = Flux.ones32) + @test all(isone, l.a) + @test all(isone, l.dense_x.weight) + + l_edge = GATConv((4, 2) => 3; add_self_loops = false, init = Flux.ones32) + @test all(isone, l_edge.a) + @test all(isone, l_edge.dense_x.weight) + @test all(isone, l_edge.dense_e.weight) + + default_l = GATConv((4, 2) => 3; heads = 2, add_self_loops = false) + @test size(default_l.dense_x.weight) == (6, 4) + @test size(default_l.dense_e.weight) == (6, 2) + @test !all(isone, default_l.dense_x.weight) + @test !all(isone, default_l.dense_e.weight) +end + @testitem "GATConv GPU" setup=[TolSnippet, TestModule] tags=[:gpu] begin using .TestModule for heads in (1, 2), concat in (true, false) @@ -555,6 +573,18 @@ end end end +@testitem "GMMConv custom initializer" setup=[TestModule] begin + using .TestModule + l = GMMConv((4, 2) => 3; K = 2, init = Flux.ones32) + @test all(isone, l.mu) + @test all(isone, l.sigma_inv) + @test all(isone, l.dense_x.weight) + + default_l = GMMConv((4, 2) => 3; K = 2) + @test size(default_l.dense_x.weight) == (6, 4) + @test !all(isone, default_l.dense_x.weight) +end + @testitem "GMMConv GPU" setup=[TolSnippet, TestModule] tags=[:gpu] begin using .TestModule ein_channel = 10