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 4, 2022
1 parent a74f86d commit b6a3401
Show file tree
Hide file tree
Showing 2 changed files with 16 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

1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ using Flux: OneHotArray, OneHotMatrix, OneHotVector
using Test
using Random, Statistics, LinearAlgebra
using IterTools: ncycle
using Zygote
using CUDA

Random.seed!(0)
Expand Down

0 comments on commit b6a3401

Please sign in to comment.