34.8  Further Reading

Throughout this chapter, we proved our main results under clean assumptions that deep learning practice routinely bends: a ReLU network is full of sharp kinks, a reverse-mode tape can easily outgrow GPU memory, and a thousand-dimensional integral cannot be placed on a grid. The short notes below summarize what happens when those assumptions break down, followed by a curated list of textbooks, courses, and tutorials covering the chapter’s core material. Two topics bear directly on everyday training and are worth reading first: conservative fields, which explain in what sense backpropagation through kinks is still valid, and recursive checkpointing, which keeps memory manageable on long computations. Nothing elsewhere in the book depends on this section.

34.8.1 Derivatives at Kinks

34.8.1.1 Conservative Fields

As Section 34.1 illustrates, adopting the standard convention \(\mathrm{ReLU}'(0)=0\) leads to a curious anomaly: if we write the identity function as \(\mathrm{ReLU}(x)-\mathrm{ReLU}(-x)=x\), backpropagation returns slope \(0\) at \(x=0\), a number that is neither the true derivative nor even a valid subgradient of \(x\). Classical subdifferentials cannot explain this behavior, because their sum and chain rules hold only as set inclusions once the constituent functions are no longer convex. To close this gap, Bolte and Pauwels (2021) introduce conservative fields, set-valued generalizations of the derivative that obey the chain rule by construction and agree with the ordinary gradient everywhere outside a set of measure zero. Backpropagation with any fixed choice of slope at each kink always returns an element of such a field. And why is the exceptional set of kinks harmlessly small? By Rademacher’s theorem (Rademacher 1919), every Lipschitz function on \(\mathbb R^n\) is differentiable almost everywhere, so the kinks of a ReLU network’s loss occupy a set of measure zero.

The same work settles the practical question of whether stochastic gradient descent driven by these backpropagation values still converges. For losses built from standard neural network layers, assuming bounded iterates and the usual conditions on step sizes and gradient noise, the iterates converge to the set of critical points where the conservative field contains zero. That guarantee holds in exact arithmetic, whereas in finite-precision floating point, iterates actually land on kinks. Section 34.1 reports how often this occurs across three numerical precisions, as measured by Bertoin et al. (2021) and corrected in their 2023 erratum, and shows how little the choice of \(\mathrm{ReLU}'(0)\) ends up affecting training.

34.8.1.2 Subgradient Methods

Smooth optimization relies on the descent lemma, which guarantees that a small step against the gradient lowers the objective. Nonsmooth functions break that guarantee: at the minimum of \(|x|\), the valid subgradient \(\tfrac12\) actually points uphill, as shown in Section 34.1. Remarkably, the subgradient method converges anyway, because its analysis tracks the Euclidean distance to a minimizer rather than the objective value itself. With diminishing step sizes satisfying \(\sum_t\eta_t=\infty\) and \(\sum_t\eta_t^2<\infty\), the best objective value seen so far converges to the minimum. Obtaining the optimal convergence rate calls for a different schedule: for a convex function whose subgradients have norm at most \(G\), starting at distance \(R\) from a minimizer, a constant step size \(R/(G\sqrt T)\) brings the best of \(T\) iterates within \(RG/\sqrt T\) of the minimum. When the dimension exceeds \(T\), no method relying solely on subgradients can improve on this rate by more than a constant factor (Nesterov 2018). For a systematic development of subdifferential calculus, including exact conditions under which the sum rule holds with equality, see Rockafellar (1970) .

34.8.2 Derivatives of Vector and Matrix Maps

34.8.2.1 The Mean Value Theorem for Vector-Valued Maps

In one dimension, the mean value theorem of Section 34.1 guarantees an intermediate point \(\xi\) such that \(f(b)-f(a)=f'(\xi)(b-a)\). It is tempting to assume the same equality holds for vector-valued curves \(\boldsymbol\gamma:\mathbb R\to\mathbb R^n\), but it fails completely. Take the unit circle \(\boldsymbol\gamma(t)=(\cos t,\sin t)\): after a full turn at \(t=2\pi\), the curve returns to its starting point so \(\boldsymbol\gamma(2\pi)-\boldsymbol\gamma(0)=\mathbf 0\), yet the velocity \(\boldsymbol\gamma'(\xi)\) has unit length and is never \(\mathbf 0\) for any \(\xi\). What survives in higher dimensions is only the mean value inequality, \(\|\boldsymbol\gamma(b)-\boldsymbol\gamma(a)\|\le\sup_\xi\|\boldsymbol\gamma'(\xi)\|\,|b-a|\) (Theorem 5.19 of Rudin (1976)). Fortunately, the Taylor bounds in Section 34.2 never need a vector version of the theorem, because they restrict a scalar-valued loss to a line segment, where the ordinary one-variable theorem applies directly.

34.8.2.2 Jacobians of Matrix-Valued Maps

In Section 34.4, we differentiate scalar losses, so every gradient conveniently has the same shape as its matrix variable. Once we differentiate a matrix-valued function with respect to a matrix input, however, the full derivative becomes a four-index array. A standard way to keep the algebra linear and familiar is to flatten both matrices with the column-stacking operator \(\operatorname{vec}\), turning the four-index tensor into an ordinary Jacobian matrix. Under this flattening, a matrix differential \(d\mathbf F=\mathbf A\,d\mathbf X\,\mathbf B\) becomes \(d\operatorname{vec}\mathbf F=(\mathbf B^\top\otimes\mathbf A)\,d\operatorname{vec}\mathbf X\), and the chain rule simply multiplies Kronecker products. Giles (2008) provides a handy catalog of forward and reverse differentiation rules for matrix products, inverses, determinants, and standard matrix decompositions.

34.8.3 Automatic Differentiation

34.8.3.1 Optimal Jacobian Accumulation

As Section 34.4 shows, simply changing the order in which we multiply a chain of Jacobians can alter the computational cost by roughly a factor of the layer width. For a straight chain of \(K\) factors, finding the cheapest parenthesization is the classical matrix-chain multiplication problem, which dynamic programming solves in \(O(K^3)\) time. A general computation graph with branches and skip connections opens up a much larger space of elimination orders: each intermediate node can be eliminated by multiplying the partial derivatives on its incoming and outgoing edges, in any sequence. Finding the elimination order with the fewest multiplications turns out to be NP-complete (Naumann 2008). Deep learning frameworks therefore do not attempt global optimization of the elimination order; instead, they provide forward mode, reverse mode, and their compositions, leaving the choice of mode to the user. Griewank and Walther (2008) develop vertex, edge, and face elimination in full generality and review the heuristics used by derivative compilers.

34.8.3.2 Recursive Checkpointing

The one-level checkpointing scheme in Section 34.5 reduces peak activation memory to \(T/s+s\) stored states, reaching \(2\sqrt T\) at the optimal block size \(s\) at the cost of one extra forward pass (Chen et al. 2016). For very long sequences or unrolled iterative solvers, even \(O(\sqrt T)\) memory can be too much. Applying the same idea recursively inside each recomputed segment brings memory all the way down to \(O(\log T)\) while requiring \(O(T\log T)\) recomputation (Griewank 1992). When every step has the same cost, Griewank’s binomial checkpointing schedule is provably optimal for any fixed memory budget (Griewank and Walther 2008). In practice, checkpointing utilities implement one level of checkpointing per marked block.

PyTorch provides torch.utils.checkpoint.

TensorFlow provides tf.recompute_grad.

JAX provides jax.checkpoint; nesting those blocks lets you build a recursive schedule manually.

34.8.3.3 Taylor Mode

Computing a \(k\)-th directional derivative by nesting forward-mode automatic differentiation \(k\) times is wasteful, because each nesting doubles the state and carries \(2^k\) components per value. Taylor mode avoids this exponential blow-up by replacing dual numbers with truncated power series \(a_0+a_1\varepsilon+\cdots+a_k\varepsilon^k\) subject to \(\varepsilon^{k+1}=0\). Each elementary operation propagates all \(k+1\) coefficients in a single pass: multiplication convolves the two coefficient sequences in \(O(k^2)\) operations, and transcendental functions such as \(\exp\), \(\log\), and \(\sin\) follow from recurrences of the same \(O(k^2)\) cost (Griewank and Walther 2008). The exercise on computing second derivatives in one forward pass in Section 34.5 is the \(k=2\) case.

jax.experimental.jet implements Taylor mode for arbitrary order \(k\).

34.8.3.4 Forward Gradients

Reverse-mode differentiation requires storing a tape of intermediate values, whereas forward mode avoids the tape but requires one pass per input parameter. Baydin et al. (2022) sidestep both costs by running a single forward pass along a random Gaussian tangent \(\mathbf v\sim\mathcal N(\mathbf 0,\mathbf I)\) and taking \((\nabla\ell^\top\mathbf v)\,\mathbf v\) as a stochastic gradient estimate. Because \(\mathbb{E}[\mathbf v\mathbf v^\top]=\mathbf I\), the estimate is unbiased, and for \(n\) parameters its mean squared error is \((n+1)\|\nabla\ell\|^2\). The memory tape disappears completely, but the trade-off is stark: the typical estimation error is roughly \(\sqrt n\) times the norm of the true gradient, which is manageable for small models yet prohibitive at modern neural network scales.

34.8.4 Integration

34.8.4.1 The Lebesgue Integral

The Riemann integral partitions the domain into intervals, a strategy that breaks down on wildly discontinuous functions: as shown in Section 34.6, the indicator of the rational numbers has tagged sums that never settle, and even a pointwise limit of Riemann-integrable functions need not remain Riemann integrable. Lebesgue’s insight is to slice the range instead of the domain: measure the size of the set where \(f\) exceeds each height level, and add up those measures. Sets of measure zero, such as the rational numbers or the ray \(\theta=0\) in polar coordinates, contribute nothing at all, so the indicator of the rationals cleanly integrates to \(0\). Both Section 34.6 and Section 34.7 invoke three workhorse theorems of this theory without proof: Fubini–Tonelli, the \(n\)-dimensional change of variables, and differentiation under an integral over an infinite domain. All three rest on the monotone and dominated convergence theorems, which specify when a limit may be swapped with an integral: if \(f_k\to f\) pointwise and \(|f_k|\le g\) for a single integrable function \(g\), then \(\int f_k\to\int f\) (Folland 1999).

34.8.4.2 Quasi-Monte Carlo

In Section 36.5.1.7, we compared a second-order grid, whose error decays as \(N^{-2/d}\), with Monte Carlo integration, whose error decays as \(N^{-1/2}\) regardless of dimension. Purely random samples, however, inevitably leave accidental clumps and empty gaps. Low-discrepancy point sets (such as Sobol sequences, Halton sequences, and lattice rules) are constructed to fill the unit cube far more evenly, achieving an error of \(O(N^{-1}(\log N)^d)\) for integrands of bounded variation (in the sense of Hardy and Krause). Taken purely as a worst-case guarantee, this bound is sobering: ignoring constants, it drops below \(N^{-1/2}\) only past several thousand points for \(d=2\) and past \(10^{15}\) points for \(d=5\). In practice, quasi-Monte Carlo still frequently outperforms ordinary Monte Carlo even in high dimensions, usually because real integrands depend primarily on a small number of effective coordinates at a time. Because a deterministic point set provides no built-in error bar, randomized quasi-Monte Carlo randomly shifts or scrambles the points so that independent replicates yield an unbiased variance estimate. Owen (2013) covers both deterministic and randomized methods in Chapters 15–17.

34.8.4.3 Gradient Estimators beyond Score and Pathwise

In Section 34.7, we derived the score-function and pathwise estimators and reduced the variance of the score-function estimator using a constant baseline. More sophisticated control variates exploit the structure of the model itself: REBAR (Tucker et al. 2017) subtracts the pathwise gradient of a continuous relaxation from the score-function estimator and adds back its analytic expectation, lowering variance while keeping the estimator unbiased for discrete random variables. The continuous relaxations themselves, such as Gumbel-softmax (Jang et al. 2017; Maddison et al. 2017) and straight-through estimators (Bengio et al. 2013), offer low variance at the cost of introducing bias relative to the original discrete objective. A third approach, measure-valued derivatives, expresses the derivative of a probability density as a scaled difference of two densities and estimates the gradient by sampling from both. Mohamed et al. (2020) unite all three families in a single framework and spell out the conditions under which each applies.

34.8.5 Books, Courses, and Tutorials

Books

Courses and Tutorials

Discussions