一句话:揭示高阶函数前向自动微分中扰动标记失效导致结果错误的微妙 bug,并讨论两种修复方案及其缺陷。
自动微分(AD)在前向模式中给每个数附加扰动,并通过重载算术运算传播导数。嵌套求导时,不同导数计算及其扰动必须被区分,现有实现通常为每次求导创建唯一标签并标记扰动。本文指出一个已部署实现中的微妙缺陷:尽管有标签机制,扰动仍会混淆并导致错误结果,尤其在高阶函数上。其根源是:标签应对应每个导数计算,而现有实现却在“在点求函数导数”时创建标签;对高阶函数(如柯里化函数)二者不必一致。作者给出反例并讨论两种修复方案:用 eta 展开延迟新标签创建,或包装导数算子输出做标签替换;两者都难以不破坏前向 AD 复杂度保证。
Abstract Automatic differentiation (AD) is a technique for augmenting computer programs to compute derivatives. The essence of AD in its forward accumulation mode is to attach perturbations to each number, and propagate these through the computation by overloading the arithmetic operators. When derivatives are nested, the distinct derivative calculations, and their associated perturbations, must be distinguished. This is typically accomplished by creating a unique tag for each derivative calculation and tagging the perturbations. We exhibit a subtle bug, present in fielded implementations which support derivatives of higher-order functions, in which perturbations are confused despite the tagging machinery, leading to incorrect results. The essence of the bug is as follows: a unique tag is needed for each derivative calculation, but in existing implementations unique tags are created when taking the derivative of a function at a point. When taking derivatives of higher-order functions, these need not correspond! We exhibit a simple example: a higher-order function f whose derivative at a point x , namely f ′( x ), is itself a function which calculates a derivative. This situation arises naturally when taking derivatives of curried functions. Two potential solutions are presented, and their deficiencies discussed. One uses eta expansion to delay the creation of fresh tags in order to put them into one-to-one correspondence with derivative calculations. The other wraps outputs of derivative operators with tag substitution machinery. Both solutions seem very difficult to implement without violating the desirable complexity guarantees of forward AD.
@article{paperbot720,
title = {Perturbation confusion in forward automatic differentiation of higher-order functions},
author = {OLEKSANDR MANZYUK and BARAK A. PEARLMUTTER and ALEXEY ANDREYEVICH RADUL and DAVID R. RUSH and JEFFREY MARK SISKIND},
journal = {Journal of Functional Programming},
volume = {29},
year = {2019},
doi = {10.1017/s095679681900008x}
}