|
1 | 1 | @testset "Conv Layers" begin
|
| 2 | + RTOL_LOW = 1e-2 |
| 3 | + RTOL_HIGH = 1e-5 |
| 4 | + |
2 | 5 | in_channel = 3
|
3 | 6 | out_channel = 5
|
4 | 7 | N = 4
|
|
27 | 30 | @testset "GCNConv" begin
|
28 | 31 | l = GCNConv(in_channel => out_channel)
|
29 | 32 | for g in test_graphs
|
30 |
| - test_layer(l, g, rtol=1e-5, outsize=(out_channel, g.num_nodes)) |
| 33 | + test_layer(l, g, rtol=RTOL_HIGH, outsize=(out_channel, g.num_nodes)) |
31 | 34 | end
|
32 | 35 |
|
33 | 36 | l = GCNConv(in_channel => out_channel, tanh, bias=false)
|
34 | 37 | for g in test_graphs
|
35 |
| - test_layer(l, g, rtol=1e-5, outsize=(out_channel, g.num_nodes)) |
| 38 | + test_layer(l, g, rtol=RTOL_HIGH, outsize=(out_channel, g.num_nodes)) |
36 | 39 | end
|
37 | 40 |
|
38 | 41 | l = GCNConv(in_channel => out_channel, add_self_loops=false)
|
39 |
| - test_layer(l, g1, rtol=1e-5, outsize=(out_channel, g1.num_nodes)) |
| 42 | + test_layer(l, g1, rtol=RTOL_HIGH, outsize=(out_channel, g1.num_nodes)) |
40 | 43 |
|
41 | 44 | @testset "edge weights" begin
|
42 | 45 | s = [2,3,1,3,1,2]
|
|
57 | 60 | x = rand(T, 1, 3)
|
58 | 61 | g = GNNGraph((s, t, w), ndata=x, graph_type=GRAPH_T, edata=w)
|
59 | 62 | l = GCNConv(1 => 1, add_self_loops=false, use_edge_weight=true)
|
60 |
| - test_layer(l, g, rtol=1e-5, outsize=(1, g.num_nodes), test_gpu=false) |
| 63 | + test_layer(l, g, rtol=RTOL_HIGH, outsize=(1, g.num_nodes), test_gpu=false) |
61 | 64 | @test gradient(w -> sum(l(g, x, w)), w)[1] isa AbstractVector{T} # redundan test but more esplicit
|
62 | 65 | end
|
63 | 66 | end
|
|
70 | 73 | @test l.k == k
|
71 | 74 | for g in test_graphs
|
72 | 75 | g = add_self_loops(g)
|
73 |
| - test_layer(l, g, rtol=1e-5, test_gpu=false, outsize=(out_channel, g.num_nodes)) |
| 76 | + test_layer(l, g, rtol=RTOL_HIGH, test_gpu=false, outsize=(out_channel, g.num_nodes)) |
74 | 77 | if TEST_GPU
|
75 |
| - @test_broken test_layer(l, g, rtol=1e-5, test_gpu=true, outsize=(out_channel, g.num_nodes)) |
| 78 | + @test_broken test_layer(l, g, rtol=RTOL_HIGH, test_gpu=true, outsize=(out_channel, g.num_nodes)) |
76 | 79 | end
|
77 | 80 | end
|
78 | 81 |
|
|
85 | 88 | @testset "GraphConv" begin
|
86 | 89 | l = GraphConv(in_channel => out_channel)
|
87 | 90 | for g in test_graphs
|
88 |
| - test_layer(l, g, rtol=1e-5, outsize=(out_channel, g.num_nodes)) |
| 91 | + test_layer(l, g, rtol=RTOL_HIGH, outsize=(out_channel, g.num_nodes)) |
89 | 92 | end
|
90 | 93 |
|
91 | 94 | l = GraphConv(in_channel => out_channel, relu, bias=false, aggr=mean)
|
92 | 95 | for g in test_graphs
|
93 |
| - test_layer(l, g, rtol=1e-5, outsize=(out_channel, g.num_nodes)) |
| 96 | + test_layer(l, g, rtol=RTOL_HIGH, outsize=(out_channel, g.num_nodes)) |
94 | 97 | end
|
95 | 98 |
|
96 | 99 | @testset "bias=false" begin
|
|
104 | 107 | for heads in (1, 2), concat in (true, false)
|
105 | 108 | l = GATConv(in_channel => out_channel; heads, concat)
|
106 | 109 | for g in test_graphs
|
107 |
| - test_layer(l, g, rtol=1e-3, |
| 110 | + test_layer(l, g, rtol=RTOL_LOW, |
108 | 111 | outsize=(concat ? heads*out_channel : out_channel, g.num_nodes))
|
109 | 112 | end
|
110 | 113 | end
|
|
113 | 116 | ein = 3
|
114 | 117 | l = GATConv((in_channel, ein) => out_channel, add_self_loops=false)
|
115 | 118 | g = GNNGraph(g1, edata=rand(T, ein, g1.num_edges))
|
116 |
| - test_layer(l, g, rtol=1e-3, outsize=(out_channel, g.num_nodes)) |
| 119 | + test_layer(l, g, rtol=RTOL_LOW, outsize=(out_channel, g.num_nodes)) |
117 | 120 | end
|
118 | 121 |
|
119 | 122 | @testset "num params" begin
|
|
131 | 134 | for heads in (1, 2), concat in (true, false)
|
132 | 135 | l = GATv2Conv(in_channel => out_channel, tanh; heads, concat)
|
133 | 136 | for g in test_graphs
|
134 |
| - test_layer(l, g, rtol=1e-3, |
| 137 | + test_layer(l, g, rtol=RTOL_LOW, |
135 | 138 | outsize=(concat ? heads*out_channel : out_channel, g.num_nodes))
|
136 | 139 | end
|
137 | 140 | end
|
|
140 | 143 | ein = 3
|
141 | 144 | l = GATv2Conv((in_channel, ein) => out_channel, add_self_loops=false)
|
142 | 145 | g = GNNGraph(g1, edata=rand(T, ein, g1.num_edges))
|
143 |
| - test_layer(l, g, rtol=1e-3, outsize=(out_channel, g.num_nodes)) |
| 146 | + test_layer(l, g, rtol=RTOL_LOW, outsize=(out_channel, g.num_nodes)) |
144 | 147 | end
|
145 | 148 |
|
146 | 149 | @testset "num params" begin
|
|
167 | 170 | @test size(l.weight) == (out_channel, out_channel, num_layers)
|
168 | 171 |
|
169 | 172 | for g in test_graphs
|
170 |
| - test_layer(l, g, rtol=1e-5, outsize=(out_channel, g.num_nodes)) |
| 173 | + test_layer(l, g, rtol=RTOL_HIGH, outsize=(out_channel, g.num_nodes)) |
171 | 174 | end
|
172 | 175 | end
|
173 | 176 |
|
174 | 177 | @testset "EdgeConv" begin
|
175 | 178 | l = EdgeConv(Dense(2*in_channel, out_channel), aggr=+)
|
176 | 179 | for g in test_graphs
|
177 |
| - test_layer(l, g, rtol=1e-5, outsize=(out_channel, g.num_nodes)) |
| 180 | + test_layer(l, g, rtol=RTOL_HIGH, outsize=(out_channel, g.num_nodes)) |
178 | 181 | end
|
179 | 182 | end
|
180 | 183 |
|
|
183 | 186 |
|
184 | 187 | l = GINConv(nn, 0.01f0, aggr=mean)
|
185 | 188 | for g in test_graphs
|
186 |
| - test_layer(l, g, rtol=1e-5, outsize=(out_channel, g.num_nodes)) |
| 189 | + test_layer(l, g, rtol=RTOL_HIGH, outsize=(out_channel, g.num_nodes)) |
187 | 190 | end
|
188 | 191 |
|
189 | 192 | @test !in(:eps, Flux.trainable(l))
|
|
196 | 199 | l = NNConv(in_channel => out_channel, nn, tanh, bias=true, aggr=+)
|
197 | 200 | for g in test_graphs
|
198 | 201 | g = GNNGraph(g, edata=rand(T, edim, g.num_edges))
|
199 |
| - test_layer(l, g, rtol=1e-5, outsize=(out_channel, g.num_nodes)) |
| 202 | + test_layer(l, g, rtol=RTOL_HIGH, outsize=(out_channel, g.num_nodes)) |
200 | 203 | end
|
201 | 204 | end
|
202 | 205 |
|
|
206 | 209 |
|
207 | 210 | l = SAGEConv(in_channel => out_channel, tanh, bias=false, aggr=+)
|
208 | 211 | for g in test_graphs
|
209 |
| - test_layer(l, g, rtol=1e-5, outsize=(out_channel, g.num_nodes)) |
| 212 | + test_layer(l, g, rtol=RTOL_HIGH, outsize=(out_channel, g.num_nodes)) |
210 | 213 | end
|
211 | 214 | end
|
212 | 215 |
|
213 | 216 |
|
214 | 217 | @testset "ResGatedGraphConv" begin
|
215 | 218 | l = ResGatedGraphConv(in_channel => out_channel, tanh, bias=true)
|
216 | 219 | for g in test_graphs
|
217 |
| - test_layer(l, g, rtol=1e-5, outsize=(out_channel, g.num_nodes)) |
| 220 | + test_layer(l, g, rtol=RTOL_HIGH, outsize=(out_channel, g.num_nodes)) |
218 | 221 | end
|
219 | 222 | end
|
220 | 223 |
|
|
224 | 227 | l = CGConv((in_channel, edim) => out_channel, tanh, residual=false, bias=true)
|
225 | 228 | for g in test_graphs
|
226 | 229 | g = GNNGraph(g, edata=rand(T, edim, g.num_edges))
|
227 |
| - test_layer(l, g, rtol=1e-5, outsize=(out_channel, g.num_nodes)) |
| 230 | + test_layer(l, g, rtol=RTOL_HIGH, outsize=(out_channel, g.num_nodes)) |
228 | 231 | end
|
229 | 232 |
|
230 | 233 | # no edge features
|
|
238 | 241 | l = AGNNConv()
|
239 | 242 | @test l.β == [1f0]
|
240 | 243 | for g in test_graphs
|
241 |
| - test_layer(l, g, rtol=1e-5, outsize=(in_channel, g.num_nodes)) |
| 244 | + test_layer(l, g, rtol=RTOL_HIGH, outsize=(in_channel, g.num_nodes)) |
242 | 245 | end
|
243 | 246 | end
|
244 | 247 |
|
245 | 248 | @testset "MEGNetConv" begin
|
246 | 249 | l = MEGNetConv(in_channel => out_channel, aggr=+)
|
247 | 250 | for g in test_graphs
|
248 | 251 | g = GNNGraph(g, edata=rand(T, in_channel, g.num_edges))
|
249 |
| - test_layer(l, g, rtol=1e-3, |
| 252 | + test_layer(l, g, rtol=RTOL_LOW, |
250 | 253 | outtype=:node_edge,
|
251 | 254 | outsize=((out_channel, g.num_nodes), (out_channel, g.num_edges)))
|
252 | 255 | end
|
|
0 commit comments