Abstract: This paper considers the reliability of automatic differentiation (AD) for neural networks involving the nonsmooth MaxPool operation. We investigate the behavior of AD across different precision levels (16, 32, 64 bits) and convolutional architectures (LeNet, VGG, and ResNet) on various datasets (MNIST, CIFAR10, SVHN, and ImageNet). Although AD can be incorrect, recent research has shown that it coincides with the derivative almost everywhere, even in the presence of nonsmooth operations (such as MaxPool and ReLU). On the other hand, in practice, AD operates with floating-point numbers (not real numbers), and there is, therefore, a need to explore subsets on which AD can be numerically incorrect. These subsets include a bifurcation zone (where AD is incorrect over reals) and a compensation zone (where AD is incorrect over floating-point numbers but correct over reals). Using SGD for the training process, we study the impact of different choices of the nonsmooth Jacobian for the MaxPool function on the precision of 16 and 32 bits. These findings suggest that nonsmooth MaxPool Jacobians with lower norms help maintain stable and efficient test accuracy, whereas those with higher norms can result in instability and decreased performance. We also observe that the influence of MaxPool's nonsmooth Jacobians on learning can be reduced by using batch normalization, Adam-like optimizers, or increasing the precision level.
Introduction
Most modern deep learning frameworks rely on Automatic Differentiation (AD) to compute the gradients necessary for backpropagation. While AD is mathematically robust for smooth functions, its application to "nonsmooth" operations—such as ReLU or MaxPool—introduces significant complexity. In these cases, the derivative is not uniquely defined at certain points, such as when two pixels in a pooling window share the exact same maximum value.
While theoretical research suggests AD is "correct almost everywhere" over real numbers, practical implementations rely on floating-point arithmetic (16, 32, or 64 bits). This paper explores the gap between theoretical correctness and numerical reliability, specifically focusing on how MaxPool behaves under varying precision levels and how the choice of subgradient impacts training stability.
Categorizing AD Failures
The authors introduce a framework to categorize where AD fails by defining two distinct zones of error:
- Bifurcation Zone: Areas where AD is theoretically incorrect even over real numbers. In these zones, different implementations of the same operation may yield different results.
- Compensation Zone: A newly defined category where AD would be theoretically correct over real numbers but fails in practice due to floating-point rounding errors and the non-associativity of computer arithmetic.
To quantify these zones, the researchers implemented three versions of MaxPool Jacobians: a Native implementation (choosing the first index), a Minimal implementation (averaging all indices sharing the maximum value), and a Hybrid version parameterized by a value $\beta$, where higher $\beta$ values correspond to higher-norm Jacobians.
The Role of Precision
A key finding of the study is that numerical instability is heavily dependent on the precision of the floating-point representation. In experiments using a VGG11 model on the CIFAR10 dataset, the authors observed that at 16-bit and 32-bit precision, a staggering 100% of the parameters resided within the numerical bifurcation zone.
As shown in the figure above, the proportion of errors remains high in lower precision settings but drops to 0% when using 64-bit precision. This suggests that the low-precision training environments common in modern hardware are inherently more susceptible to AD errors.
Jacobian Norms and Training Stability
The "size" or norm of the Jacobian chosen for MaxPool significantly impacts the training process. High-norm Jacobians (represented by large $\beta$ values) act as a source of noise that can lead to exploding gradients. For $\beta$ values greater than $10^3$, the authors observed significant training instability and performance degradation in 16-bit settings.
Even when a model eventually reaches acceptable final accuracy, high-norm Jacobians can cause "chaotic" training behavior, characterized by sudden fluctuations in the learning curve. These fluctuations typically disappear when switching to higher precision or adopting lower-norm Jacobians, such as the "minimal" averaging approach.
Mitigation Strategies
Despite these numerical vulnerabilities, the study identifies several effective mitigation strategies already prevalent in deep learning:
- Normalization: Batch Normalization is remarkably effective at counteracting the negative effects of large MaxPool Jacobians, effectively "masking" the underlying numerical unreliability.
- Optimizers: Adam-like optimizers provide more robustness against these errors compared to standard SGD.
- Structural Choices: Using multivariate functions like
NormPool(Euclidean norm) instead of standard MaxPool can avoid the compensation errors entirely.
Conclusion
To ensure robust training, especially in low-precision environments, practitioners should favor low-norm Jacobians (the minimal averaging approach) for nonsmooth operations. While modern architectural choices like Batch Normalization and Adam help mitigate these issues, understanding the bifurcation and compensation zones is critical for developing the next generation of numerically reliable deep learning systems.
Summary updated