Skip to content

Commit cb58e8d

Browse files
committed
add code to diagnose ci fails
1 parent da35dcc commit cb58e8d

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

test/cuda/layers.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@ const ACTIVATIONS = [identity, relu, tanh,
2222
sigmoid, exp, softplus,
2323
elu, selu]
2424

25+
function test_approx(x,y; kw...)
26+
pass = isapprox(x,y; kw...)
27+
if !pass
28+
kw = (;kw...)
29+
@show norm(x) norm(y) norm(x-y) kw
30+
end
31+
@test pass
32+
end
33+
2534
function gpu_gradtest(name::String, layers::Vector, x_cpu = nothing, args...; test_cpu = true)
2635
isnothing(x_cpu) && error("Missing input to test the layers against.")
2736
@testset "$name GPU grad tests" begin
@@ -50,10 +59,12 @@ function gpu_gradtest(name::String, layers::Vector, x_cpu = nothing, args...; te
5059

5160
# test
5261
if test_cpu
62+
test_approx(y_gpu, y_cpu, rtol=1f-3, atol=1f-3)
5363
@test y_gpu y_cpu rtol=1f-3 atol=1f-3
5464
if isnothing(xg_cpu)
5565
@test isnothing(xg_gpu)
5666
else
67+
test_approx(Array(xg_gpu), xg_cpu, rtol=1f-3, atol=1f-3)
5768
@test Array(xg_gpu) xg_cpu rtol=1f-3 atol=1f-3
5869
end
5970
end
@@ -64,6 +75,7 @@ function gpu_gradtest(name::String, layers::Vector, x_cpu = nothing, args...; te
6475
else
6576
@test gs_gpu[p_gpu] isa Flux.CUDA.CuArray
6677
if test_cpu
78+
test_approx(Array(gs_gpu[p_gpu]), gs_cpu[p_cpu], rtol=1f-3, atol=1f-3)
6779
@test Array(gs_gpu[p_gpu]) gs_cpu[p_cpu] rtol=1f-3 atol=1f-3
6880
end
6981
end

0 commit comments

Comments
 (0)