Abstract
Training large-scale Transformer models is often constrained by activation memory. We present Inverted Activations (InvAct), a method that reduces activation memory by approximately 25% by storing the output of a nonlinearity instead of its input. To handle non-monotonic functions like GELU and SiLU, InvAct utilizes a 1-bit indicator and high-precision mathematical approximations for the backward pass. Empirical results across BERT, Llama, and ViT demonstrate significant memory savings with negligible computational overhead and no loss in accuracy.
Introduction
Modern deep learning training is a constant battle against memory limits. While model parameters (weights) are often the focus, a substantial portion of GPU memory is consumed by activation tensors—intermediate results stored during the forward pass for use in gradient calculations during the backward pass.
In standard frameworks like PyTorch, pointwise nonlinearities (e.g., GELU or SiLU) save their entire input tensor. However, the subsequent layer typically saves that same tensor as its input, leading to redundant "double storage." For architectures like BERT, Llama, and Vision Transformers (ViT), this redundancy is a significant bottleneck. We introduce Inverted Activations (InvAct), a drop-in replacement that eliminates this redundancy by reconstructing inputs from outputs during the backward pass.
Methodology
The core principle of InvAct is to save the output ($y$) of an activation function $f$ instead of its input ($x$). During the backward pass, the gradient requires the derivative $f'(x)$. By storing $y$, we can recover $x$ via the inverse function: $x = f^{-1}(y)$.
Handling Non-Invertibility
Popular activation functions like GELU and SiLU are not strictly monotonic, meaning multiple inputs can produce the same output. To address this, InvAct stores a 1-bit Boolean indicator per element to track which monotonic region the input belongs to (e.g., left or right of the local minimum). These bits are packed into uint8 tensors, resulting in a minimal overhead of exactly 1 bit per element.
Mathematical Approximation
Since functions like GELU lack a simple analytical inverse, calculating $f^{-1}$ exactly is computationally expensive. Instead, we employ highly accurate, hand-tuned mathematical approximations for the composite function $g(y) = f'(f^{-1}(y))$. This approach ensures the backward pass remains computationally efficient while maintaining high gradient precision.
Experimental Evaluation
We validated InvAct across several models and datasets:
- BERT: Fine-tuned on the Yelp Review dataset for sentiment classification.
- Llama v3.1 8B: Fine-tuned using ORPO on DPO preference datasets.
- Vision Models: Evaluated on ViT, CLIP, and Audio Spectral Transformer using standard Hugging Face configurations.
Key Results
- Memory Efficiency: InvAct consistently reduced activation memory by 22.9% to 24.0% across BERT, ViT, and CLIP models.
- Performance Parity: Training curves for BERT and Llama v3.1 were virtually identical to standard PyTorch baselines. The variance between random seeds exceeded any difference introduced by InvAct.
- Computational Overhead: The overhead for calculating approximations was negligible, measuring less than 0.1% in full-scale training scenarios.
- Comparison to Quantization: InvAct outperformed gradient quantization methods (like FewBit) by providing higher gradient accuracy and superior validation scores for the same memory footprint.
Discussion and Limitations
InvAct exploits the inherent redundancy in Transformer layers. By making the activation layer reconstruct its input from the output already stored by the next layer, one large tensor becomes unnecessary.
However, the effectiveness of InvAct depends on the network architecture; it primarily saves memory when the subsequent layer also caches its input. Furthermore, the benefits may overlap with activation checkpointing strategies. While current approximations were manually derived, future work could explore automated symbolic regression to generate efficient inverse approximations for a broader range of nonlinearities.
Conclusion
Inverted Activations offer a simple yet effective "clever trick" to slash training memory by nearly 25% without sacrificing speed or accuracy. As a seamless drop-in replacement for standard layers, InvAct provides a practical path toward training larger models on existing hardware.
Summary updated