一句话:将反向模式自动微分分解为正向模式、线性/非线性解压与线性部分转置,并证明其正确性。
自动微分传统上被视为正向与反向等不同算法,通常分别呈现和实现。本文追问能否只有一种。作者形式化了一种分解:反向模式 AD = 正向模式 AD + 解压线性/非线性部分 + 线性部分转置。为此定义子结构线性类型系统,证明一类函数代数线性;并证明正向 AD 产生线性函数,任意此类函数均可保成本、保大小、保线性地解压与转置。三步复合可恢复反向模式。该分解还自然解释了 checkpointing,源于解压 let 表达式的自由选择,并可用于通用部分求值。
Automatic differentiation (AD) is conventionally understood as a family of distinct algorithms, rooted in two “modes”—forward and reverse—which are typically presented (and implemented) separately. Can there be only one? Following up on the AD systems developed in the JAX and Dex projects, we formalize a decomposition of reverse-mode AD into (i) forward-mode AD followed by (ii) unzipping the linear and non-linear parts and then (iii) transposition of the linear part. To that end, we define a (substructurally) linear type system that can prove a class of functions are (algebraically) linear. Our main results are that forward-mode AD produces such linear functions, and that we can unzip and transpose any such linear function, conserving cost, size, and linearity. Composing these three transformations recovers reverse-mode AD. This decomposition also sheds light on checkpointing, which emerges naturally from a free choice in unzipping let expressions. As a corollary, checkpointing techniques are applicable to general-purpose partial evaluation, not just AD. We hope that our formalization will lead to a deeper understanding of automatic differentiation and that it will simplify implementations, by separating the concerns of differentiation proper from the concerns of gaining efficiency (namely, separating the derivative computation from the act of running it backward).
@article{paperbot2093,
title = {You Only Linearize Once: Tangents Transpose to Gradients},
author = {Alexey Radul and Adam Paszke and Roy Frostig and Matthew J. Johnson and Dougal Maclaurin},
journal = {Proceedings of the ACM on Programming Languages},
volume = {7},
number = {POPL},
year = {2023},
doi = {10.1145/3571236}
}