Package | Docs |
---|---|
DifferentiationInterface | |
DifferentiationInterfaceTest |
An interface to various automatic differentiation (AD) backends in Julia.
This package provides a unified syntax to differentiate functions, including:
- First- and second-order operators (gradients, Jacobians, Hessians and more)
- In-place and out-of-place differentiation
- Preparation mechanism (e.g. to pre-allocate a cache or record a tape)
- Built-in sparsity handling
- Thorough validation on standard inputs and outputs (numbers, vectors, matrices)
- Testing and benchmarking utilities accessible to users with DifferentiationInterfaceTest
We support the following backends defined by ADTypes.jl:
- ChainRulesCore.jl
- Diffractor.jl (currently broken)
- Enzyme.jl
- FastDifferentiation.jl
- FiniteDiff.jl
- FiniteDifferences.jl
- ForwardDiff.jl
- GTPSA.jl
- Mooncake.jl
- PolyesterForwardDiff.jl
- ReverseDiff.jl
- Symbolics.jl
- Tracker.jl
- Zygote.jl
Note that in some cases, going through DifferentiationInterface.jl might be slower than a direct call to the backend's API. This is mostly true for Enzyme.jl, whose handling of activities and multiple arguments unlocks additional performance. We are working on this challenge, and welcome any suggestions or contributions. Meanwhile, if differentiation fails or takes too long, consider using Enzyme.jl directly.
To install the stable version of the package, run the following code in a Julia REPL:
using Pkg
Pkg.add("DifferentiationInterface")
To install the development version, run this instead:
using Pkg
Pkg.add(
url="https://github.com/JuliaDiff/DifferentiationInterface.jl",
subdir="DifferentiationInterface"
)
using DifferentiationInterface
import ForwardDiff, Enzyme, Zygote # AD backends you want to use
f(x) = sum(abs2, x)
x = [1.0, 2.0]
value_and_gradient(f, AutoForwardDiff(), x) # returns (5.0, [2.0, 4.0]) with ForwardDiff.jl
value_and_gradient(f, AutoEnzyme(), x) # returns (5.0, [2.0, 4.0]) with Enzyme.jl
value_and_gradient(f, AutoZygote(), x) # returns (5.0, [2.0, 4.0]) with Zygote.jl
To improve your performance by up to several orders of magnitude compared to this example, take a look at the tutorial and its section on operator preparation.
Whenever you refer to this package or the ideas it contains, please cite our preprint Sparser, Better, Faster, Stronger: Efficient Automatic Differentiation for Sparse Jacobians and Hessians and DifferentiationInterface.jl's inspiration AbstractDifferentiation.jl.
You can use the provided CITATION.cff
file or the following BibTeX entries:
@misc{hill2025sparserbetterfasterstronger,
title={Sparser, Better, Faster, Stronger: Efficient Automatic Differentiation for Sparse Jacobians and Hessians},
author={Adrian Hill and Guillaume Dalle},
year={2025},
eprint={2501.17737},
archivePrefix={arXiv},
primaryClass={cs.LG},
url={https://arxiv.org/abs/2501.17737},
}
@misc{schäfer2022abstractdifferentiationjlbackendagnosticdifferentiableprogramming,
title={AbstractDifferentiation.jl: Backend-Agnostic Differentiable Programming in Julia},
author={Frank Schäfer and Mohamed Tarek and Lyndon White and Chris Rackauckas},
year={2022},
eprint={2109.12449},
archivePrefix={arXiv},
primaryClass={cs.MS},
url={https://arxiv.org/abs/2109.12449},
}
If you use the software, additionally cite us using the precise Zenodo DOI of the package version you used, or the BibTeX entry below:
@software{dalleDifferentiationInterface2025,
author={Dalle, Guillaume and Hill, Adrian},
title={Differentiation{I}nterface.jl},
year={2024},
publisher={Zenodo},
doi={10.5281/zenodo.11092033},
url={https://doi.org/10.5281/zenodo.11092033},
}