|
25 | 25 |
|
26 | 26 | @testitem "TGCNCell" setup=[TemporalConvTestModule, TestModule] begin |
27 | 27 | using .TemporalConvTestModule, .TestModule |
28 | | - |
| 28 | + |
| 29 | + # Mooncake is skipped here: it returns wrong gradients through the cell's |
| 30 | + # sigmoid gates (`Dense(_, sigmoid)`) on a fraction of inputs, so the check is |
| 31 | + # flaky (Zygote and finite differences agree). Upstream Mooncake bug with |
| 32 | + # NNlib.sigmoid: https://github.com/chalk-lab/Mooncake.jl/issues/1257. |
| 33 | + # Reference against Zygote only, matching the other temporal cells. |
| 34 | + ad_backends = [Flux.AutoZygote()] |
| 35 | + |
29 | 36 | # Test with default activation function |
30 | 37 | cell = GraphNeuralNetworks.TGCNCell(in_channel => out_channel) |
31 | 38 | y, h = cell(g, g.x) |
32 | 39 | @test y === h |
33 | 40 | @test size(h) == (out_channel, g.num_nodes) |
34 | 41 | # with no initial state |
35 | | - test_gradients(cell, g, g.x, loss=cell_loss, rtol=RTOL_HIGH) |
| 42 | + test_gradients(cell, g, g.x, loss=cell_loss, rtol=RTOL_HIGH; ad_backends) |
36 | 43 | # with initial state |
37 | | - test_gradients(cell, g, g.x, h, loss=cell_loss, rtol=RTOL_HIGH) |
38 | | - |
| 44 | + test_gradients(cell, g, g.x, h, loss=cell_loss, rtol=RTOL_HIGH; ad_backends) |
| 45 | + |
39 | 46 | # Test with custom activation function |
40 | 47 | custom_activation = tanh |
41 | 48 | cell_custom = GraphNeuralNetworks.TGCNCell(in_channel => out_channel, act = custom_activation) |
|
45 | 52 | # Test that outputs differ when using different activation functions |
46 | 53 | @test !isapprox(y, y_custom, rtol=RTOL_HIGH) |
47 | 54 | # with no initial state |
48 | | - test_gradients(cell_custom, g, g.x, loss=cell_loss, rtol=RTOL_HIGH) |
| 55 | + test_gradients(cell_custom, g, g.x, loss=cell_loss, rtol=RTOL_HIGH; ad_backends) |
49 | 56 | # with initial state |
50 | | - test_gradients(cell_custom, g, g.x, h_custom, loss=cell_loss, rtol=RTOL_HIGH) |
| 57 | + test_gradients(cell_custom, g, g.x, h_custom, loss=cell_loss, rtol=RTOL_HIGH; ad_backends) |
51 | 58 | end |
52 | 59 |
|
53 | 60 | @testitem "TGCN" setup=[TemporalConvTestModule, TestModule] begin |
54 | 61 | using .TemporalConvTestModule, .TestModule |
55 | | - |
| 62 | + |
| 63 | + # Mooncake is skipped here (see the TGCNCell test item and |
| 64 | + # https://github.com/chalk-lab/Mooncake.jl/issues/1257): it returns wrong |
| 65 | + # gradients through the cell's sigmoid gates on some inputs. Zygote only. |
| 66 | + ad_backends = [Flux.AutoZygote()] |
| 67 | + |
56 | 68 | # Test with default activation function |
57 | 69 | layer = TGCN(in_channel => out_channel) |
58 | 70 | x = rand(Float32, in_channel, timesteps, g.num_nodes) |
|
61 | 73 | @test layer isa GNNRecurrence |
62 | 74 | @test size(y) == (out_channel, timesteps, g.num_nodes) |
63 | 75 | # with no initial state |
64 | | - test_gradients(layer, g, x, rtol = RTOL_HIGH) |
| 76 | + test_gradients(layer, g, x, rtol = RTOL_HIGH; ad_backends) |
65 | 77 | # with initial state |
66 | | - test_gradients(layer, g, x, state0, rtol = RTOL_HIGH) |
| 78 | + test_gradients(layer, g, x, state0, rtol = RTOL_HIGH; ad_backends) |
67 | 79 |
|
68 | 80 | # Test with custom activation function |
69 | 81 | custom_activation = tanh |
|
74 | 86 | # Test that outputs differ when using different activation functions |
75 | 87 | @test !isapprox(y, y_custom, rtol = RTOL_HIGH) |
76 | 88 | # with no initial state |
77 | | - test_gradients(layer_custom, g, x, rtol = RTOL_HIGH) |
| 89 | + test_gradients(layer_custom, g, x, rtol = RTOL_HIGH; ad_backends) |
78 | 90 | # with initial state |
79 | | - test_gradients(layer_custom, g, x, state0, rtol = RTOL_HIGH) |
| 91 | + test_gradients(layer_custom, g, x, state0, rtol = RTOL_HIGH; ad_backends) |
80 | 92 |
|
81 | 93 | # interplay with GNNChain |
82 | 94 | model = GNNChain(TGCN(in_channel => out_channel), Dense(out_channel, 1)) |
83 | 95 | y = model(g, x) |
84 | 96 | @test size(y) == (1, timesteps, g.num_nodes) |
85 | | - test_gradients(model, g, x, rtol = RTOL_HIGH, atol = ATOL_LOW) |
| 97 | + test_gradients(model, g, x, rtol = RTOL_HIGH, atol = ATOL_LOW; ad_backends) |
86 | 98 | end |
87 | 99 |
|
88 | 100 | @testitem "GConvLSTMCell" setup=[TemporalConvTestModule, TestModule] begin |
|
0 commit comments