Skip to content
auto-differentiationPublic

About

The fastest automatic differentiation library for C++, with Python bindings. Forward, adjoint and higher-order derivatives, checkpointing, Eigen support and JIT. Reproducible benchmarks against CppAD, Adept and autodiff.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

437 stars

Watchers

11 watching

Forks

XAD

XAD: The fastest automatic differentiation library for C++

Exact derivatives of your existing C++ code, in forward, adjoint and higher-order mode, with low runtime overhead and a small memory footprint. Python bindings: pip install xad.

For Monte Carlo and other repetitive workloads, XAD also provides a JIT backend interface for record-once / replay-many execution.

Documentation · Install · Samples · Benchmarks · Python · Discussions

Download Build Status Coverage PyPI vcpkg DOI License: AGPL-3.0 or commercial

Example

Every derivative of a function in one adjoint sweep:

#include <XAD/XAD.hpp>
#include <iostream>

using mode = xad::adj<double>;   // adjoint (reverse) mode
using AD = mode::active_type;

template <class T>
T f(T x, T y) { return x * sin(y) + exp(x * y); }   // your code, unchanged

int main() {
    mode::tape_type tape;
    AD x = 1.3, y = 5.2;
    tape.registerInput(x);
    tape.registerInput(y);
    tape.newRecording();
    AD z = f(x, y);
    tape.registerOutput(z);
    derivative(z) = 1.0;
    tape.computeAdjoints();       // every input derivative in one sweep
    std::cout << "dz/dx = " << derivative(x) << ", dz/dy = " << derivative(y) << "\n";
}

Install

With vcpkg:

vcpkg install xad
find_package(XAD CONFIG REQUIRED)
target_link_libraries(my_app PRIVATE XAD::xad)

With CMake, straight from GitHub:

include(FetchContent)
FetchContent_Declare(XAD GIT_REPOSITORY https://github.com/auto-differentiation/xad.git GIT_TAG v2.1.0)
FetchContent_MakeAvailable(XAD)
target_link_libraries(my_app PRIVATE XAD::xad)

Or build from source:

git clone https://github.com/auto-differentiation/xad.git
cmake -S xad -B xad/build
cmake --build xad/build

Python: pip install xad. More in the Installation Guide and the Tutorials.

Benchmarks

Compared against CppAD, Adept 2, autodiff, and finite differences on quant-finance workloads. We are rebuilding the suite with new workloads, pinned library versions and gradient checks, run on GitHub CI; new results in November 2026.

Key Features

  • Forward & Reverse (Adjoint) Mode: Supports any order using operator overloading.
  • Vector mode: Compute multiple derivatives at once.
  • Checkpointing Support: Efficient tape memory management for large-scale applications.
  • External Function Interface: Seamlessly connect with external libraries.
  • Eigen support: Works with the popular linear algebra library Eigen.
  • JIT Backend Support (optional): Infrastructure for pluggable JIT backends, enabling record-once/replay-many workflows. See samples/jit_tutorial.

Ecosystem

Repository Description
xad-py Python bindings for XAD
QuantLibAAD Full QuantLib integration — compute all Greeks at once, up to 3 orders of magnitude faster than bump-and-reval
QuantLib-Risks-Py QuantLib risks from Python
xad-codegen Native code generation backend — maximum throughput (commercial)
AAD Training Hands-on AAD training for quants and quant developers - delivered to dozens of tier 1 banks and financial services firms

Documentation

Full documentation, including API reference and usage examples, is available at: https://auto-differentiation.github.io/

Contributing

Contributions are welcome. Please see the Contributing Guide for details, and feel free to start a discussion in our GitHub Discussions.

New here? Pick a good first issue. Each one is small, self-contained and comes with a clear task.

Thanks to everyone who has contributed:

Contributors

Found a Bug?

Please report bugs and issues via the GitHub Issue Tracker.

License

XAD is free under the AGPL-3.0 (version 3 only) for evaluation, research and open-source use. For production use without AGPL obligations, a commercial subscription is available.

About

The fastest automatic differentiation library for C++, with Python bindings. Forward, adjoint and higher-order derivatives, checkpointing, Eigen support and JIT. Reproducible benchmarks against CppAD, Adept and autodiff.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

437 stars

Watchers

11 watching

Forks

Releases

Used by

Contributors

Languages