Reducing Fine-Tuning Memory Overhead by Approximate and Memory-Sharing Backpropagation

Yuchen Yang, Yingdong Shi, Cheems Wang, Xiantong Zhen, Yuxuan Shi, Jun Xu · DOI

Abstract

Fine-tuning large-scale pretrained models like LLaMA and Vision Transformers (ViT) is often constrained by the high memory requirements of activations during backpropagation. While Parameter-Efficient Fine-Tuning (PEFT) methods like LoRA reduce parameter memory, activation memory remains a significant bottleneck. This paper introduces two novel strategies—Approximate Backpropagation (Approx-BP) and Memory-Sharing Backpropagation (MS-BP)—to reduce activation memory by up to 30% without sacrificing training speed or model accuracy. By utilizing 2-bit derivative approximations for activation functions and merging normalization layers with subsequent linear layers, these methods enable more efficient fine-tuning on consumer-grade hardware.

Introduction

The standard paradigm for adapting large-scale models to specific downstream tasks is fine-tuning. However, as models grow to billions of parameters, the hardware requirements become prohibitive. While recent advances in Parameter-Efficient Fine-Tuning (PEFT) have successfully minimized the memory footprint of model weights, the activation memory—the intermediate data stored during the forward pass to compute gradients—remains a massive hurdle. In architectures like ViT and LLaMA, non-linear modules such as activation functions and layer normalization can account for 60-70% of total activation memory.

Existing solutions, such as gradient checkpointing, mitigate this by recomputing activations during the backward pass. However, this comes at a significant computational cost, typically slowing down training by approximately 20%. This research explores a different path: reducing the memory footprint by modifying the backward pass while maintaining the integrity of the forward pass and the speed of the training process.

Proposed Methods

The authors propose two primary techniques designed to target the most memory-intensive components of the Transformer architecture.

1. Approximate Backpropagation (Approx-BP)

Approx-BP is based on the theoretical insight that the backward pass is more flexible than the forward pass. The authors prove that if an approximate function is sufficiently close to the original in functional space, its derivative can be used during backpropagation without destabilizing the learning process.

Applying this to common activation functions like GELU and SiLU, the researchers developed ReGELU2 and ReSiLU2. These variants utilize a 4-segment step function as a derivative. Because a step function only requires identifying which segment an input falls into, the derivative can be stored using only 2 bits per element, rather than the standard 16-bit floating-point representation. This drastically reduces the memory required for activation functions while keeping the forward pass identical to the original pretrained model.

2. Memory-Sharing Backpropagation (MS-BP)

The second technique, MS-BP, addresses the redundancy between Layer Normalization (LN) and the subsequent Linear layers. In standard implementations, both layers store separate, high-precision activation tensors.

Through "mathematical surgery," the authors demonstrate that the affine parameters (weight and bias) of the LN or RMSNorm layer can be mathematically merged into the weights of the following Linear layer during the gradient calculation. This allows the two layers to share a single activation buffer, effectively eliminating one entire set of stored activations. This method, implemented as MS-LN and MS-RMSNorm, provides a structural optimization that saves memory without adding any computational overhead.

Experimental Evaluation

The researchers validated these methods across a diverse range of architectures and benchmarks:

  • Vision Tasks: Using ViT-B and ViT-L on CIFAR-10/100 and Fine-Grained Visual Classification (FGVC) datasets.
  • Large Language Models (LLMs): LLaMA-7B and 13B models were fine-tuned on the Alpaca dataset and evaluated via MMLU and the lm-evaluation-harness.
  • Natural Language Understanding: RoBERTa-base on the GLUE benchmark and BERT on SQuAD-v2.
  • Object Detection: SwinTransformer on the PASCAL VOC dataset.

Key Results

  • Memory Efficiency: The combined application of Approx-BP and MS-BP reduced peak GPU memory usage by approximately 30% across all tested models.
  • Throughput Preservation: Unlike gradient checkpointing, these methods maintained or slightly improved training throughput. By avoiding recomputation, the training speed (samples per second) remained high.
  • Accuracy Stability: Performance remained comparable to standard full-precision fine-tuning. For LLaMA-7B, the accuracy drop was a negligible 0.4%, while saving roughly 6 GiB of VRAM.
  • Extended Sequence Lengths: On a single consumer-grade RTX 4090 GPU, the method allowed LLaMA-7B to increase its maximum training sequence length by 46% (from 1,354 to 1,979 tokens), significantly expanding the model's utility for long-context tasks.

Discussion and Limitations

While highly effective, the proposed methods have specific constraints. MS-BP is designed for the specific sequence of LayerNorm followed by a Linear layer; while this is the standard in Transformers, it may not apply to unconventional architectures. Additionally, while these techniques complement optimizations like FlashAttention, they do not directly address the memory consumed by the attention matrix itself.

Future work may involve testing the long-term stability of Approx-BP during the pretraining phase, where the model must remain stable over millions of iterations. However, for the purposes of fine-tuning, these methods offer a rare "free lunch": substantial memory savings with zero extra compute and minimal impact on accuracy.

Conclusion

By rethinking the requirements of the backward pass, Approx-BP and MS-BP provide a practical path toward democratizing the fine-tuning of massive models. These techniques allow researchers and developers to work with larger models and longer sequences on existing hardware, bridging the gap between high-end industrial clusters and consumer-grade workstations.

Summary updated

BibTeX
@inproceedings{yang2024reducing,
  author = {Yuchen Yang and Yingdong Shi and Cheems Wang and Xiantong Zhen and Yuxuan Shi and Jun Xu},
  title = {{Reducing Fine-Tuning Memory Overhead by Approximate and Memory-Sharing Backpropagation}},
  booktitle = {International Conference on Machine Learning},
  year = {2024},
  url = {https://openreview.net/forum?id=IpSKpOY2EH},
}
Figure