22.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.

22.8.1 Derivatives at Kinks#

22.8.1.1 Conservative Fields#

As Section 22.1 illustrates, adopting the standard convention ReLU′(0)=0\mathrm{ReLU}'(0)=0 leads to a curious anomaly: if we write the identity function as ReLU(x)−ReLU(−x)=x\mathrm{ReLU}(x)-\mathrm{ReLU}(-x)=x, backpropagation returns slope 00 at x=0x=0, a number that is neither the true derivative nor even a valid subgradient of xx. 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 Rn\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 22.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 ReLU′(0)\mathrm{ReLU}'(0) ends up affecting training.

22.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∣|x|, the valid subgradient 12\tfrac12 actually points uphill, as shown in Section 22.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 ∑tηt=∞\sum_t\eta_t=\infty and ∑tηt2<∞\sum_t\eta_t^2\lt \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 GG, starting at distance RR from a minimizer, a constant step size R/(GT)R/(G\sqrt T) brings the best of TT iterates within RG/TRG/\sqrt T of the minimum. When the dimension exceeds TT, 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).

22.8.2 Derivatives of Vector and Matrix Maps#

22.8.2.1 The Mean Value Theorem for Vector-Valued Maps#

In one dimension, the mean value theorem of Section 22.1 guarantees an intermediate point ξ\xi such that f(b)−f(a)=f′(ξ)(b−a)f(b)-f(a)=f'(\xi)(b-a). It is tempting to assume the same equality holds for vector-valued curves γ:R→Rn\boldsymbol\gamma:\mathbb R\to\mathbb R^n, but it fails completely. Take the unit circle γ(t)=(cos⁡t,sin⁡t)\boldsymbol\gamma(t)=(\cos t,\sin t): after a full turn at t=2πt=2\pi, the curve returns to its starting point so γ(2π)−γ(0)=0\boldsymbol\gamma(2\pi)-\boldsymbol\gamma(0)=\mathbf 0, yet the velocity γ′(ξ)\boldsymbol\gamma'(\xi) has unit length and is never 0\mathbf 0 for any ξ\xi. What survives in higher dimensions is only the mean value inequality, ∥γ(b)−γ(a)∥≤sup⁡ξ∥γ′(ξ)∥ ∣b−a∣\|\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 22.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.

22.8.2.2 Jacobians of Matrix-Valued Maps#

In Section 22.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 vec⁡\operatorname{vec}, turning the four-index tensor into an ordinary Jacobian matrix. Under this flattening, a matrix differential dF=A dX Bd\mathbf F=\mathbf A\,d\mathbf X\,\mathbf B becomes dvec⁡F=(B⊤⊗A) dvec⁡Xd\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.

22.8.3 Automatic Differentiation#

22.8.3.1 Optimal Jacobian Accumulation#

As Section 22.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 KK factors, finding the cheapest parenthesization is the classical matrix-chain multiplication problem, which dynamic programming solves in O(K3)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.

22.8.3.2 Recursive Checkpointing#

The one-level checkpointing scheme in Section 22.5 reduces peak activation memory to T/s+sT/s+s stored states, reaching 2T2\sqrt T at the optimal block size ss at the cost of one extra forward pass (Chen et al., 2016). For very long sequences or unrolled iterative solvers, even O(T)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)O(\log T) while requiring O(Tlog⁡T)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.

22.8.3.3 Taylor Mode#

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

22.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 v∼N(0,I)\mathbf v\sim\mathcal N(\mathbf 0,\mathbf I) and taking (∇ℓ⊤v) v(\nabla\ell^\top\mathbf v)\,\mathbf v as a stochastic gradient estimate. Because E[vv⊤]=I\mathbb{E}[\mathbf v\mathbf v^\top]=\mathbf I, the estimate is unbiased, and for nn parameters its mean squared error is (n+1)∥∇ℓ∥2(n+1)\|\nabla\ell\|^2. The memory tape disappears completely, but the trade-off is stark: the typical estimation error is roughly n\sqrt n times the norm of the true gradient, which is manageable for small models yet prohibitive at modern neural network scales.

22.8.4 Integration#

22.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 22.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 ff exceeds each height level, and add up those measures. Sets of measure zero, such as the rational numbers or the ray θ=0\theta=0 in polar coordinates, contribute nothing at all, so the indicator of the rationals cleanly integrates to 00. Both Section 22.6 and Section 22.7 invoke three workhorse theorems of this theory without proof: Fubini–Tonelli, the nn-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 fk→ff_k\to f pointwise and ∣fk∣≤g|f_k|\le g for a single integrable function gg, then ∫fk→∫f\int f_k\to\int f (Folland, 1999).

22.8.4.2 Quasi-Monte Carlo#

In Section 24.5.1.7, we compared a second-order grid, whose error decays as N−2/dN^{-2/d}, with Monte Carlo integration, whose error decays as N−1/2N^{-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)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/2N^{-1/2} only past several thousand points for d=2d=2 and past 101510^{15} points for d=5d=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.

22.8.4.3 Gradient Estimators beyond Score and Pathwise#

In Section 22.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.

22.8.5 Books, Courses, and Tutorials#

Books

Courses and Tutorials

Discussions