Deterministic and probabilistic backward error analysis of neural networks in floating-point arithmetic

Théo Beuzeville, Alfredo Buttari, Serge Gratton, Théo MarySPIRE 2024

Abstract

The use of artificial neural networks is now becoming widespread across a wide variety of tasks. In this context of very rapid development, issues related to the storage and computational performance of these models emerge, since networks are sometimes very deep and comprise up to billions of parameters. For all these reasons, the use of reduced precision is increasingly being considered although, until now, its accuracy and robustness had been approached mostly from a practical standpoint or verified by software. The aim of this work is to provide formal tools to better understand, explain, and predict the accuracy and stability of neural networks when using floating-point arithmetic. To this end, we first extend to neural networks some well-known concepts from numerical linear algebra, such as condition number and backward error. We then apply a rounding error analysis based on existing tools in numerical linear algebra to obtain both forward and backward error bounds. This includes both deterministic worst-case bounds as well as probabilistic bounds that are sharper on average. These bounds both ensure the proper functioning of neural networks once trained, and provide recommendations on architectures and training methods to enhance the robustness of neural networks.

Introduction

As neural networks (NNs) grow to trillions of parameters, the industry is racing toward "reduced precision" formats (like FP16, BF16, or INT8) to save energy and memory. However, most practitioners treat numerical stability as an empirical game: if the model doesn't "blow up" during training, it is assumed to be fine.

This research argues that we lack the formal tools to predict why or when a network will fail due to rounding errors. In traditional scientific computing, researchers use "backward error analysis" to determine if a computed solution is the exact solution to a slightly perturbed problem. This paper brings that rigor to NNs, moving beyond empirical observation to provide mathematical proofs of stability.

Methodology

The researchers adapted classical tools from numerical linear algebra—specifically backward error and condition numbers—to the non-linear world of neural networks.

1. Activation Function Modeling

They treated activation functions (like ReLU or Tanh) as operations that introduce their own rounding errors. These errors can then be "pushed back" onto the input data as structured perturbations, allowing the entire network to be analyzed as a perturbed system.

2. Deterministic vs. Probabilistic Bounds

  • Deterministic Bounds: The authors first derived "worst-case" bounds. These are mathematically certain but often too pessimistic for real-world use, as they assume all errors accumulate in the most damaging way possible.
  • Probabilistic Bounds: Using Martingale theory and the Azuma-Hoeffding inequality, they derived much tighter bounds that describe how errors behave on average. These bounds provide a more realistic expectation of network performance in low-precision environments.

3. Linearized Approximation

Since calculating the "true" backward error for a deep network is an NP-hard optimization problem, the authors used a first-order linearized approximation to validate their theoretical bounds experimentally. This approach bridges the gap between complex theory and practical measurement.

Experimental Validation

The authors validated their theory using two distinct approaches:

  • Synthetic Random Networks: Untrained networks with weights drawn from Gaussian and Uniform distributions were used to test the limits of the mathematical bounds.
  • FashionMNIST: A standard image classification dataset was used to train both Fully Connected (FC) and Convolutional Neural Networks (CNNs) to observe how errors evolve during actual training and inference.

Key Insights and Results

The "Zero-Mean" Advantage

One of the most significant findings is that if a layer's weights are independent and have a mean of zero (common in well-initialized NNs), the rounding error bound does not grow with the size of the layer ($n$). This explains why massive models like Large Language Models (LLMs) can remain stable even in low precision.

Activation Functions as Gatekeepers

The stability of a network is highly sensitive to the "condition number" of its activation functions. If a value falls into a region where the activation function is nearly flat (like the saturated ends of a Tanh curve), the condition number approaches zero, potentially amplifying errors or making the network more susceptible to adversarial attacks.

CNNs vs. Fully Connected Layers

The analysis shows that convolutional layers typically have much smaller backward errors than fully connected layers due to their sparsity (fewer operations per output). However, they may have higher condition numbers, making them more sensitive to input noise.

Predictive Power and Heuristics

The probabilistic bounds were found to be orders of magnitude tighter than deterministic ones, almost perfectly tracking actual observed errors. Furthermore, the results provide a theoretical justification for popular initialization schemes like Glorot (Xavier) initialization, showing they are mathematically optimal for minimizing rounding error propagation.

Limitations and Future Work

While this work provides a new foundation for NN stability, it relies on a first-order (linearized) approximation. This may lose accuracy for extremely low-bit quantization (e.g., 4-bit or 2-bit). Additionally, the current work focuses on standard layers (Linear, Conv, Activations). Future work is needed to extend these bounds to more complex structures like Layer Normalization, Batch Normalization, and the Attention mechanisms found in Transformers. Finally, while this paper focuses on inference, applying this level of rigor to the training process remains a challenging open frontier.

Summary updated

BibTeX
@inproceedings{beuzeville2024deterministic,
  author = {Théo Beuzeville and Alfredo Buttari and Serge Gratton and Théo Mary},
  title = {{Deterministic and probabilistic backward error analysis of neural networks in floating-point arithmetic}},
  booktitle = {SPIRE},
  year = {2024},
}
Figure