@@ -22,6 +22,15 @@ const ACTIVATIONS = [identity, relu, tanh,
22
22
sigmoid, exp, softplus,
23
23
elu, selu]
24
24
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
+
25
34
function gpu_gradtest (name:: String , layers:: Vector , x_cpu = nothing , args... ; test_cpu = true )
26
35
isnothing (x_cpu) && error (" Missing input to test the layers against." )
27
36
@testset " $name GPU grad tests" begin
@@ -50,10 +59,12 @@ function gpu_gradtest(name::String, layers::Vector, x_cpu = nothing, args...; te
50
59
51
60
# test
52
61
if test_cpu
62
+ test_approx (y_gpu, y_cpu, rtol= 1f-3 , atol= 1f-3 )
53
63
@test y_gpu ≈ y_cpu rtol= 1f-3 atol= 1f-3
54
64
if isnothing (xg_cpu)
55
65
@test isnothing (xg_gpu)
56
66
else
67
+ test_approx (Array (xg_gpu), xg_cpu, rtol= 1f-3 , atol= 1f-3 )
57
68
@test Array (xg_gpu) ≈ xg_cpu rtol= 1f-3 atol= 1f-3
58
69
end
59
70
end
@@ -64,6 +75,7 @@ function gpu_gradtest(name::String, layers::Vector, x_cpu = nothing, args...; te
64
75
else
65
76
@test gs_gpu[p_gpu] isa Flux. CUDA. CuArray
66
77
if test_cpu
78
+ test_approx (Array (gs_gpu[p_gpu]), gs_cpu[p_cpu], rtol= 1f-3 , atol= 1f-3 )
67
79
@test Array (gs_gpu[p_gpu]) ≈ gs_cpu[p_cpu] rtol= 1f-3 atol= 1f-3
68
80
end
69
81
end
0 commit comments