Skip to content

Commit

Permalink
second derivative tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mcabbott committed Jan 2, 2022
1 parent a74f86d commit 480833c
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions test/layers/basic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -269,3 +269,18 @@ import Flux: activations
@test_throws DimensionMismatch m(OneHotVector(3, 1000))
end
end

@testset "second derivatives" begin
m1 = Chain(Dense(3,4,tanh; bias=false), Dense(4,2))
@test Zygote.hessian_dual(summ1, [1,2,3]) Zygote.hessian_reverse(summ1, [1,2,3])

# NNlib's softmax gradient writes in-place
m2 = Chain(Dense(3,4,tanh), Dense(4,2), softmax)
@test_broken Zygote.hessian_dual(summ2, [1,2,3]) Zygote.hessian_reverse(summ2, [1,2,3])

# https://github.com/FluxML/NNlib.jl/issues/362
m3 = Chain(Conv((3,), 2 => 3, relu), Dense(2,2))
x3 = cat(Float32[1 2; 3 4; 5 6; 7 8]; dims=3)
@test_broken Zygote.hessian_dual(summ3, x3) Zygote.hessian_reverse(summ3, x3)
end

0 comments on commit 480833c

Please sign in to comment.