Thinking Forward: Memory-Efficient Federated Finetuning of Language Models

Kunjal Panchal, Nisarg Parikh, Sunav Choudhary, Lijun Zhang, Yuriy Brun, Hui Guan

Introduction

In the rapidly evolving landscape of Large Language Models (LLMs), "finetuning" has traditionally been synonymous with massive GPU clusters and hundreds of gigabytes of Video RAM (VRAM). This high barrier to entry poses a significant challenge for privacy-preserving applications where data must remain on edge devices, such as smartphones or IoT sensors. While Federated Learning (FL) offers a theoretical path to training on decentralized private data, it has long been stymied by the "memory wall" of backpropagation.

A recent breakthrough from researchers at the University of Massachusetts Amherst and Adobe Research, titled "Thinking Forward: Memory-Efficient Federated Finetuning of Language Models," introduces SPRY. This novel framework rethinks the fundamental mechanics of model training to make on-device LLM tuning a practical reality.

The Memory Bottleneck: Why Backpropagation Fails on Edge Devices

The standard engine for training neural networks is backpropagation (Reverse-mode Auto-Differentiation). To calculate gradients, backpropagation requires a "forward pass" to compute outputs, followed by a "backward pass." The critical flaw for memory-constrained devices is that the system must store all intermediate activations from the forward pass to use them during the backward pass.

For LLMs, these activations are enormous. For instance, finetuning a 4-bit Llama2-7B model using Low-Rank Adaptation (LoRA) requires approximately 33.9GB of RAM, with a staggering 84% of that footprint dedicated solely to activations. Most consumer mobile devices simply lack the hardware to support this. While "zero-order" methods (which estimate gradients using only loss values) exist, they typically suffer from slow convergence and poor accuracy.

The SPRY Approach: Forward-Mode AD and Weight Splitting

SPRY (named for its agility and light memory footprint) overcomes these limitations by replacing backpropagation with Forward-mode Auto-Differentiation (AD).

1. Forward Gradients via Jacobian-Vector Products (JVP)

Instead of a backward pass, SPRY computes "forward gradients" during the forward pass itself. This eliminates the need to store intermediate activations, reducing the memory overhead to roughly the size of the largest single activation layer.

2. Strategic Weight Splitting

Forward-mode AD typically becomes less accurate as the number of trainable parameters grows. SPRY addresses this by splitting the trainable weights (such as LoRA layers) among the participating clients in each federated learning round.

The SPRY workflow: Layers are split across clients, who compute forward gradients (JVP) on assigned weights before the server aggregates updates.

By assigning each client only a small subset of the model's weights to train, the resulting forward gradient becomes a much more accurate estimation of the true gradient. The server then aggregates these partial updates to evolve the full global model.

Experimental Evaluation

The researchers evaluated SPRY across eight diverse language tasks, including classification (AG News, SST2), inference (SNLI, MNLI), and question answering (SQuADv2). The framework was tested on architectures ranging from RoBERTa-Large to massive models like Llama2-7B, OPT6.7B, and OPT13B.

Key Results: Breaking the Memory Wall

The empirical results demonstrate that SPRY makes the previously "impossible" task of on-device LLM tuning feasible:

  • Massive Memory Savings: As shown in the comparative analysis, peak memory for Llama2-7B dropped from 33.9GB to just 6.2GB. For the OPT13B model, memory usage plummeted from 76.5GB to 10.8GB.
  • Superior Performance: Compared to state-of-the-art zero-order methods like MeZO, SPRY achieved 5.2–13.5% higher accuracy and converged 1.2–20.3x faster.
  • Accuracy Parity: SPRY reached within 0.6–6.2% of the accuracy of full backpropagation while using only a fraction of the memory.
Memory footprint comparison across various models. SPRY (First-Order Forward Mode AD) significantly reduces memory by eliminating activation storage.

Insights and Future Directions

A striking insight from this research is that the inherent weakness of Forward-mode AD—its difficulty scaling to many parameters—is perfectly mitigated by the structure of Federated Learning. By distributing the parameter load across many clients, the mathematical limitations of the method are bypassed.

Furthermore, SPRY offers significant communication flexibility. In its "Per-Iteration" mode, clients only need to return a single scalar value (the Jacobian-vector product), drastically reducing the bandwidth required for federated updates.

While SPRY represents a major leap forward, challenges remain. The current implementation of Jacobian-vector products in standard libraries like PyTorch is computationally intensive, meaning SPRY can be slower per-round than backpropagation. Additionally, high data heterogeneity across clients can introduce bias into gradient estimates. Future work will likely focus on optimizing these computational kernels and developing more sophisticated layer-to-client mapping strategies.

By decoupling LLM finetuning from the need for high-end server hardware, SPRY paves the way for a new generation of private, personalized AI running directly on the devices we carry every day.

Source Code: https://github.com/Astuary/Spry

Summary updated

BibTeX
@inproceedings{panchal2024thinking,
  author = {Kunjal Panchal and Nisarg Parikh and Sunav Choudhary and Lijun Zhang and Yuriy Brun and Hui Guan},
  title = {{Thinking Forward: Memory-Efficient Federated Finetuning of Language Models}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2024},
  url = {https://openreview.net/forum?id=dGQtja9X2C},
}
Figure