# On Correctness of Automatic Differentiation for Non-Differentiable Functions

arXiv: https://arxiv.org/abs/2006.06903 · HTML: https://mlsanity.com/paper/2006.06903/

## Key facts

- Cited by 20 papers in the map (data through 14 Oct 2026).
- First posted on arXiv 12 Jun 2020.

## Built on by (most cited first, 20 of 20)

- [Nonsmooth Implicit Differentiation for Machine Learning and Optimization](https://mlsanity.com/paper/2106.04350/) (2021)
- [Automatic differentiation of nonsmooth iterative algorithms](https://mlsanity.com/paper/2206.00457/) (2022)
- [Bounds for the smallest eigenvalue of the NTK for arbitrary spherical data of arbitrary dimension](https://mlsanity.com/paper/2405.14630/) (2024)
- [Meta-Learning for Physically-Constrained Neural System Identification](https://mlsanity.com/paper/2501.06167/) (2025)
- [A Gradient Sampling Algorithm for Stratified Maps with Applications to Topological Data Analysis](https://mlsanity.com/paper/2109.00530/) (2021)
- [The structure of conservative gradient fields](https://mlsanity.com/paper/2101.00699/) (2021)
- [Learning Sparsity-Promoting Regularizers using Bilevel Optimization](https://mlsanity.com/paper/2207.08939/) (2022)
- [On the Correctness of Automatic Differentiation for Neural Networks with Machine-Representable Parameters](https://mlsanity.com/paper/2301.13370/) (2023)
- [ωPAP Spaces: Reasoning Denotationally About Higher-Order, Recursive Probabilistic and Differentiable Programs](https://mlsanity.com/paper/2302.10636/) (2023)
- [Deep Learning as the Disciplined Construction of Tame Objects](https://mlsanity.com/paper/2509.18025/) (2025)
- [An Efficient Learning-Based Solver for Two-Stage DC Optimal Power Flow with Feasibility Guarantees](https://mlsanity.com/paper/2304.01409/) (2023)
- [Understanding Automatic Differentiation Pitfalls](https://mlsanity.com/paper/2305.07546/) (2023)
- [Auto-Differentiation of Relational Computations for Very Large Scale Machine Learning](https://mlsanity.com/paper/2306.00088/) (2023)
- [Network control by a constrained external agent as a continuous optimization problem](https://mlsanity.com/paper/2108.10298/) (2021)
- [An Algebraic Approach to Learning and Grounding](https://mlsanity.com/paper/2204.02813/) (2022)
- [Global quantitative robustness of regression feed-forward neural networks](https://mlsanity.com/paper/2211.10124/) (2022)
- [On the numerical reliability of nonsmooth autodiff: a MaxPool case study](https://mlsanity.com/paper/2401.02736/) (2024)
- [BrowNNe: Brownian Nonlocal Neurons & Activation Functions](https://mlsanity.com/paper/2406.15617/) (2024)
- [GradInf: Gradient Estimation as Probabilistic Inference](https://mlsanity.com/paper/2607.07840/) (2026)
- [LazyHMC: Hamiltonian Monte Carlo Simulation for Lazy, Infinite Dimensional Probabilistic Programs](https://mlsanity.com/paper/2608.08588/) (2026)

## Abstract (arXiv)

Differentiation lies at the core of many machine-learning algorithms, and is well-supported by popular autodiff systems, such as TensorFlow and PyTorch. Originally, these systems have been developed to compute derivatives of differentiable functions, but in practice, they are commonly applied to functions with non-differentiabilities. For instance, neural networks using ReLU define non-differentiable functions in general, but the gradients of losses involving those functions are computed using autodiff systems in practice. This status quo raises a natural question: are autodiff systems correct in any formal sense when they are applied to such non-differentiable functions? In this paper, we provide a positive answer to this question. Using counterexamples, we first point out flaws in often-used informal arguments, such as: non-differentiabilities arising in deep learning do not cause any issues because they form a measure-zero set. We then investigate a class of functions, called PAP functions, that includes nearly all (possibly non-differentiable) functions in deep learning nowadays. For these PAP functions, we propose a new type of derivatives, called intensional derivatives, and prove that these derivatives always exist and coincide with standard derivatives for almost all inputs. We also show that these intensional derivatives are what most autodiff systems compute or try to compute essentially. In this way, we formally establish the correctness of autodiff systems applied to non-differentiable functions.
