Table of Contents
Fetching ...

Thinking Forward: Memory-Efficient Federated Finetuning of Language Models

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

TL;DR

Spry, an FL algorithm that splits trainable weights of an LLM among participating clients, such that each client computes gradients using forward-mode AD that are closer estimations of the true gradients, achieves a low memory footprint, high accuracy, and fast convergence.

Abstract

Finetuning large language models (LLMs) in federated learning (FL) settings has become increasingly important as it allows resource-constrained devices to finetune a model using private data. However, finetuning LLMs using backpropagation requires excessive memory (especially from intermediate activations) for resource-constrained devices. While Forward-mode Auto-Differentiation (AD) can significantly reduce memory footprint from activations, we observe that directly applying it to LLM finetuning results in slow convergence and poor accuracy. In this paper, we introduce Spry, an FL algorithm that splits trainable weights of an LLM among participating clients, such that each client computes gradients using forward-mode AD that are closer estimations of the true gradients. Spry achieves a low memory footprint, high accuracy, and fast convergence. We formally prove that the global gradients in Spry are unbiased estimators of true global gradients for homogeneous data distributions across clients, while heterogeneity increases bias of the estimates. We also derive Spry's convergence rate, showing that the gradients decrease inversely proportional to the number of FL rounds, indicating the convergence up to the limits of heterogeneity. Empirically, Spry reduces the memory footprint during training by 1.4-7.1x in contrast to backpropagation, while reaching comparable accuracy, across a wide range of language tasks, models, and FL settings. Spry reduces the convergence time by 1.2-20.3x and achieves 5.2-13.5% higher accuracy against zero-order methods. When finetuning Llama2-7B with LoRA, compared to the peak memory consumption of 33.9GB of backpropagation, Spry only consumes 6.2GB of peak memory. For OPT13B, the reduction is from 76.5GB to 10.8GB. Spry makes feasible previously impossible FL deployments on commodity edge devices. Our source code is available at https://github.com/Astuary/Spry.

Thinking Forward: Memory-Efficient Federated Finetuning of Language Models

TL;DR

Spry, an FL algorithm that splits trainable weights of an LLM among participating clients, such that each client computes gradients using forward-mode AD that are closer estimations of the true gradients, achieves a low memory footprint, high accuracy, and fast convergence.

Abstract

Finetuning large language models (LLMs) in federated learning (FL) settings has become increasingly important as it allows resource-constrained devices to finetune a model using private data. However, finetuning LLMs using backpropagation requires excessive memory (especially from intermediate activations) for resource-constrained devices. While Forward-mode Auto-Differentiation (AD) can significantly reduce memory footprint from activations, we observe that directly applying it to LLM finetuning results in slow convergence and poor accuracy. In this paper, we introduce Spry, an FL algorithm that splits trainable weights of an LLM among participating clients, such that each client computes gradients using forward-mode AD that are closer estimations of the true gradients. Spry achieves a low memory footprint, high accuracy, and fast convergence. We formally prove that the global gradients in Spry are unbiased estimators of true global gradients for homogeneous data distributions across clients, while heterogeneity increases bias of the estimates. We also derive Spry's convergence rate, showing that the gradients decrease inversely proportional to the number of FL rounds, indicating the convergence up to the limits of heterogeneity. Empirically, Spry reduces the memory footprint during training by 1.4-7.1x in contrast to backpropagation, while reaching comparable accuracy, across a wide range of language tasks, models, and FL settings. Spry reduces the convergence time by 1.2-20.3x and achieves 5.2-13.5% higher accuracy against zero-order methods. When finetuning Llama2-7B with LoRA, compared to the peak memory consumption of 33.9GB of backpropagation, Spry only consumes 6.2GB of peak memory. For OPT13B, the reduction is from 76.5GB to 10.8GB. Spry makes feasible previously impossible FL deployments on commodity edge devices. Our source code is available at https://github.com/Astuary/Spry.
Paper Structure (58 sections, 5 theorems, 56 equations, 11 figures, 7 tables, 1 algorithm)

This paper contains 58 sections, 5 theorems, 56 equations, 11 figures, 7 tables, 1 algorithm.

Key Result

Theorem 4.1

In Spry, global forward gradients $\nabla \hat{f}$ of the trainable weights $w \in \mathbb{R}^d$, with the corresponding weight perturbations $v\in \mathbb{R}^d$, computed by $M$ participating clients is estimated in terms of true global gradients $\nabla f$ as, where the expectation is under the randomness of sampled data and random perturbation $v$. $C$ is total number of classes and $\alpha_{m

Figures (11)

  • Figure 1: Overview of Spry, a federated learning framework to finetune language models with low memory footprint. The term "PEFT" stands for parameter-efficient fine-tuning.
  • Figure 2: Peak memory consumption of Spry's Forward-mode AD versus backpropgation- and zero-order-based methods. RoBERTa Large, Llama2-7B, and OPT6.7B are profiled with a batch size of 8, and OPT13B with a batch size of 4. Spry reduces total memory usage by 27.90--86.26% compared to backpropagation- based methods. The 1.54--1.96$\times$ additional memory Spry uses, compared to zero-order-based methods, is offset by the accuracy gains (§ \ref{['subsec:performance-comparison']}).
  • Figure 3: Time to convergence for Spry and its counterparts. Spry achieves faster convergence than zero-order methods due to more accurate gradient estimations in a single perturbation.
  • Figure 4: Ablation studies on PEFT methods, communication frequency, and LoRA hyperparameters.
  • Figure 5: Ablation studies on perturbation counts, participating client counts, and layer splitting strategy.
  • ...and 6 more figures

Theorems & Definitions (8)

  • Theorem 4.1: Estimation of the Global Gradient
  • Theorem 4.2: Convergence Analysis
  • Theorem I.4: Estimation of the Global Gradient
  • proof
  • Lemma I.5: Norm of the Forward Gradient
  • proof
  • Theorem I.6
  • proof