gdalle / DifferentiationInterface.jl

An interface to various automatic differentiation backends in Julia.
https://gdalle.github.io/DifferentiationInterface.jl/DifferentiationInterface
MIT License
145 stars 13 forks source link

Why does FiniteDiff over FiniteDiff HVP fail? #78

Open gdalle opened 3 months ago

gdalle commented 3 months ago

Does it have to do with the finite difference mode chosen by default?

gdalle commented 3 weeks ago

Non deterministic outputs:

julia> using DifferentiationInterface

julia> import FiniteDiff

julia> backend = AutoFiniteDiff()

julia> f(x) = sum(abs2, x)
f (generic function with 1 method)

julia> hessian(f, backend, rand(3))
3×3 LinearAlgebra.Symmetric{Float64, Matrix{Float64}}:
 2.0         1.86265e-9  0.0
 1.86265e-9  2.0         0.0
 0.0         0.0         2.0

julia> hvp(f, backend, rand(3), ones(3))
3-element Vector{Float64}:
 2.5
 2.0
 2.0

julia> hvp(f, backend, rand(3), ones(3))
3-element Vector{Float64}:
 1.0
 1.0
 1.0

julia> hvp(f, backend, rand(3), ones(3))
3-element Vector{Float64}:
 1.5
 2.0
 1.5