NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Few-bit Backward: Quantized Gradients of Activation Functions for Memory Footprint Reduction

Georgii Sergeevich Novikov, Daniel Bershatsky, Julia Gusak, Alex Shonenkov, Denis Valerievich Dimitrov, Ivan Oseledets

Training massive neural networks is often bottlenecked by the memory required to store activations for the backward pass. The paper Few-bit Backward introduces a novel method that uses dynamic programming to create optimal, low-bit piecewise-constant approximations of activation function derivatives. This approach reduces total training memory by up to 40% with a negligible impact on model accuracy.

The Memory Bottleneck in Training

When training a neural network, the forward pass isn't just about computing the final output; the system must also save the intermediate inputs (activations) to every operation to calculate gradients during the backward pass. For modern architectures like Transformers or deep ResNets, these stored activations can consume significantly more memory than the model weights themselves.

While techniques like gradient checkpointing (recomputing activations) or offloading (moving them to CPU RAM) exist, they often incur heavy computational or communication penalties. The authors identify a specific, often-overlooked culprit: pointwise nonlinearities (such as GELU, Swish, or Sigmoid). Standard deep learning frameworks store the full-precision (32-bit) input for these layers. The authors pose a critical question: Can we store a highly compressed version of this information and still compute accurate gradients?

The Few-bit Backward Method

The core innovation of Few-bit Backward is approximating the derivative of the activation function rather than compressing the activation values themselves.

Forward and backward pass pipeline showing quantized tensor saving

The method operates on three main principles:

1. Piecewise-Constant Approximation

Instead of relying on the exact derivative $f'(x)$, the authors propose replacing it with a piecewise-constant function $q(x)$. This function divides the input range into $k$ discrete bins. Instead of storing a 32-bit float during the forward pass, the system only stores the bin index (e.g., 2 bits for 4 bins, or 4 bits for 16 bins).

Illustration of a piecewise-constant approximation of a derivative

2. Optimal Quantization via Dynamic Programming

Finding the best boundaries and values for these bins is a non-trivial optimization problem. The authors utilize a dynamic programming (DP) approach to minimize the weighted $L_2$ distance between the true derivative and the staircase approximation. Crucially, this DP task only needs to be solved once for each activation function type (e.g., once for GELU, once for Sigmoid). The resulting optimal bins can then be used as a "drop-in" replacement in any model.

3. Efficient Implementation

To ensure these theoretical memory savings translate to real-world performance, the authors provide a custom CUDA kernel. During the forward pass, the kernel performs a rapid binary search to find the correct bin index. In the backward pass, it executes a simple, highly efficient table lookup to retrieve the gradient approximation.

Key Insights and Results

The researchers validated their approach across diverse domains, including Natural Language Understanding (RoBERTa-base on GLUE), Computer Vision (ResNet18 on ImageNet), and multimodal tasks (ruDALL-E Malevich on the Russian Emoji Dataset).

  • Significant Memory Reduction: The method yields up to a 40% reduction in total device memory consumption during training. For a ResNet18 trained on ImageNet, utilizing 4-bit approximations increased the maximum possible batch size by over 33%.
  • Accuracy Parity: Stochastic Gradient Descent (SGD) is remarkably robust to noise. The authors demonstrate that the "shape" of an activation's derivative is simple enough that even a 3-bit or 4-bit approximation provides a gradient signal nearly identical to full precision. On the GLUE benchmark, 3-bit and 4-bit GELU variants achieved results virtually identical to the standard 32-bit GELU.
  • Superiority at Extreme Low-Bits: In highly memory-constrained environments, even a 1-bit approximation (essentially a step function) performs surprisingly well. Compared to ActNN, a popular activation quantization framework, Few-bit Backward showed much higher stability at very low bit-widths. For instance, on the QQP task, the 1-bit Few-bit method reached 0.9080 accuracy compared to ActNN's 0.8880.
  • Data-Agnostic Efficiency: Unlike competing methods that adapt quantization dynamically to the specific data in a batch, Few-bit Backward pre-calculates optimal bins based on a standard distribution. This makes it faster and easier to implement without sacrificing accuracy. Furthermore, because the backward pass replaces complex mathematical operations (like exponents) with a simple memory lookup, the custom CUDA layers run slightly faster than standard implementations.

Limitations and Future Directions

While highly effective, the method does have limitations. The optimal bins are calculated assuming a specific distribution of inputs (e.g., Gaussian). If a model's activations deviate wildly from this assumption due to extreme outliers or unusual scaling, the approximation quality might degrade.

Additionally, the current scope focuses exclusively on pointwise nonlinearities. While these are ubiquitous, they represent only one component of a network's total memory footprint. Future work could explore extending this optimal DP-based staircase approximation to other types of neural network layers, further slashing the memory requirements of massive models.

Summary updated

BibTeX
@inproceedings{novikov2023few,
  author = {Georgii Sergeevich Novikov and Daniel Bershatsky and Julia Gusak and Alex Shonenkov and Denis Valerievich Dimitrov and Ivan Oseledets},
  title = {{Few-bit Backward: Quantized Gradients of Activation Functions for Memory Footprint Reduction}},
  booktitle = {International Conference on Machine Learning},
  year = {2023},
  url = {https://openreview.net/forum?id=m2S96Qf2R3},
}
Figure