From a205b17e1bf7f3b6c8ce3a7dc22dc6d530405913 Mon Sep 17 00:00:00 2001 From: Simeon Schaub Date: Mon, 21 Dec 2020 21:10:28 +0100 Subject: [PATCH] debug further --- test/zygote.jl | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/test/zygote.jl b/test/zygote.jl index 6f2f9a61b..517c1e682 100644 --- a/test/zygote.jl +++ b/test/zygote.jl @@ -9,6 +9,10 @@ function gradcheck(f, xs...; rtol = 1e-6, atol = 1e-6) #return all(isapprox.(grad_zygote, grad_finite_difference; rtol = rtol, atol = atol)) for (grad_zygote, grad_finite_difference) in zip(grad_zygote, grad_finite_difference) @test isapprox(grad_zygote, grad_finite_difference; rtol = rtol, atol = atol) + if !isapprox(grad_zygote, grad_finite_difference; rtol = rtol, atol = atol) + display(grad_zygote - grad_finite_difference) + println() + end end end @@ -23,11 +27,11 @@ gradtest((x, W, b) -> elu.(W*x .+ b, 2), 5, (2,5), 2) gradtest((x, W, b) -> elu.(W*x .+ b, 2), (5,3), (2,5), 2) # tests for https://github.com/FluxML/Zygote.jl/issues/758 -gradient(xs -> sum(selu.(xs)), [1_000, 10_000]) == ([1.0507009873554805, 1.0507009873554805],) -gradient(x -> selu(x), 1_000) == (1.0507009873554805,) -gradient(xs -> sum(elu.(xs, 2)), [1_000, 10_000]) == ([1., 1.],) -gradient(x -> elu(x, 2), 1_000) == (1.,) -gradient(x -> elu(x, 2), -1) == (2*exp(-1),) +@test gradient(xs -> sum(selu.(xs)), [1_000, 10_000])[1] ≈ [1.0507009873554805, 1.0507009873554805] rtol=1e-8 +@test gradient(x -> selu(x), 1_000) == (1.0507009873554805,) +@test gradient(xs -> sum(elu.(xs, 2)), [1_000, 10_000]) == ([1., 1.],) +@test gradient(x -> elu(x, 2), 1_000) == (1.,) +@test gradient(x -> elu(x, 2), -1) == (2*exp(-1),) gradcheck(x->sum(selu.(x)),[100., 1_000.]) gradcheck(x->sum(elu.(x, 3.5)),[100., 1_000.]) gradcheck(x->sum(elu.(x, 3.5)),[1_000., 10_000.]) # for elu the tests are passing but for selu not, interesting