DifferentiationInterface
package | docs |
---|---|
DifferentiationInterface | |
DifferentiationInterfaceTest |
An interface to various automatic differentiation (AD) backends in Julia.
Goal
This package provides a backend-agnostic syntax to differentiate functions of the following types:
- allocating:
f(x) = y
- mutating:
f!(y, x) = nothing
Features
- First and second order operators
- In-place and out-of-place differentiation
- Preparation mechanism (e.g. to create a config or tape)
- Thorough validation on standard inputs and outputs (scalars, vectors, matrices)
- Testing and benchmarking utilities accessible to users with DifferentiationInterfaceTest
Compatibility
We support most of the backends defined by ADTypes.jl:
backend | object |
---|---|
ChainRulesCore.jl | AutoChainRules(ruleconfig) |
Diffractor.jl | AutoDiffractor() |
Enzyme.jl | AutoEnzyme(Enzyme.Forward) , AutoEnzyme(Enzyme.Reverse) |
FiniteDiff.jl | AutoFiniteDiff() |
FiniteDifferences.jl | AutoFiniteDifferences(fdm) |
ForwardDiff.jl | AutoForwardDiff() |
PolyesterForwardDiff.jl | AutoPolyesterForwardDiff(; chunksize) |
ReverseDiff.jl | AutoReverseDiff() |
SparseDiffTools.jl | AutoSparseForwardDiff() , AutoSparseFiniteDiff() |
Tracker.jl | AutoTracker() |
Zygote.jl | AutoZygote() |
We also provide some experimental backends ourselves:
backend | object |
---|---|
FastDifferentiation.jl | AutoFastDifferentiation() , AutoSparseFastDifferentiation() |
Tapir.jl | AutoTapir() |
Installation
Until the package is registered, you need to install it from the GitHub repo:
julia> using Pkg
julia> Pkg.add(
url="https://github.com/gdalle/DifferentiationInterface.jl",
subdir="DifferentiationInterface"
)
Once the package is registered, you will be able to do:
julia> using Pkg
julia> Pkg.add("DifferentiationInterface")
Example
julia> import ForwardDiff
julia> using DifferentiationInterface
julia> backend = AutoForwardDiff();
julia> f(x) = sum(abs2, x);
julia> value_and_gradient(f, backend, [1., 2., 3.])
(14.0, [2.0, 4.0, 6.0])
Related packages
- AbstractDifferentiation.jl is the original inspiration for DifferentiationInterface.jl.
- AutoDiffOperators.jl is an attempt to bridge ADTypes.jl with AbstractDifferentiation.jl.