Automatic differentiation is the algorithmic backbone of modern deep learning, computing exact gradients by applying the chain rule to elementary arithmetic operations within a program's execution trace. Unlike numerical differentiation, it introduces no truncation error, and unlike symbolic differentiation, it avoids expression swell by operating on intermediate values rather than mathematical formulas.
Glossary
Automatic Differentiation

What is Automatic Differentiation?
Automatic differentiation (AD) is a family of techniques for numerically evaluating the exact derivative of a function specified by a computer program, distinct from both symbolic differentiation and numerical approximation.
AD operates in two primary modes: forward mode, which propagates derivatives from inputs to outputs and is efficient for functions with few inputs, and reverse mode (backpropagation), which propagates adjoints from outputs to inputs and is optimal for scalar-valued functions with many parameters—precisely the scenario encountered when training neural network potentials on forces and energies.
Key Characteristics of Automatic Differentiation
Automatic differentiation (AD) is the algorithmic workhorse that computes exact derivatives of arbitrary computer functions, enabling the training of neural network potentials on quantum mechanical forces and energies without manual derivation or numerical approximation errors.
Forward-Mode AD
Computes derivatives by propagating tangent values alongside the primal computation from inputs to outputs. For a function with n inputs and m outputs, forward mode requires n passes to compute a full Jacobian.
- Mechanism: Dual numbers carry both value and derivative component through each operation
- Efficiency: Ideal when
n < m(few inputs, many outputs) - Use case: Computing directional derivatives or Jacobian-vector products for sensitivity analysis in molecular property prediction
- Memory cost: Proportional to the number of operations, not the number of inputs
Reverse-Mode AD (Backpropagation)
Computes derivatives by propagating adjoint values from outputs backward through the computation graph to inputs. This is the algorithm underlying backpropagation in deep learning frameworks like PyTorch and JAX.
- Mechanism: Records a computational graph (tape) during forward pass, then traverses it in reverse
- Efficiency: Ideal when
n >> m(many inputs, few outputs) — exactly the case for neural network potentials where millions of parameters map to a single scalar energy - Memory cost: Must store all intermediate activations, leading to the checkpointing trade-off in large molecular dynamics simulations
- Gradient of energy: Computes forces on all atoms in a single backward pass
Computational Graph Construction
AD operates on a directed acyclic graph (DAG) where nodes represent variables and edges represent functional dependencies. Each elementary operation (addition, multiplication, sin, exp) has a known derivative rule.
- Dynamic graphs: PyTorch builds the graph on-the-fly during execution, enabling flexible control flow in equivariant neural networks
- Static graphs: TensorFlow compiles the graph before execution, enabling aggressive operator fusion and memory optimization
- Tracing vs. source transformation: Operator overloading intercepts each operation at runtime, while source-to-source AD rewrites the program before execution
- Custom gradients: Users can register hand-derived derivatives for operations like spherical harmonics where automatic rules may be suboptimal
Exact Derivatives vs. Numerical Approximation
Unlike numerical differentiation (finite differences) which introduces truncation and round-off errors, AD computes derivatives to machine precision by applying the chain rule to elementary operations.
- Numerical differentiation error:
f'(x) ≈ [f(x+h) - f(x)]/hsuffers from O(h) truncation error and catastrophic cancellation as h → 0 - Symbolic differentiation: Produces exact expressions but suffers from expression swell — the derivative formula can be exponentially larger than the original function
- AD advantage: Delivers exact derivatives with only a small constant factor overhead (typically 2-5x the original function cost)
- Critical for force matching: Training neural network potentials requires accurate forces; numerical noise in gradients would corrupt the learned potential energy surface
Checkpointing and Memory Management
Reverse-mode AD stores all intermediate values during the forward pass, creating a memory bottleneck for deep networks and long molecular dynamics trajectories. Gradient checkpointing trades computation for memory.
- Checkpointing strategy: Discard intermediate activations, then recompute them on-demand during the backward pass from stored checkpoints
- Optimal schedule: The binomial checkpointing algorithm achieves O(log n) memory with O(n log n) recomputation
- Application: Training equivariant neural networks on large molecular systems where storing per-atom features for thousands of atoms exceeds GPU memory
- JAX's approach: Functional transforms like
jax.checkpointautomatically apply checkpointing to arbitrary functions
Higher-Order Derivatives
AD can be applied recursively to compute Hessians (second derivatives) and higher-order tensors required for vibrational analysis and transition state optimization in quantum chemistry.
- Forward-over-reverse: Combine forward and reverse modes to efficiently compute Hessian-vector products without materializing the full Hessian matrix
- Application: Computing harmonic vibrational frequencies from a neural network potential by differentiating the energy gradient
- Force constants: The Hessian of the potential energy with respect to atomic coordinates yields the force constant matrix for normal mode analysis
- Framework support: JAX provides
jax.hessian, PyTorch providestorch.autograd.functional.hessian
Automatic Differentiation vs. Other Methods
A comparison of automatic differentiation with numerical and symbolic differentiation for computing gradients in neural network potentials and quantum chemistry machine learning.
| Feature | Automatic Differentiation | Numerical Differentiation | Symbolic Differentiation |
|---|---|---|---|
Computational complexity for gradient of scalar function with n inputs | O(1) cost per gradient evaluation (forward mode) or O(n) for reverse mode | O(n) function evaluations minimum | O(1) evaluation but expression size can grow exponentially |
Numerical precision | Machine precision (no truncation error) | Subject to truncation and round-off errors; typically 10^-5 to 10^-8 | Exact arithmetic (no approximation error) |
Handles control flow (loops, conditionals) | |||
Handles arbitrary code (black-box functions) | |||
Expression swell (intermediate expression growth) | |||
Requires source code access | |||
Typical use in neural network training | |||
Memory overhead for reverse mode | Proportional to number of operations in computation graph | Minimal | Can be exponential in expression complexity |
Frequently Asked Questions
Clear, technically precise answers to the most common questions about automatic differentiation, the computational engine that powers gradient-based optimization in neural network potentials and modern quantum chemistry.
Automatic differentiation (AD) is a computational technique that evaluates the exact derivative of a function specified by a computer program by systematically applying the chain rule to elementary arithmetic operations and functions. Unlike numerical differentiation, which approximates derivatives using finite differences and suffers from truncation and round-off errors, AD computes derivatives to machine precision. Unlike symbolic differentiation, which manipulates mathematical expressions to produce a closed-form derivative that can suffer from expression swell, AD operates directly on the program's computational graph, generating derivative code without an explosion in complexity. AD achieves this by decomposing any function, no matter how complex, into a sequence of elementary operations—addition, multiplication, sine, exponential—whose derivatives are trivially known, and then composing these via the chain rule in either the forward mode or reverse mode.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
Master the foundational techniques and architectural principles that make automatic differentiation the computational engine behind modern neural network potentials.
Forward-Mode AD
Computes derivatives by propagating tangent values forward through the computational graph alongside the primal calculation. Dual numbers are used to carry both value and derivative, making this mode efficient for functions with few inputs and many outputs.
- Mechanism: Applies the chain rule from inputs to outputs
- Complexity: O(N) in number of inputs
- Use case: Computing Jacobian-vector products for directional derivatives
- Limitation: Inefficient for gradient computation in neural networks with millions of parameters
Reverse-Mode AD
The workhorse of deep learning, also known as backpropagation. Computes gradients by first executing a forward pass to record all intermediate values, then propagating adjoint sensitivities backward from the output to all inputs simultaneously.
- Mechanism: Applies the chain rule from outputs to inputs
- Complexity: O(N) in number of outputs, independent of input count
- Use case: Training neural network potentials on forces and energies
- Key advantage: Computes full gradient of a scalar loss with respect to millions of parameters in a single backward pass
Computational Graph
A directed acyclic graph representing the sequence of elementary operations in a function. Each node stores an operation and its intermediate value, while edges define data dependencies. AD traverses this graph to apply the chain rule.
- Static graphs: Defined once before execution, enabling aggressive compiler optimizations (TensorFlow 1.x)
- Dynamic graphs: Constructed on-the-fly during execution, allowing native control flow (PyTorch, JAX)
- Wengert tape: The linearized record of operations generated during the forward pass that reverse-mode AD traverses backward
Vector-Jacobian Product (VJP)
The fundamental building block of reverse-mode AD. Instead of computing the full Jacobian matrix explicitly, a VJP efficiently computes the product of a row vector with the Jacobian. This avoids the prohibitive O(n²) memory cost of materializing the full Jacobian.
- Pullback function: The VJP operator associated with each primitive operation
- Gradient accumulation: VJPs from multiple downstream nodes are summed at branch points
- Efficiency: Reduces gradient computation from O(n²) to O(n) for scalar-output functions
Higher-Order Differentiation
AD can be applied recursively to compute second derivatives like Hessians and Laplacians, essential for quantum chemistry applications such as vibrational frequency analysis and transition state optimization.
- Forward-over-reverse: Computes Hessian-vector products efficiently without materializing the full Hessian matrix
- Double backpropagation: Applying reverse-mode AD twice to obtain second-order derivatives
- Use in NNPs: Computing force constants and phonon spectra from neural network potentials
- Frameworks: JAX's
grad,jacfwd, andjacrevcompose naturally for arbitrary-order differentiation
Source Code Transformation
An AD implementation strategy that parses source code into an intermediate representation and generates new code that computes derivatives. This approach enables compile-time optimization and produces efficient derivative code without runtime overhead.
- Tools: Tapenade, Zygote (Julia), Enzyme (LLVM-level)
- Advantage: Can differentiate through control flow, loops, and recursion
- Differentiable programming: The paradigm where entire programs are written to be end-to-end differentiable
- Application: Differentiating through entire quantum chemistry workflows, including SCF convergence

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us