LoRA: Low-Rank Adaptation of Large Language Models | AGIDaily
AGI Daily
资讯日报词条论文人物新创
返回论文列表
Abstract1 IntroductionTerminologies and Conventions2 Problem Statement3 Aren’t Existing Solutions Good Enough?Adapter Layers Introduce Inference LatencyDirectly Optimizing the Prompt is Hard4 Our Method4.1 Low-Rank-Parametrized Update Matrices4.2 Applying LoRA to Transformer5 Empirical Experiments5.1 Baselines5.2 RoBERTa base/large5.3 DeBERTa XXL5.4 GPT-2 medium/large5.5 Scaling up to GPT-3 175B6 Related Works7 Understanding the Low-Rank Updates7.1 Which Weight Matrices in Transformer Should We Apply LoRA to?7.2 What is the Optimal Rank $r$ for LoRA?7.3 How Does the Adaptation Matrix $\Delta W$ Compare to $W$?8 Conclusion and Future WorkReferencesAppendix A Large Language Models Still Need Parameter UpdatesAppendix B Inference Latency Introduced by Adapter LayersAppendix C Dataset DetailsAppendix D Hyperparameters Used in ExperimentsD.1 RoBERTaD.2 DeBERTaD.3 GPT-2D.4 GPT-3Appendix E Combining LoRA with Prefix TuningAppendix F Additional Empirical ExperimentsF.1 Additional Experiments on GPT-2F.2 Additional Experiments on GPT-3F.3 Low-Data RegimeAppendix G Measuring Similarity Between SubspacesAppendix H Additional Experiments on Low-Rank MatricesH.1 Correlation between LoRA ModulesH.2 Effect of $r$ on GPT-2H.3 Correlation between $W$ and $\Delta W$H.4 Amplification Factor
返回论文列表
目录

LoRA: Low-Rank Adaptation of Large Language Models

收录于 arXiv:2106.09685(Microsoft);ICLR 2022
打开论文来源

LoRA: Low-Rank Adaptation of Large Language Models

Edward Hu Thanks:  Equal contribution.    Yelong ShenPhillip Wallis Zeyuan Allen-ZhuYuanzhi LiShean WangLu WangWeizhu Chen Microsoft Corporation {edwardhu, yeshe, phwallis, zeyuana,yuanzhil, swang, luw, wzchen}@microsoft.comyuanzhil@andrew.cmu.edu (Version 2)

Abstract

An important paradigm of natural language processing consists of large-scale pre-training on general domain data and adaptation to particular tasks or domains. As we pre-train larger models, full fine-tuning, which retrains all model parameters, becomes less feasible. Using GPT-3 175B as an example – deploying independent instances of fine-tuned models, each with 175B parameters, is prohibitively expensive. We propose Low-Rank Adaptation, or LoRA, which freezes the pre-trained model weights and injects trainable rank decomposition matrices into each layer of the Transformer architecture, greatly reducing the number of trainable parameters for downstream tasks. Compared to GPT-3 175B fine-tuned with Adam, LoRA can reduce the number of trainable parameters by 10,000 times and the GPU memory requirement by 3 times. LoRA performs on-par or better than fine-tuning in model quality on RoBERTa, DeBERTa, GPT-2, and GPT-3, despite having fewer trainable parameters, a higher training throughput, and, unlike adapters, no additional inference latency. We also provide an empirical investigation into rank-deficiency in language model adaptation, which sheds light on the efficacy of LoRA. We release a package that facilitates the integration of LoRA with PyTorch models and provide our implementations and model checkpoints for RoBERTa, DeBERTa, and GPT-2 at https://github.com/microsoft/LoRA.

自然语言处理的一个重要范式是:在通用领域数据上大规模预训练,再适配到特定任务或领域。随着我们预训练更大的模型,重新训练全部模型参数的全量微调变得越来越不可行。以 GPT-3 175B 为例——部署各自拥有 175B 参数的独立微调实例,代价高得难以承受。我们提出 Low-Rank Adaptation(LoRA):冻结预训练模型权重,并向 Transformer 架构的每一层注入可训练的秩分解矩阵,从而大幅减少下游任务的可训练参数数量。相对用 Adam 微调的 GPT-3 175B,LoRA 可将可训练参数数减少约 10,000 倍,GPU 内存需求减少约 3 倍。尽管可训练参数更少、训练吞吐更高,且与 adapter 不同、不引入额外推理延迟,LoRA 在 RoBERTa、DeBERTa、GPT-2 与 GPT-3 上的模型质量仍与全量微调持平或更好。我们还对语言模型适配中的秩亏缺做了实证考察,以阐明 LoRA 有效性并对未来应用给出启示。我们发布便于把 LoRA 集成到 PyTorch 模型的软件包,并在 https://github.com/microsoft/LoRA 提供 RoBERTa、DeBERTa 与 GPT-2 的实现与模型检查点。

1 Introduction

Figure 1

Figure 1: Our reparametrization. We only train AAA and BBB.

图 1:我们的重参数化。只训练 AAA 与 BBB。

Many applications in natural language processing rely on adapting one large-scale, pre-trained language model to multiple downstream applications. Such adaptation is usually done via fine-tuning, which updates all the parameters of the pre-trained model. The major downside of fine-tuning is that the new model contains as many parameters as in the original model. As larger models are trained every few months, this changes from a mere “inconvenience” for GPT-2 (Radford et al. b) or RoBERTa large (Liu et al. 2019) to a critical deployment challenge for GPT-3 (Brown et al. 2020) with 175 billion trainable parameters.[^1]

自然语言处理的许多应用依赖把一个大规模预训练语言模型适配到多个下游应用。这种适配通常通过微调完成,即更新预训练模型的全部参数。微调的主要缺点是:新模型包含与原模型一样多的参数。随着每隔几个月就训练更大的模型,这对 GPT-2(Radford et al. b)或 RoBERTa large(Liu et al. 2019)还只是“不便”,对拥有 1750 亿可训练参数的 GPT-3(Brown et al. 2020)则变成关键部署挑战。[^1]

Many sought to mitigate this by adapting only some parameters or learning external modules for new tasks. This way, we only need to store and load a small number of task-specific parameters in addition to the pre-trained model for each task, greatly boosting the operational efficiency when deployed. However, existing techniques often introduce inference latency (Houlsby et al. 2019; Rebuffi et al. 2017) by extending model depth or reduce the model’s usable sequence length (Li & Liang 2021; Lester et al. 2021; Hambardzumyan et al. 2020; Liu et al. 2021) (Section 3). More importantly, these method often fail to match the fine-tuning baselines, posing a trade-off between efficiency and model quality.

许多人试图只适配部分参数,或为新任务学习外部模块来缓解这一问题。这样,对每个任务我们只需在预训练模型之外存储并加载少量任务特定参数,从而在部署时大幅提升运维效率。但现有技术往往通过加深模型引入推理延迟(Houlsby et al. 2019; Rebuffi et al. 2017),或缩短模型可用序列长度(Li & Liang 2021; Lester et al. 2021; Hambardzumyan et al. 2020; Liu et al. 2021)(第 3 节)。更重要的是,这些方法常常无法匹配微调基线,从而在效率与模型质量之间形成权衡。

We take inspiration from Li et al. 2018a; Aghajanyan et al. 2020 which show that the learned over-parametrized models in fact reside on a low intrinsic dimension. We hypothesize that the change in weights during model adaptation also has a low “intrinsic rank”, leading to our proposed Low-Rank Adaptation (LoRA) approach. LoRA allows us to train some dense layers in a neural network indirectly by optimizing rank decomposition matrices of the dense layers’ change during adaptation instead, while keeping the pre-trained weights frozen, as shown in Figure 1. Using GPT-3 175B as an example, we show that a very low rank (i.e., r in Figure 1 can be one or two) suffices even when the full rank (i.e., d) is as high as 12,288, making LoRA both storage- and compute-efficient.

我们受 Li et al. 2018a; Aghajanyan et al. 2020 启发:学得的过参数化模型实际上落在低本征维上。我们假设模型适配期间的权重变化也具有低“本征秩”,由此提出 Low-Rank Adaptation(LoRA)。如图 1 所示,LoRA 允许我们通过优化稠密层在适配期间变化量的秩分解矩阵,间接训练神经网络中的某些稠密层,同时保持预训练权重冻结。以 GPT-3 175B 为例,我们表明即便全秩(即 d)高达 12,288,极低的秩(即图 1 中的 r 可为 1 或 2)也已足够,从而使 LoRA 在存储与计算上都高效。

LoRA possesses several key advantages.

LoRA 具有若干关键优势。

  • • A pre-trained model can be shared and used to build many small LoRA modules for different tasks. We can freeze the shared model and efficiently switch tasks by replacing the matrices AAA and BBB in Figure 1, reducing the storage requirement and task-switching overhead significantly.
  • • 一个预训练模型可被共享,并为不同任务构建许多小型 LoRA 模块。我们可以冻结共享模型,通过替换图 1 中的矩阵 AAA 与 BBB 高效切换任务,显著降低存储需求与任务切换开销。
  • • LoRA makes training more efficient and lowers the hardware barrier to entry by up to 3 times when using adaptive optimizers since we do not need to calculate the gradients or maintain the optimizer states for most parameters. Instead, we only optimize the injected, much smaller low-rank matrices.
  • • LoRA 使训练更高效,并在使用自适应优化器时将硬件门槛最高降低约 3 倍:因为我们不必为大多数参数计算梯度或维护优化器状态,而只需优化注入的、小得多的低秩矩阵。
  • • Our simple linear design allows us to merge the trainable matrices with the frozen weights when deployed, introducing no inference latency compared to a fully fine-tuned model, by construction.
  • • 我们的简单线性设计允许在部署时把可训练矩阵与冻结权重合并,相对全量微调模型不引入推理延迟,这由构造保证。
  • • LoRA is orthogonal to many prior methods and can be combined with many of them, such as prefix-tuning. We provide an example in Appendix E.
  • • LoRA 与许多先前方法正交,并可与其中许多结合,例如 prefix-tuning。附录 E 给出一个例子。

Terminologies and Conventions

We make frequent references to the Transformer architecture and use the conventional terminologies for its dimensions. We call the input and output dimension size of a Transformer layer dmodeld_{model}dmodel​. We use WqW_{q}Wq​, WkW_{k}Wk​, WvW_{v}Wv​, and WoW_{o}Wo​ to refer to the query/key/value/output projection matrices in the self-attention module. WWW or W0W_{0}W0​ refers to a pre-trained weight matrix and ΔW\Delta WΔW its accumulated gradient update during adaptation. We use rrr to denote the rank of a LoRA module. We follow the conventions set out by (Vaswani et al. 2017; Brown et al. 2020) and use Adam (Loshchilov & Hutter 2019; Kingma & Ba 2017) for model optimization and use a Transformer MLP feedforward dimension dffn=4×dmodeld_{ffn}=4\times d_{model}dffn​=4×dmodel​.

Terminologies and Conventions

我们频繁引用 Transformer 架构,并对其维度使用常规术语。我们把 Transformer 层的输入与输出维数称为 dmodeld_{model}dmodel​。用 WqW_{q}Wq​、WkW_{k}Wk​、WvW_{v}Wv​ 与 WoW_{o}Wo​ 指自注意力模块中的 query/key/value/output 投影矩阵。WWW 或 W0W_{0}W0​ 指预训练权重矩阵,ΔW\Delta WΔW 指其在适配期间累积的梯度更新。用 rrr 表示 LoRA 模块的秩。我们遵循(Vaswani et al. 2017; Brown et al. 2020)的惯例,用 Adam(Loshchilov & Hutter 2019; Kingma & Ba 2017)做模型优化,并使用 Transformer MLP 前馈维 dffn=4×dmodeld_{ffn}=4\times d_{model}dffn​=4×dmodel​。

2 Problem Statement

While our proposal is agnostic to training objective, we focus on language modeling as our motivating use case. Below is a brief description of the language modeling problem and, in particular, the maximization of conditional probabilities given a task-specific prompt.

虽然我们的提议与训练目标无关,但我们以语言建模作为动机用例。以下简要描述语言建模问题,特别是给定任务特定提示时条件概率的最大化。

Suppose we are given a pre-trained autoregressive language model PΦ(y∣x)P_{\Phi}(y|x)PΦ​(y∣x) parametrized by Φ\PhiΦ. For instance, PΦ(y∣x)P_{\Phi}(y|x)PΦ​(y∣x) can be a generic multi-task learner such as GPT (Radford et al. b; Brown et al. 2020) based on the Transformer architecture (Vaswani et al. 2017). Consider adapting this pre-trained model to downstream conditional text generation tasks, such as summarization, machine reading comprehension (MRC), and natural language to SQL (NL2SQL). Each downstream task is represented by a training dataset of context-target pairs: Z={(xi,yi)}i=1,..,N\mathcal{Z}=\{(x_{i},y_{i})\}_{i=1,..,N}Z={(xi​,yi​)}i=1,..,N​, where both xix_{i}xi​ and yiy_{i}yi​ are sequences of tokens. For example, in NL2SQL, xix_{i}xi​ is a natural language query and yiy_{i}yi​ its corresponding SQL command; for summarization, xix_{i}xi​ is the content of an article and yiy_{i}yi​ its summary.

假设给定由 Φ\PhiΦ 参数化的预训练自回归语言模型 PΦ(y∣x)P_{\Phi}(y|x)PΦ​(y∣x)。例如,PΦ(y∣x)P_{\Phi}(y|x)PΦ​(y∣x) 可以是基于 Transformer 架构(Vaswani et al. 2017)的通用多任务学习器,如 GPT(Radford et al. b; Brown et al. 2020)。考虑把该预训练模型适配到下游条件文本生成任务,例如摘要、机器阅读理解(MRC)以及自然语言到 SQL(NL2SQL)。每个下游任务由上下文–目标对的训练数据集表示:Z={(xi,yi)}i=1,..,N\mathcal{Z}=\{(x_{i},y_{i})\}_{i=1,..,N}Z={(xi​,yi​)}i=1,..,N​,其中 xix_{i}xi​ 与 yiy_{i}yi​ 都是 token 序列。例如在 NL2SQL 中,xix_{i}xi​ 是自然语言查询,yiy_{i}yi​ 是对应 SQL 命令;对摘要,xix_{i}xi​ 是文章内容,yiy_{i}yi​ 是其摘要。

During full fine-tuning, the model is initialized to pre-trained weights Φ0\Phi_{0}Φ0​ and updated to Φ0+ΔΦ\Phi_{0}+\Delta\PhiΦ0​+ΔΦ by repeatedly following the gradient to maximize the conditional language modeling objective:

在全量微调中,模型初始化为预训练权重 Φ0\Phi_{0}Φ0​,并通过反复沿梯度上升最大化条件语言建模目标,更新为 Φ0+ΔΦ\Phi_{0}+\Delta\PhiΦ0​+ΔΦ:

max⁡Φ∑(x,y)∈Z∑t=1∣y∣log(PΦ(yt∣x,y<t))(1)\displaystyle\max_{\Phi}\sum_{(x,y)\in\mathcal{Z}}\sum_{t=1}^{|y|}\text{log}\left(P_{\Phi}(y_{t}|x,y_{<t})\right) \tag{1}Φmax​(x,y)∈Z∑​t=1∑∣y∣​log(PΦ​(yt​∣x,y<t​))(1)

One of the main drawbacks for full fine-tuning is that for each downstream task, we learn a different set of parameters ΔΦ\Delta\PhiΔΦ whose dimension ∣ΔΦ∣|\Delta\Phi|∣ΔΦ∣ equals ∣Φ0∣|\Phi_{0}|∣Φ0​∣. Thus, if the pre-trained model is large (such as GPT-3 with ∣Φ0∣≈175 Billion|\Phi_{0}|\approx 175\text{~Billion}∣Φ0​∣≈175 Billion), storing and deploying many independent instances of fine-tuned models can be challenging, if at all feasible.

全量微调的主要缺点之一是:对每个下游任务,我们学到一组不同的参数 ΔΦ\Delta\PhiΔΦ,其维数 ∣ΔΦ∣|\Delta\Phi|∣ΔΦ∣ 等于 ∣Φ0∣|\Phi_{0}|∣Φ0​∣。因此,若预训练模型很大(如 GPT-3,∣Φ0∣≈175 Billion|\Phi_{0}|\approx 175\text{~Billion}∣Φ0​∣≈175 Billion),存储并部署许多独立微调实例即便可行也极具挑战。

In this paper, we adopt a more parameter-efficient approach, where the task-specific parameter increment ΔΦ=ΔΦ(Θ)\Delta\Phi=\Delta\Phi(\Theta)ΔΦ=ΔΦ(Θ) is further encoded by a much smaller-sized set of parameters Θ\ThetaΘ with ∣Θ∣≪∣Φ0∣|\Theta|\ll|\Phi_{0}|∣Θ∣≪∣Φ0​∣. The task of finding ΔΦ\Delta\PhiΔΦ thus becomes optimizing over Θ\ThetaΘ:

本文采用更参数高效的方法:任务特定参数增量 ΔΦ=ΔΦ(Θ)\Delta\Phi=\Delta\Phi(\Theta)ΔΦ=ΔΦ(Θ) 进一步由规模小得多的参数集 Θ\ThetaΘ 编码,且 ∣Θ∣≪∣Φ0∣|\Theta|\ll|\Phi_{0}|∣Θ∣≪∣Φ0​∣。于是寻找 ΔΦ\Delta\PhiΔΦ 变为对 Θ\ThetaΘ 优化:

max⁡Θ∑(x,y)∈Z∑t=1∣y∣log⁡(pΦ0+ΔΦ(Θ)(yt∣x,y<t))(2)\displaystyle\max_{\Theta}\sum_{(x,y)\in\mathcal{Z}}\sum_{t=1}^{|y|}\log\left({p_{\Phi_{0}+\Delta\Phi(\Theta)}(y_{t}|x,y_{<t}})\right) \tag{2}Θmax​(x,y)∈Z∑​t=1∑∣y∣​log(pΦ0​+ΔΦ(Θ)​(yt​∣x,y<t​))(2)

In the subsequent sections, we propose to use a low-rank representation to encode ΔΦ\Delta\PhiΔΦ that is both compute- and memory-efficient. When the pre-trained model is GPT-3 175B, the number of trainable parameters ∣Θ∣|\Theta|∣Θ∣ can be as small as 0.01%0.01\%0.01% of ∣Φ0∣|\Phi_{0}|∣Φ0​∣.

后续章节中,我们提出用低秩表示编码 ΔΦ\Delta\PhiΔΦ,使其在计算与内存上都高效。当预训练模型为 GPT-3 175B 时,可训练参数数 ∣Θ∣|\Theta|∣Θ∣ 可小至 ∣Φ0∣|\Phi_{0}|∣Φ0​∣ 的 0.01%0.01\%0.01%。

3 Aren’t Existing Solutions Good Enough?

The problem we set out to tackle is by no means new. Since the inception of transfer learning, dozens of works have sought to make model adaptation more parameter- and compute-efficient. See Section 6 for a survey of some of the well-known works. Using language modeling as an example, there are two prominent strategies when it comes to efficient adaptations: adding adapter layers (Houlsby et al. 2019; Rebuffi et al. 2017; Pfeiffer et al. 2021; Rücklé et al. 2020) or optimizing some forms of the input layer activations (Li & Liang 2021; Lester et al. 2021; Hambardzumyan et al. 2020; Liu et al. 2021). However, both strategies have their limitations, especially in a large-scale and latency-sensitive production scenario.

我们着手解决的问题绝非全新。自迁移学习诞生以来,已有数十项工作试图使模型适配更参数高效与计算高效。第 6 节综述其中一些知名工作。以语言建模为例,高效适配有两条突出策略:加入 adapter 层(Houlsby et al. 2019; Rebuffi et al. 2017; Pfeiffer et al. 2021; Rücklé et al. 2020),或优化输入层激活的某些形式(Li & Liang 2021; Lester et al. 2021; Hambardzumyan et al. 2020; Liu et al. 2021)。但两条策略都有局限,尤其在大规模、对延迟敏感的生产场景中。

Adapter Layers Introduce Inference Latency

There are many variants of adapters. We focus on the original design by Houlsby et al. 2019 which has two adapter layers per Transformer block and a more recent one by  Lin et al. 2020 which has only one per block but with an additional LayerNorm (Ba et al. 2016). While one can reduce the overall latency by pruning layers or exploiting multi-task settings (Rücklé et al. 2020; Pfeiffer et al. 2021), there is no direct ways to bypass the extra compute in adapter layers. This seems like a non-issue since adapter layers are designed to have few parameters (sometimes <<<1% of the original model) by having a small bottleneck dimension, which limits the FLOPs they can add. However, large neural networks rely on hardware parallelism to keep the latency low, and adapter layers have to be processed sequentially. This makes a difference in the online inference setting where the batch size is typically as small as one. In a generic scenario without model parallelism, such as running inference on GPT-2 (Radford et al. b) medium on a single GPU, we see a noticeable increase in latency when using adapters, even with a very small bottleneck dimension (Table 1).

Adapter Layers Introduce Inference Latency

Adapter 有许多变体。我们聚焦 Houlsby et al. 2019 的原始设计(每个 Transformer 块两个 adapter 层),以及 Lin et al. 2020 更近的设计(每块仅一个,但额外有 LayerNorm(Ba et al. 2016))。虽然可通过剪枝层或利用多任务设定降低总体延迟(Rücklé et al. 2020; Pfeiffer et al. 2021),但没有直接办法绕过 adapter 层中的额外计算。这看似不是问题,因为 adapter 层通过很小的瓶颈维设计成参数很少(有时 <<<1% 原模型),从而限制它们能增加的 FLOPs。但大型神经网络依赖硬件并行保持低延迟,而 adapter 层必须顺序处理。这在 batch size 通常小到 1 的在线推理设定中会有差别。在无模型并行的一般场景中,例如在单 GPU 上对 GPT-2(Radford et al. b)medium 做推理,即便瓶颈维很小,使用 adapter 也会带来可察觉的延迟增加。

Batch Size 32 16 1
Sequence Length 512 256 128
∣Θ∣|\Theta|∣Θ∣ 0.5M 11M 11M
Fine-Tune/LoRA 1449.4±\pm±0.8 338.0±\pm±0.6 19.8±\pm±2.7
AdapterL\text{Adapter}^{\text{L}}AdapterL 1482.0±\pm±1.0 (+2.2%) 354.8±\pm±0.5 (+5.0%) 23.9±\pm±2.1 (+20.7%)
AdapterH\text{Adapter}^{\text{H}}AdapterH 1492.2±\pm±1.0 (+3.0%) 366.3±\pm±0.5 (+8.4%) 25.8±\pm±2.2 (+30.3%)

Table 1: Infernece latency of a single forward pass in GPT-2 medium measured in milliseconds, averaged over 100 trials. We use an NVIDIA Quadro RTX8000. “∣Θ∣|\Theta|∣Θ∣” denotes the number of trainable parameters in adapter layers. AdapterL\text{Adapter}^{\text{L}}AdapterL and AdapterH\text{Adapter}^{\text{H}}AdapterH are two variants of adapter tuning, which we describe in Section 5.1. The inference latency introduced by adapter layers can be significant in an online, short-sequence-length scenario. See the full study in Appendix B.

Batch Size 32 16 1
Sequence Length 512 256 128
∣Θ∣|\Theta|∣Θ∣ 0.5M 11M 11M
Fine-Tune/LoRA 1449.4±\pm±0.8 338.0±\pm±0.6 19.8±\pm±2.7
AdapterL\text{Adapter}^{\text{L}}AdapterL 1482.0±\pm±1.0 (+2.2%) 354.8±\pm±0.5 (+5.0%) 23.9±\pm±2.1 (+20.7%)
AdapterH\text{Adapter}^{\text{H}}AdapterH 1492.2±\pm±1.0 (+3.0%) 366.3±\pm±0.5 (+8.4%) 25.8±\pm±2.2 (+30.3%)

表 1:GPT-2 medium 单次前向的推理延迟(毫秒),100 次试验平均。使用 NVIDIA Quadro RTX8000。“∣Θ∣|\Theta|∣Θ∣”表示 adapter 层中可训练参数数。AdapterL\text{Adapter}^{\text{L}}AdapterL 与 AdapterH\text{Adapter}^{\text{H}}AdapterH 是第 5.1 节描述的两种 adapter tuning 变体。在在线、短序列场景中,adapter 层引入的推理延迟可能显著。完整研究见附录 B。

This problem gets worse when we need to shard the model as done in Shoeybi et al. 2020; Lepikhin et al. 2020, because the additional depth requires more synchronous GPU operations such as AllReduce and Broadcast, unless we store the adapter parameters redundantly many times.

当我们需要像 Shoeybi et al. 2020; Lepikhin et al. 2020 那样对模型做分片时,问题更糟:额外深度需要更多同步 GPU 操作(如 AllReduce 与 Broadcast),除非我们把 adapter 参数冗余存储许多份。

Directly Optimizing the Prompt is Hard

The other direction, as exemplified by prefix tuning (Li & Liang 2021), faces a different challenge. We observe that prefix tuning is difficult to optimize and that its performance changes non-monotonically in trainable parameters, confirming similar observations in the original paper. More fundamentally, reserving a part of the sequence length for adaptation necessarily reduces the sequence length available to process a downstream task, which we suspect makes tuning the prompt less performant compared to other methods. We defer the study on task performance to Section 5.

Directly Optimizing the Prompt is Hard

另一方向以 prefix tuning(Li & Liang 2021)为代表,面临不同挑战。我们观察到 prefix tuning 难以优化,且其表现随可训练参数非单调变化,这与原论文的类似观察一致。更根本的是,为适配预留一部分序列长度必然减少可用于处理下游任务的序列长度,我们怀疑这使得调 prompt 相对其他方法表现更弱。任务表现研究留到第 5 节。

4 Our Method

We describe the simple design of LoRA and its practical benefits. The principles outlined here apply to any dense layers in deep learning models, though we only focus on certain weights in Transformer language models in our experiments as the motivating use case.

我们描述 LoRA 的简单设计及其实际收益。这里概述的原则适用于深度学习模型中的任意稠密层,尽管实验中我们只聚焦 Transformer 语言模型中的某些权重作为动机用例。

4.1 Low-Rank-Parametrized Update Matrices

A neural network contains many dense layers which perform matrix multiplication. The weight matrices in these layers typically have full-rank. When adapting to a specific task, Aghajanyan et al. 2020 shows that the pre-trained language models have a low “instrisic dimension” and can still learn efficiently despite a random projection to a smaller subspace. Inspired by this, we hypothesize the updates to the weights also have a low “intrinsic rank” during adaptation. For a pre-trained weight matrix W0∈Rd×kW_{0}\in\mathbb{R}^{d\times k}W0​∈Rd×k, we constrain its update by representing the latter with a low-rank decomposition W0+ΔW=W0+BAW_{0}+\Delta W=W_{0}+BAW0​+ΔW=W0​+BA, where B∈Rd×r,A∈Rr×kB\in\mathbb{R}^{d\times r},A\in\mathbb{R}^{r\times k}B∈Rd×r,A∈Rr×k, and the rank r≪min⁡(d,k)r\ll\min(d,k)r≪min(d,k). During training, W0W_{0}W0​ is frozen and does not receive gradient updates, while AAA and BBB contain trainable parameters. Note both W0W_{0}W0​ and ΔW=BA\Delta W=BAΔW=BA are multiplied with the same input, and their respective output vectors are summed coordinate-wise. For h=W0xh=W_{0}xh=W0​x, our modified forward pass yields:

神经网络包含许多执行矩阵乘法的稠密层。这些层中的权重矩阵通常满秩。适配到特定任务时,Aghajanyan et al. 2020 表明预训练语言模型具有低“本征维”,即便随机投影到更小子空间仍能高效学习。受此启发,我们假设适配期间权重更新也具有低“本征秩”。对预训练权重矩阵 W0∈Rd×kW_{0}\in\mathbb{R}^{d\times k}W0​∈Rd×k,我们通过低秩分解约束其更新:W0+ΔW=W0+BAW_{0}+\Delta W=W_{0}+BAW0​+ΔW=W0​+BA,其中 B∈Rd×rB\in\mathbb{R}^{d\times r}B∈Rd×r,A∈Rr×kA\in\mathbb{R}^{r\times k}A∈Rr×k,且秩 r≪min⁡(d,k)r\ll\min(d,k)r≪min(d,k)。训练时 W0W_{0}W0​ 冻结、不接收梯度更新,而 AAA 与 BBB 含可训练参数。注意 W0W_{0}W0​ 与 ΔW=BA\Delta W=BAΔW=BA 都与同一输入相乘,各自输出向量按坐标相加。对 h=W0xh=W_{0}xh=W0​x,我们修改后的前向为:

h=W0x+ΔWx=W0x+BAx(3)h=W_{0}x+\Delta Wx=W_{0}x+BAx \tag{3}h=W0​x+ΔWx=W0​x+BAx(3)

We illustrate our reparametrization in Figure 1. We use a random Gaussian initialization for AAA and zero for BBB, so ΔW=BA\Delta W=BAΔW=BA is zero at the beginning of training. We then scale ΔWx\Delta WxΔWx by αr\frac{\alpha}{r}rα​, where α\alphaα is a constant in rrr. When optimizing with Adam, tuning α\alphaα is roughly the same as tuning the learning rate if we scale the initialization appropriately. As a result, we simply set α\alphaα to the first rrr we try and do not tune it. This scaling helps to reduce the need to retune hyperparameters when we vary rrr (Yang & Hu 2021).

我们在图 1 中说明重参数化。对 AAA 使用随机高斯初始化,对 BBB 置零,因而训练开始时 ΔW=BA\Delta W=BAΔW=BA 为零。随后把 ΔWx\Delta WxΔWx 按 αr\frac{\alpha}{r}rα​ 缩放,其中 α\alphaα 是相对 rrr 的常数。用 Adam 优化时,若适当缩放初始化,调节 α\alphaα 大致等同于调节学习率。因此我们简单把 α\alphaα 设为首次尝试的 rrr 且不再调它。该缩放有助于在改变 rrr 时减少重新调节超参的需要(Yang & Hu 2021)。

A Generalization of Full Fine-tuning.  A more general form of fine-tuning allows the training of a subset of the pre-trained parameters. LoRA takes a step further and does not require the accumulated gradient update to weight matrices to have full-rank during adaptation. This means that when applying LoRA to all weight matrices and training all biases[^2], we roughly recover the expressiveness of full fine-tuning by setting the LoRA rank rrr to the rank of the pre-trained weight matrices. In other words, as we increase the number of trainable parameters [^3], training LoRA roughly converges to training the original model, while adapter-based methods converges to an MLP and prefix-based methods to a model that cannot take long input sequences.

A Generalization of Full Fine-tuning. 更一般的微调形式允许训练预训练参数的一个子集。LoRA 更进一步,不要求适配期间权重矩阵的累积梯度更新满秩。这意味着:当对所有权重矩阵应用 LoRA 并训练所有偏置[^2] 时,通过把 LoRA 秩 rrr 设为预训练权重矩阵的秩,我们大致恢复全量微调的表达能力。换言之,随着可训练参数数增加[^3],训练 LoRA 大致收敛到训练原模型;而基于 adapter 的方法收敛到一个 MLP,基于 prefix 的方法收敛到无法接受长输入序列的模型。

No Additional Inference Latency.  When deployed in production, we can explicitly compute and store W=W0+BAW=W_{0}+BAW=W0​+BA and perform inference as usual. Note that both W0W_{0}W0​ and BABABA are in Rd×k\mathbb{R}^{d\times k}Rd×k. When we need to switch to another downstream task, we can recover W0W_{0}W0​ by subtracting BABABA and then adding a different B′A′B^{\prime}A^{\prime}B′A′, a quick operation with very little memory overhead. Critically, this guarantees that we do not introduce any additional latency during inference compared to a fine-tuned model by construction.

No Additional Inference Latency. 在生产部署时,我们可以显式计算并存储 W=W0+BAW=W_{0}+BAW=W0​+BA,并照常推理。注意 W0W_{0}W0​ 与 BABABA 都在 Rd×k\mathbb{R}^{d\times k}Rd×k 中。需要切换到另一下游任务时,可通过减去 BABABA 再加不同的 B′A′B^{\prime}A^{\prime}B′A′ 恢复 W0W_{0}W0​,这是内存开销很小的快速操作。关键的是,这由构造保证:相对微调模型,我们在推理时不引入任何额外延迟。

4.2 Applying LoRA to Transformer

In principle, we can apply LoRA to any subset of weight matrices in a neural network to reduce the number of trainable parameters. In the Transformer architecture, there are four weight matrices in the self-attention module (Wq,Wk,Wv,WoW_{q},W_{k},W_{v},W_{o}Wq​,Wk​,Wv​,Wo​) and two in the MLP module. We treat WqW_{q}Wq​ (or WkW_{k}Wk​, WvW_{v}Wv​) as a single matrix of dimension dmodel×dmodeld_{model}\times d_{model}dmodel​×dmodel​, even though the output dimension is usually sliced into attention heads. We limit our study to only adapting the attention weights for downstream tasks and freeze the MLP modules (so they are not trained in downstream tasks) both for simplicity and parameter-efficiency.We further study the effect on adapting different types of attention weight matrices in a Transformer in Section 7.1. We leave the empirical investigation of adapting the MLP layers, LayerNorm layers, and biases to a future work.

原则上,我们可对神经网络中任意权重矩阵子集应用 LoRA 以减少可训练参数数。在 Transformer 架构中,自注意力模块有四个权重矩阵(Wq,Wk,Wv,WoW_{q},W_{k},W_{v},W_{o}Wq​,Wk​,Wv​,Wo​),MLP 模块有两个。即便输出维通常切成注意力头,我们仍把 WqW_{q}Wq​(或 WkW_{k}Wk​、WvW_{v}Wv​)视为维数为 dmodel×dmodeld_{model}\times d_{model}dmodel​×dmodel​ 的单个矩阵。为简洁与参数效率,我们把研究限制为只适配注意力权重用于下游任务,并冻结 MLP 模块(因而下游任务中不训练它们)。我们在第 7.1 节进一步研究所适配的注意力权重矩阵类型的影响。把 MLP 层、LayerNorm 层与偏置也纳入适配的实证考察留待未来工作。

Practical Benefits and Limitations.  The most significant benefit comes from the reduction in memory and storage usage. For a large Transformer trained with Adam, we reduce that VRAM usage by up to 2/32/32/3 if r≪dmodelr\ll d_{model}r≪dmodel​ as we do not need to store the optimizer states for the frozen parameters. On GPT-3 175B, we reduce the VRAM consumption during training from 1.2TB to 350GB. With r=4r=4r=4 and only the query and value projection matrices being adapted, the checkpoint size is reduced by roughly 10,000×\times× (from 350GB to 35MB)[^4]. This allows us to train with significantly fewer GPUs and avoid I/O bottlenecks. Another benefit is that we can switch between tasks while deployed at a much lower cost by only swapping the LoRA weights as opposed to all the parameters. This allows for the creation of many customized models that can be swapped in and out on the fly on machines that store the pre-trained weights in VRAM. We also observe a 25% speedup during training on GPT-3 175B compared to full fine-tuning[^5] as we do not need to calculate the gradient for the vast majority of the parameters.

Practical Benefits and Limitations. 最显著收益来自内存与存储占用的降低。对用 Adam 训练的大型 Transformer,若 r≪dmodelr\ll d_{model}r≪dmodel​,由于不必为冻结参数存储优化器状态,我们最高可将 VRAM 占用降低约 2/32/32/3。在 GPT-3 175B 上,训练时 VRAM 消耗从 1.2TB 降到 350GB。以 r=4r=4r=4 且只适配 query 与 value 投影矩阵时,检查点大小约缩小 10,000×\times×(从 350GB 到 35MB)[^4]。这使我们能用显著更少的 GPU 训练并避免 I/O 瓶颈。另一收益是:部署时可仅交换 LoRA 权重而非全部参数,从而以低得多的代价在任务间切换。这允许创建许多定制模型,并在把预训练权重存于 VRAM 的机器上即时换入换出。我们还观察到:相对全量微调,在 GPT-3 175B 上训练加速约 25%[^5],因为不必为绝大多数参数计算梯度。

LoRA also has its limitations. For example, it is not straightforward to batch inputs to different tasks with different AAA and BBB in a single forward pass, if one chooses to absorb AAA and BBB into WWW to eliminate additional inference latency. Though it is possible to not merge the weights and dynamically choose the LoRA modules to use for samples in a batch for scenarios where latency is not critical.

LoRA 也有局限。例如,若选择把 AAA 与 BBB 吸收进 WWW 以消除额外推理延迟,则不易在单次前向中把使用不同 AAA、BBB 的不同任务输入批在一起。不过在延迟不关键的场景中,也可以不合并权重,并为 batch 中的样本动态选择所用的 LoRA 模块。

5 Empirical Experiments

We evaluate the downstream task performance of LoRA on RoBERTa (Liu et al. 2019), DeBERTa (He et al. 2021), and GPT-2 (Radford et al. b), before scaling up to GPT-3 175B (Brown et al. 2020). Our experiments cover a wide range of tasks, from natural language understanding (NLU) to generation (NLG). Specifically, we evaluate on the GLUE (Wang et al. 2019) benchmark for RoBERTa and DeBERTa. We follow the setup of Li & Liang 2021 on GPT-2 for a direct comparison and add WikiSQL (Zhong et al. 2017) (NL to SQL queries) and SAMSum (Gliwa et al. 2019) (conversation summarization) for large-scale experiments on GPT-3. See Appendix C for more details on the datasets we use. We use NVIDIA Tesla V100 for all experiments.

我们在 RoBERTa(Liu et al. 2019)、DeBERTa(He et al. 2021)与 GPT-2(Radford et al. b)上评估 LoRA 的下游任务表现,再扩展到 GPT-3 175B(Brown et al. 2020)。实验覆盖从自然语言理解(NLU)到生成(NLG)的广泛任务。具体地,对 RoBERTa 与 DeBERTa 我们在 GLUE(Wang et al. 2019)基准上评估。对 GPT-2 我们遵循 Li & Liang 2021 的设定以便直接比较,并为 GPT-3 上的大规模实验加入 WikiSQL(Zhong et al. 2017)(自然语言到 SQL)与 SAMSum(Gliwa et al. 2019)(对话摘要)。所用数据集更多细节见附录 C。全部实验使用 NVIDIA Tesla V100。

5.1 Baselines

To compare with other baselines broadly, we replicate the setups used by prior work and reuse their reported numbers whenever possible. This, however, means that some baselines might only appear in certain experiments.

为与其他基线广泛比较,我们复现先前工作使用的设定,并尽可能复用其报告数字。但这意味着某些基线可能只出现在部分实验中。

Fine-Tuning (FT) is a common approach for adaptation. During fine-tuning, the model is initialized to the pre-trained weights and biases, and all model parameters undergo gradient updates.A simple variant is to update only some layers while freezing others. We include one such baseline reported in prior work (Li & Liang 2021) on GPT-2, which adapts just the last two layers (FTTop2\textbf{FT}^{\textbf{Top2}}FTTop2).

Fine-Tuning (FT) 是常见的适配方法。微调时,模型初始化为预训练权重与偏置,全部模型参数接受梯度更新。简单变体是只更新某些层、冻结其余。我们纳入先前工作(Li & Liang 2021)在 GPT-2 上报告的一种基线:只适配最后两层(FTTop2\textbf{FT}^{\textbf{Top2}}FTTop2)。

Bias-only or BitFit is a baseline where we only train the bias vectors while freezing everything else. Contemporarily, this baseline has also been studied by BitFit (Zaken et al. 2021).

Bias-only or BitFit 是只训练偏置向量、冻结其余一切的基线。同期,该基线也被 BitFit(Zaken et al. 2021)研究。

Prefix-embedding tuning (PreEmbed) inserts special tokens among the input tokens. These special tokens have trainable word embeddings and are generally not in the model’s vocabulary. Where to place such tokens can have an impact on performance. We focus on “prefixing”, which prepends such tokens to the prompt, and “infixing”, which appends to the prompt; both are discussed in Li & Liang 2021. We use lpl_{p}lp​ (resp. lil_{i}li​) denote the number of prefix (resp. infix) tokens. The number of trainable parameters is ∣Θ∣=dmodel×(lp+li)|\Theta|=d_{model}\times(l_{p}+l_{i})∣Θ∣=dmodel​×(lp​+li​).

Prefix-embedding tuning (PreEmbed) 在输入 token 之间插入特殊 token。这些特殊 token 有可训练词嵌入,一般不在模型词表中。放置位置可影响表现。我们聚焦“prefixing”(把此类 token 加在提示前)与“infixing”(加在提示后);二者均在 Li & Liang 2021 中讨论。用 lpl_{p}lp​(或 lil_{i}li​)表示 prefix(或 infix)token 数。可训练参数数为 ∣Θ∣=dmodel×(lp+li)|\Theta|=d_{model}\times(l_{p}+l_{i})∣Θ∣=dmodel​×(lp​+li​)。

Prefix-layer tuning (PreLayer) is an extension to prefix-embedding tuning. Instead of just learning the word embeddings (or equivalently, the activations after the embedding layer) for some special tokens, we learn the activations after every Transformer layer. The activations computed from previous layers are simply replaced by trainable ones. The resulting number of trainable parameters is ∣Θ∣=L×dmodel×(lp+li)|\Theta|=L\times d_{model}\times(l_{p}+l_{i})∣Θ∣=L×dmodel​×(lp​+li​), where LLL is the number of Transformer layers.

Prefix-layer tuning (PreLayer) 是对 prefix-embedding tuning 的扩展。不只学习某些特殊 token 的词嵌入(或等价地,嵌入层后的激活),我们学习每个 Transformer 层后的激活。由前层算出的激活直接被可训练激活替换。所得可训练参数数为 ∣Θ∣=L×dmodel×(lp+li)|\Theta|=L\times d_{model}\times(l_{p}+l_{i})∣Θ∣=L×dmodel​×(lp​+li​),其中 LLL 为 Transformer 层数。

Adapter tuning as proposed in Houlsby et al. 2019 inserts adapter layers between the self-attention module (and the MLP module) and the subsequent residual connection. There are two fully connected layers with biases in an adapter layer with a nonlinearity in between. We call this original design AdapterH\textbf{Adapter}^{\textbf{H}}AdapterH. Recently, Lin et al. 2020 proposed a more efficient design with the adapter layer applied only after the MLP module and after a LayerNorm. We call it AdapterL\textbf{Adapter}^{\textbf{L}}AdapterL. This is very similar to another deign proposed in Pfeiffer et al. 2021, which we call AdapterP\textbf{Adapter}^{\textbf{P}}AdapterP. We also include another baseline call AdapterDrop (Rücklé et al. 2020) which drops some adapter layers for greater efficiency (AdapterD\textbf{Adapter}^{\textbf{D}}AdapterD). We cite numbers from prior works whenever possible to maximize the number of baselines we compare with; they are in rows with an asterisk (*) in the first column. In all cases, we have ∣Θ∣=L^Adpt×(2×dmodel×r+r+dmodel)+2×L^LN×dmodel|\Theta|=\hat{L}_{Adpt}\times(2\times d_{model}\times r+r+d_{model})+2\times\hat{L}_{LN}\times d_{model}∣Θ∣=L^Adpt​×(2×dmodel​×r+r+dmodel​)+2×L^LN​×dmodel​ where L^Adpt\hat{L}_{Adpt}L^Adpt​ is the number of adapter layers and L^LN\hat{L}_{LN}L^LN​ the number of trainable LayerNorms (e.g., in AdapterL\text{Adapter}^{\text{L}}AdapterL).

Adapter tuning 如 Houlsby et al. 2019 所提,在自注意力模块(以及 MLP 模块)与随后的残差连接之间插入 adapter 层。adapter 层中有两个带偏置的全连接层,中间有非线性。我们称该原始设计为 AdapterH\textbf{Adapter}^{\textbf{H}}AdapterH。近来 Lin et al. 2020 提出更高效设计:adapter 层仅加在 MLP 模块之后、并在 LayerNorm 之后。我们称之为 AdapterL\textbf{Adapter}^{\textbf{L}}AdapterL。这与 Pfeiffer et al. 2021 提出的另一设计非常相似,我们称之为 AdapterP\textbf{Adapter}^{\textbf{P}}AdapterP。我们还纳入另一基线 AdapterDrop(Rücklé et al. 2020),它丢掉部分 adapter 层以换取更高效率(AdapterD\textbf{Adapter}^{\textbf{D}}AdapterD)。为最大化比较的基线数量,我们尽可能引用先前工作数字;它们位于第一列带星号 (*) 的行。在所有情形中,∣Θ∣=L^Adpt×(2×dmodel×r+r+dmodel)+2×L^LN×dmodel|\Theta|=\hat{L}_{Adpt}\times(2\times d_{model}\times r+r+d_{model})+2\times\hat{L}_{LN}\times d_{model}∣Θ∣=L^Adpt​×(2×dmodel​×r+r+dmodel​)+2×L^LN​×dmodel​,其中 L^Adpt\hat{L}_{Adpt}L^Adpt​ 为 adapter 层数,L^LN\hat{L}_{LN}L^LN​ 为可训练 LayerNorm 数。

LoRA adds trainable pairs of rank decomposition matrices in parallel to existing weight matrices. As mentioned in Section 4.2, we only apply LoRA to WqW_{q}Wq​ and WvW_{v}Wv​ in most experiments for simplicity. The number of trainable parameters is determined by the rank rrr and the shape of the original weights: ∣Θ∣=2×L^LoRA×dmodel×r|\Theta|=2\times\hat{L}_{LoRA}\times d_{model}\times r∣Θ∣=2×L^LoRA​×dmodel​×r, where L^LoRA\hat{L}_{LoRA}L^LoRA​ is the number of weight matrices we apply LoRA to.

LoRA 与现有权重矩阵并行地加入可训练的秩分解矩阵对。如第 4.2 节所述,多数实验中为简洁只对 WqW_{q}Wq​ 与 WvW_{v}Wv​ 应用 LoRA。可训练参数数由秩 rrr 与原权重形状决定:∣Θ∣=2×L^LoRA×dmodel×r|\Theta|=2\times\hat{L}_{LoRA}\times d_{model}\times r∣Θ∣=2×L^LoRA​×dmodel​×r,其中 L^LoRA\hat{L}_{LoRA}L^LoRA​ 是我们应用 LoRA 的权重矩阵数。

5.2 RoBERTa base/large

Model & Method # Trainable
Parameters MNLI SST-2 MRPC CoLA QNLI QQP RTE STS-B Avg.
RoBbase\text{RoB}_{\text{base}}RoBbase​ (FT)* 125.0M 87.6 94.8 90.2 63.6 92.8 91.9 78.7 91.2 86.4
RoBbase\text{RoB}_{\text{base}}RoBbase​ (BitFit)* 0.1M 84.7 93.7 92.7 62.0 91.8 84.0 81.5 90.8 85.2
RoBbase\text{RoB}_{\text{base}}RoBbase​ (AdptD\text{Adpt}^{\text{D}}AdptD)* 0.3M 87.1±\pm±.0 94.2±\pm±.1 88.5±\pm±1.1 60.8±\pm±.4 93.1±\pm±.1 90.2±\pm±.0 71.5±\pm±2.7 89.7±\pm±.3 84.4
RoBbase\text{RoB}_{\text{base}}RoBbase​ (AdptD\text{Adpt}^{\text{D}}AdptD)* 0.9M 87.3±\pm±.1 94.7±\pm±.3 88.4±\pm±.1 62.6±\pm±.9 93.0±\pm±.2 90.6±\pm±.0 75.9±\pm±2.2 90.3±\pm±.1 85.4
RoBbase\text{RoB}_{\text{base}}RoBbase​ (LoRA) 0.3M 87.5±\pm±.3 95.1±\pm±.2 89.7±\pm±.7 63.4±\pm±1.2 93.3±\pm±.3 90.8±\pm±.1 86.6±\pm±.7 91.5±\pm±.2 87.2
RoBlarge\text{RoB}_{\text{large}}RoBlarge​ (FT)* 355.0M 90.2 96.4 90.9 68.0 94.7 92.2 86.6 92.4 88.9
RoBlarge\text{RoB}_{\text{large}}RoBlarge​ (LoRA) 0.8M 90.6±\pm±.2 96.2±\pm±.5 90.9±\pm±1.2 68.2±\pm±1.9 94.9±\pm±.3 91.6±\pm±.1 87.4±\pm±2.5 92.6±\pm±.2 89.0
RoBlarge\text{RoB}_{\text{large}}RoBlarge​ (AdptP\text{Adpt}^{\text{P}}AdptP)†\dagger† 3.0M 90.2±\pm±.3 96.1±\pm±.3 90.2±\pm±.7 68.3±\pm±1.0 94.8±\pm±.2 91.9±\pm±.1 83.8±\pm±2.9 92.1±\pm±.7 88.4
RoBlarge\text{RoB}_{\text{large}}RoBlarge​ (AdptP\text{Adpt}^{\text{P}}AdptP)†\dagger† 0.8M 90.5±\pm±.3 96.6±\pm±.2 89.7±\pm±1.2 67.8±\pm±2.5 94.8±\pm±.3 91.7±\pm±.2 80.1±\pm±2.9 91.9±\pm±.4 87.9
RoBlarge\text{RoB}_{\text{large}}RoBlarge​ (AdptH\text{Adpt}^{\text{H}}AdptH)†\dagger† 6.0M 89.9±\pm±.5 96.2±\pm±.3 88.7±\pm±2.9 66.5±\pm±4.4 94.7±\pm±.2 92.1±\pm±.1 83.4±\pm±1.1 91.0±\pm±1.7 87.8
RoBlarge\text{RoB}_{\text{large}}RoBlarge​ (AdptH\text{Adpt}^{\text{H}}AdptH)†\dagger† 0.8M 90.3±\pm±.3 96.3±\pm±.5 87.7±\pm±1.7 66.3±\pm±2.0 94.7±\pm±.2 91.5±\pm±.1 72.9±\pm±2.9 91.5±\pm±.5 86.4
RoBlarge\text{RoB}_{\text{large}}RoBlarge​ (LoRA)†\dagger† 0.8M 90.6±\pm±.2 96.2±\pm±.5 90.2±\pm±1.0 68.2±\pm±1.9 94.8±\pm±.3 91.6±\pm±.2 85.2±\pm±1.1 92.3±\pm±.5 88.6
DeBXXL\text{DeB}_{\text{XXL}}DeBXXL​ (FT)* 1500.0M 91.8 97.2 92.0 72.0 96.0 92.7 93.9 92.9 91.1
DeBXXL\text{DeB}_{\text{XXL}}DeBXXL​ (LoRA) 4.7M 91.9±\pm±.2 96.9±\pm±.2 92.6±\pm±.6 72.4±\pm±1.1 96.0±\pm±.1 92.9±\pm±.1 94.9±\pm±.4 93.0±\pm±.2 91.3

Table 2: RoBERTabase\text{RoBERTa}_{\text{base}}RoBERTabase​, RoBERTalarge\text{RoBERTa}_{\text{large}}RoBERTalarge​, and DeBERTaXXL\text{DeBERTa}_{\text{XXL}}DeBERTaXXL​ with different adaptation methods on the GLUE benchmark. We report the overall (matched and mismatched) accuracy for MNLI, Matthew’s correlation for CoLA, Pearson correlation for STS-B, and accuracy for other tasks. Higher is better for all metrics. * indicates numbers published in prior works. †\dagger† indicates runs configured in a setup similar to Houlsby et al. 2019 for a fair comparison.

表 2:RoBERTa base/large 在 GLUE 上不同适配方法的结果(数字与模型名保留)。

Model & Method # Trainable
Parameters MNLI SST-2 MRPC CoLA QNLI QQP RTE STS-B Avg.
RoBbase\text{RoB}_{\text{base}}RoBbase​ (FT)* 125.0M 87.6 94.8 90.2 63.6 92.8 91.9 78.7 91.2 86.4
RoBbase\text{RoB}_{\text{base}}RoBbase​ (BitFit)* 0.1M 84.7 93.7 92.7 62.0 91.8 84.0 81.5 90.8 85.2
RoBbase\text{RoB}_{\text{base}}RoBbase​ (AdptD\text{Adpt}^{\text{D}}AdptD)* 0.3M 87.1±\pm±.0 94.2±\pm±.1 88.5±\pm±1.1 60.8±\pm±.4 93.1±\pm±.1 90.2±\pm±.0 71.5±\pm±2.7 89.7±\pm±.3 84.4
RoBbase\text{RoB}_{\text{base}}RoBbase​ (AdptD\text{Adpt}^{\text{D}}AdptD)* 0.9M 87.3±\pm±.1 94.7±\pm±.3 88.4±\pm±.1 62.6±\pm±.9 93.0±\pm±.2 90.6±\pm±.0 75.9±\pm±2.2 90.3±\pm±.1 85.4
RoBbase\text{RoB}_{\text{base}}RoBbase​ (LoRA) 0.3M 87.5±\pm±.3 95.1±\pm±.2 89.7±\pm±.7 63.4±\pm±1.2 93.3±\pm±.3 90.8±\pm±.1 86.6±\pm±.7 91.5±\pm±.2 87.2
RoBlarge\text{RoB}_{\text{large}}RoBlarge​ (FT)* 355.0M 90.2 96.4 90.9 68.0 94.7 92.2 86.6 92.4 88.9
RoBlarge\text{RoB}_{\text{large}}RoBlarge​ (LoRA) 0.8M 90.6±\pm±.2 96.2±\pm±.5 90.9±\pm±1.2 68.2±\pm±1.9 94.9±\pm±.3 91.6±\pm±.1 87.4±\pm±2.5 92.6±\pm±.2 89.0
RoBlarge\text{RoB}_{\text{large}}RoBlarge​ (AdptP\text{Adpt}^{\text{P}}AdptP)†\dagger† 3.0M 90.2±\pm±.3 96.1±\pm±.3 90.2±\pm±.7 68.3±\pm±1.0 94.8±\pm±.2 91.9±\pm±.1 83.8±\pm±2.9 92.1±\pm±.7 88.4
RoBlarge\text{RoB}_{\text{large}}RoBlarge​ (AdptP\text{Adpt}^{\text{P}}AdptP)†\dagger† 0.8M 90.5±\pm±.3 96.6±\pm±.2 89.7±\pm±1.2 67.8±\pm±2.5 94.8±\pm±.3 91.7±\pm±.2 80.1±\pm±2.9 91.9±\pm±.4 87.9
RoBlarge\text{RoB}_{\text{large}}RoBlarge​ (AdptH\text{Adpt}^{\text{H}}AdptH)†\dagger† 6.0M 89.9±\pm±.5 96.2±\pm±.3 88.7±\pm±2.9 66.5±\pm±4.4 94.7±\pm±.2 92.1±\pm±.1 83.4±\pm±1.1 91.0±\pm±1.7 87.8
RoBlarge\text{RoB}_{\text{large}}RoBlarge​ (AdptH\text{Adpt}^{\text{H}}AdptH)†\dagger† 0.8M 90.3±\pm±.3 96.3±\pm±.5 87.7±\pm±1.7 66.3±\pm±2.0 94.7±\pm±.2 91.5±\pm±.1 72.9±\pm±2.9 91.5±\pm±.5 86.4
RoBlarge\text{RoB}_{\text{large}}RoBlarge​ (LoRA)†\dagger† 0.8M 90.6±\pm±.2 96.2±\pm±.5 90.2±\pm±1.0 68.2±\pm±1.9 94.8±\pm±.3 91.6±\pm±.2 85.2±\pm±1.1 92.3±\pm±.5 88.6
DeBXXL\text{DeB}_{\text{XXL}}DeBXXL​ (FT)* 1500.0M 91.8 97.2 92.0 72.0 96.0 92.7 93.9 92.9 91.1
DeBXXL\text{DeB}_{\text{XXL}}DeBXXL​ (LoRA) 4.7M 91.9±\pm±.2 96.9±\pm±.2 92.6±\pm±.6 72.4±\pm±1.1 96.0±\pm±.1 92.9±\pm±.1 94.9±\pm±.4 93.0±\pm±.2 91.3

Table 2: RoBERTabase\text{RoBERTa}_{\text{base}}RoBERTabase​, RoBERTalarge\text{RoBERTa}_{\text{large}}RoBERTalarge​, and DeBERTaXXL\text{DeBERTa}_{\text{XXL}}DeBERTaXXL​ with different adaptation methods on the GLUE benchmark. We report the overall (matched and mismatched) accuracy for MNLI, Matthew’s correlation for CoLA, Pearson correlation for STS-B, and accuracy for other tasks. Higher is better for all metrics. * indicates numbers published in prior works. †\dagger† indicates runs configured in a setup similar to Houlsby et al. 2019 for a fair comparison.

RoBERTa (Liu et al. 2019) optimized the pre-training recipe originally proposed in BERT (Devlin et al. 2019a) and boosted the latter’s task performance without introducing many more trainable parameters. While RoBERTa has been overtaken by much larger models on NLP leaderboards such as the GLUE benchmark (Wang et al. 2019) in recent years, it remains a competitive and popular pre-trained model for its size among practitioners. We take the pre-trained RoBERTa base (125M) and RoBERTa large (355M) from the HuggingFace Transformers library (Wolf et al. 2020) and evaluate the performance of different efficient adaptation approaches on tasks from the GLUE benchmark. We also replicate Houlsby et al. 2019 and Pfeiffer et al. 2021 according to their setup. To ensure a fair comparison, we make two crucial changes to how we evaluate LoRA when comparing with adapters. First, we use the same batch size for all tasks and use a sequence length of 128 to match the adapter baselines. Second, we initialize the model to the pre-trained model for MRPC, RTE, and STS-B, not a model already adapted to MNLI like the fine-tuning baseline. Runs following this more restricted setup from Houlsby et al. 2019 are labeled with †\dagger†. The result is presented in Table 2 (Top Three Sections). See Section D.1 for details on the hyperparameters used.

RoBERTa(Liu et al. 2019)优化了 BERT(Devlin et al. 2019a)最初提出的预训练配方,在不引入许多额外可训练参数的情况下提升了后者的任务表现。尽管近年来 RoBERTa 已被更大模型在 GLUE 等 NLP 排行榜上超越,但就体量而言,它在从业者中仍是有竞争力且流行的预训练模型。我们从 HuggingFace Transformers 库(Wolf et al. 2020)取预训练 RoBERTa base(125M)与 RoBERTa large(355M),在 GLUE 基准任务上评估不同高效适配方法的表现。我们还按各自设定复现 Houlsby et al. 2019 与 Pfeiffer et al. 2021。为保证公平比较,与 adapter 比较时我们对 LoRA 评估做两处关键改动。第一,所有任务使用相同 batch size,序列长度 128,以匹配 adapter 基线。第二,对 MRPC、RTE 与 STS-B,模型初始化为预训练模型,而非像微调基线那样已适配到 MNLI 的模型。

5.3 DeBERTa XXL

DeBERTa (He et al. 2021) is a more recent variant of BERT that is trained on a much larger scale and performs very competitively on benchmarks such as GLUE (Wang et al. 2019) and SuperGLUE (Wang et al. 2020). We evaluate if LoRA can still match the performance of a fully fine-tuned DeBERTa XXL (1.5B) on GLUE. The result is presented in Table 2 (Bottom Section). See Section D.2 for details on the hyperparameters used.

DeBERTa(He et al. 2021)是 BERT 更近的变体,以更大尺度训练,并在 GLUE(Wang et al. 2019)与 SuperGLUE(Wang et al. 2020)等基准上表现极具竞争力。我们评估 LoRA 能否在 GLUE 上仍匹配全量微调 DeBERTa XXL(1.5B)的表现。结果见表 2(下段)。所用超参细节见第 D.2 节。

5.4 GPT-2 medium/large

Having shown that LoRA can be a competitive alternative to full fine-tuning on NLU, we hope to answer if LoRA still prevails on NLG models, such as GPT-2 medium and large (Radford et al. b). We keep our setup as close as possible to Li & Liang 2021 for a direct comparison. Due to space constraint, we only present our result on E2E NLG Challenge (Table 3) in this section. See Section F.1 for results on WebNLG (Gardent et al. 2017) and DART (Nan et al. 2020). We include a list of the hyperparameters used in Section D.3.

在表明 LoRA 可作为 NLU 上全量微调的有竞争力替代后,我们希望回答:LoRA 在 NLG 模型(如 GPT-2 medium 与 large(Radford et al. b))上是否仍然占优。我们尽可能保持与 Li & Liang 2021 接近的设定以便直接比较。受篇幅限制,本节只给出 E2E NLG Challenge 结果(表 3)。WebNLG 与 DART 的额外结果见第 F.1 节(表 10–11)。

Model & Method # Trainable E2E NLG Challenge
Parameters BLEU NIST MET ROUGE-L CIDEr
GPT-2 M (FT)* 354.92M 68.2 8.62 46.2 71.0 2.47
GPT-2 M (AdapterL\text{Adapter}^{\text{L}}AdapterL)* 0.37M 66.3 8.41 45.0 69.8 2.40
GPT-2 M (AdapterL\text{Adapter}^{\text{L}}AdapterL)* 11.09M 68.9 8.71 46.1 71.3 2.47
GPT-2 M (AdapterH\text{Adapter}^{\text{H}}AdapterH) 11.09M 67.3±\pm±.6 8.50±\pm±.07 46.0±\pm±.2 70.7±\pm±.2 2.44±\pm±.01
GPT-2 M (FTTop2\text{FT}^{\text{Top2}}FTTop2)* 25.19M 68.1 8.59 46.0 70.8 2.41
GPT-2 M (PreLayer)* 0.35M 69.7 8.81 46.1 71.4 2.49
GPT-2 M (LoRA) 0.35M 70.4±\pm±.1 8.85±\pm±.02 46.8±\pm±.2 71.8±\pm±.1 2.53±\pm±.02
GPT-2 L (FT)* 774.03M 68.5 8.78 46.0 69.9 2.45
GPT-2 L (AdapterL\text{Adapter}^{\text{L}}AdapterL) 0.88M 69.1±\pm±.1 8.68±\pm±.03 46.3±\pm±.0 71.4±\pm±.2 2.49±\pm±.0
GPT-2 L (AdapterL\text{Adapter}^{\text{L}}AdapterL) 23.00M 68.9±\pm±.3 8.70±\pm±.04 46.1±\pm±.1 71.3±\pm±.2 2.45±\pm±.02
GPT-2 L (PreLayer)* 0.77M 70.3 8.85 46.2 71.7 2.47
GPT-2 L (LoRA) 0.77M 70.4±\pm±.1 8.89±\pm±.02 46.8±\pm±.2 72.0±\pm±.2 2.47±\pm±.02

Table 3: GPT-2 medium (M) and large (L) with different adaptation methods on the E2E NLG Challenge. For all metrics, higher is better. LoRA outperforms several baselines with comparable or fewer trainable parameters. Confidence intervals are shown for experiments we ran. * indicates numbers published in prior works.

Model & Method # Trainable E2E NLG Challenge
Parameters BLEU NIST MET ROUGE-L CIDEr
GPT-2 M (FT)* 354.92M 68.2 8.62 46.2 71.0 2.47
GPT-2 M (AdapterL\text{Adapter}^{\text{L}}AdapterL)* 0.37M 66.3 8.41 45.0 69.8 2.40
GPT-2 M (AdapterL\text{Adapter}^{\text{L}}AdapterL)* 11.09M 68.9 8.71 46.1 71.3 2.47
GPT-2 M (AdapterH\text{Adapter}^{\text{H}}AdapterH) 11.09M 67.3±\pm±.6 8.50±\pm±.07 46.0±\pm±.2 70.7±\pm±.2 2.44±\pm±.01
GPT-2 M (FTTop2\text{FT}^{\text{Top2}}FTTop2)* 25.19M 68.1 8.59 46.0 70.8 2.41
GPT-2 M (PreLayer)* 0.35M 69.7 8.81 46.1 71.4 2.49
GPT-2 M (LoRA) 0.35M 70.4±\pm±.1 8.85±\pm±.02 46.8±\pm±.2 71.8±\pm±.1 2.53±\pm±.02
GPT-2 L (FT)* 774.03M 68.5 8.78 46.0 69.9 2.45
GPT-2 L (AdapterL\text{Adapter}^{\text{L}}AdapterL) 0.88M 69.1±\pm±.1 8.68±\pm±.03 46.3±\pm±.0 71.4±\pm±.2 2.49±\pm±.0
GPT-2 L (AdapterL\text{Adapter}^{\text{L}}AdapterL) 23.00M 68.9±\pm±.3 8.70±\pm±.04 46.1±\pm±.1 71.3±\pm±.2 2.45±\pm±.02
GPT-2 L (PreLayer)* 0.77M 70.3 8.85 46.2 71.7 2.47
GPT-2 L (LoRA) 0.77M 70.4±\pm±.1 8.89±\pm±.02 46.8±\pm±.2 72.0±\pm±.2 2.47±\pm±.02

表 3:GPT-2 medium (M) 与 large (L) 在 E2E NLG Challenge 上不同适配方法的结果。所有指标越高越好。LoRA 以可比或更少的可训练参数超过若干基线。置信区间对应我们运行的实验。* 表示先前工作发表的数字。

Model&Method # Trainable WikiSQL MNLI-m SAMSum
Parameters Acc. (%) Acc. (%) R1/R2/RL
GPT-3 (FT) 175,255.8M 73.8 89.5 52.0/28.0/44.5
GPT-3 (BitFit) 14.2M 71.3 91.0 51.3/27.4/43.5
GPT-3 (PreEmbed) 3.2M 63.1 88.6 48.3/24.2/40.5
GPT-3 (PreLayer) 20.2M 70.1 89.5 50.8/27.3/43.5
GPT-3 (AdapterH\text{Adapter}^{\text{H}}AdapterH) 7.1M 71.9 89.8 53.0/28.9/44.8
GPT-3 (AdapterH\text{Adapter}^{\text{H}}AdapterH) 40.1M 73.2 91.5 53.2/29.0/45.1
GPT-3 (LoRA) 4.7M 73.4 91.7 53.8/29.8/45.9
GPT-3 (LoRA) 37.7M 74.0 91.6 53.4/29.2/45.1

Table 4: Performance of different adaptation methods on GPT-3 175B. We report the logical form validation accuracy on WikiSQL, validation accuracy on MultiNLI-matched, and Rouge-1/2/L on SAMSum. LoRA performs better than prior approaches, including full fine-tuning. The results on WikiSQL have a fluctuation around ±0.5%\pm 0.5\%±0.5%, MNLI-m around ±0.1%\pm 0.1\%±0.1%, and SAMSum around ±0.2\pm 0.2±0.2/±0.2\pm 0.2±0.2/±0.1\pm 0.1±0.1 for the three metrics.

Model&Method # Trainable WikiSQL MNLI-m SAMSum
Parameters Acc. (%) Acc. (%) R1/R2/RL
GPT-3 (FT) 175,255.8M 73.8 89.5 52.0/28.0/44.5
GPT-3 (BitFit) 14.2M 71.3 91.0 51.3/27.4/43.5
GPT-3 (PreEmbed) 3.2M 63.1 88.6 48.3/24.2/40.5
GPT-3 (PreLayer) 20.2M 70.1 89.5 50.8/27.3/43.5
GPT-3 (AdapterH\text{Adapter}^{\text{H}}AdapterH) 7.1M 71.9 89.8 53.0/28.9/44.8
GPT-3 (AdapterH\text{Adapter}^{\text{H}}AdapterH) 40.1M 73.2 91.5 53.2/29.0/45.1
GPT-3 (LoRA) 4.7M 73.4 91.7 53.8/29.8/45.9
GPT-3 (LoRA) 37.7M 74.0 91.6 53.4/29.2/45.1

表 4:GPT-3 175B 上不同适配方法的表现。我们报告 WikiSQL 逻辑形式验证准确率、MultiNLI-matched 验证准确率,以及 SAMSum 上的 Rouge-1/2/L。LoRA 优于包括全量微调在内的先前方法。WikiSQL 结果波动约 ±0.5%\pm 0.5\%±0.5%,MNLI-m 约 ±0.1%\pm 0.1\%±0.1%,SAMSum 三项约 ±0.2\pm 0.2±0.2/±0.2\pm 0.2±0.2/±0.1\pm 0.1±0.1。

5.5 Scaling up to GPT-3 175B

As a final stress test for LoRA, we scale up to GPT-3 with 175 billion parameters. Due to the high training cost, we only report the typical standard deviation for a given task over random seeds, as opposed to providing one for every entry. See Section D.4 for details on the hyperparameters used.

作为对 LoRA 的最终压力测试,我们扩展到 1750 亿参数的 GPT-3。由于训练成本高,我们只报告给定任务上相对随机种子的典型标准差,而非为每个条目提供。所用超参见第 D.4 节。

As shown in Table 4, LoRA matches or exceeds the fine-tuning baseline on all three datasets. Note that not all methods benefit monotonically from having more trainable parameters, as shown in Figure 2. We observe a significant performance drop when we use more than 256 special tokens for prefix-embedding tuning or more than 32 special tokens for prefix-layer tuning. This corroborates similar observations in Li & Liang 2021. While a thorough investigation into this phenomenon is out-of-scope for this work, we suspect that having more special tokens causes the input distribution to shift further away from the pre-training data distribution. Separately, we investigate the performance of different adaptation approaches in the low-data regime in Section F.3.

如表 4 所示,LoRA 在全部三个数据集上匹配或超过微调基线。注意并非所有方法都随可训练参数增多而单调受益,见图 2。当我们为 prefix-embedding tuning 使用超过 256 个特殊 token,或为 prefix-layer tuning 使用超过 32 个特殊 token 时,观察到显著性能下降。这印证了 Li & Liang 2021 中的类似观察。对该现象的彻底研究超出本文范围,但我们怀疑更多特殊 token 会使输入分布进一步偏离预训练数据分布。另外,我们在第 F.3 节考察低数据设定下不同适配方法的表现。

Figure 2

Figure 2: GPT-3 175B validation accuracy vs. number of trainable parameters of several adaptation methods on WikiSQL and MNLI-matched. LoRA exhibits better scalability and task performance. See Section F.2 for more details on the plotted data points.

图 2:GPT-3 175B 上若干适配方法在 WikiSQL 与 MNLI-matched 上的验证准确率相对可训练参数数。LoRA 展现更好的可扩展性与任务表现。所绘数据点细节见第 F.2 节。

6 Related Works

Transformer Language Models.  Transformer (Vaswani et al. 2017) is a sequence-to-sequence architecture that makes heavy use of self-attention. Radford et al. a applied it to autoregressive language modeling by using a stack of Transformer decoders. Since then, Transformer-based language models have dominated NLP, achieving the state-of-the-art in many tasks. A new paradigm emerged with BERT (Devlin et al. 2019b) and GPT-2 (Radford et al. b) – both are large Transformer language models trained on a large amount of text – where fine-tuning on task-specific data after pre-training on general domain data provides a significant performance gain compared to training on task-specific data directly. Training larger Transformers generally results in better performance and remains an active research direction. GPT-3 (Brown et al. 2020) is the largest single Transformer language model trained to-date with 175B parameters.

Transformer Language Models. Transformer(Vaswani et al. 2017)是大量使用自注意力的序列到序列架构。Radford et al. a 通过堆叠 Transformer 解码器把它用于自回归语言建模。此后,基于 Transformer 的语言模型主导了 NLP,在许多任务上达到当时最好水平。BERT(Devlin et al. 2019b)与 GPT-2(Radford et al. b)——二者都是在大量文本上训练的大型 Transformer 语言模型——带来新范式:相对直接在任务数据上训练,先在通用领域预训练再在任务数据上微调能带来显著性能增益。训练更大的 Transformer 通常带来更好表现,仍是活跃研究方向。GPT-3(Brown et al. 2020)是当时训练过的最大单一 Transformer 语言模型,有 175B 参数。

Prompt Engineering and Fine-Tuning.  While GPT-3 175B can adapt its behavior with just a few additional training examples, the result depends heavily on the input prompt (Brown et al. 2020). This necessitates an empirical art of composing and formatting the prompt to maximize a model’s performance on a desired task, which is known as prompt engineering or prompt hacking. Fine-tuning retrains a model pre-trained on general domains to a specific task Devlin et al. 2019b; Radford et al. a. Variants of it include learning just a subset of the parameters Devlin et al. 2019b; Collobert & Weston 2008, yet practitioners often retrain all of them to maximize the downstream performance. However, the enormity of GPT-3 175B makes it challenging to perform fine-tuning in the usual way due to the large checkpoint it produces and the high hardware barrier to entry since it has the same memory footprint as pre-training.

Prompt Engineering and Fine-Tuning. 虽然 GPT-3 175B 只需少量额外训练样本就能适配其行为,结果严重依赖输入提示(Brown et al. 2020)。这催生了组合与格式化提示以最大化模型在目标任务上表现的经验艺术,称为 prompt engineering 或 prompt hacking。微调把在通用领域预训练的模型再训练到特定任务(Devlin et al. 2019b; Radford et al. a)。其变体包括只学习参数子集(Devlin et al. 2019b; Collobert & Weston 2008),但从业者常重训全部参数以最大化下游表现。然而 GPT-3 175B 的体量使其难以按常规方式微调:它产生巨大检查点,且内存占用与预训练相同,硬件门槛很高。

Parameter-Efficient Adaptation.  Many have proposed inserting adapter layers between existing layers in a neural network (Houlsby et al. 2019; Rebuffi et al. 2017; Lin et al. 2020). Our method uses a similar bottleneck structure to impose a low-rank constraint on the weight updates. The key functional difference is that our learned weights can be merged with the main weights during inference, thus not introducing any latency, which is not the case for the adapter layers (Section 3). A comtenporary extension of adapter is compacter (Mahabadi et al. 2021), which essentially parametrizes the adapter layers using Kronecker products with some predetermined weight sharing scheme. Similarly, combining LoRA with other tensor product-based methods could potentially improve its parameter efficiency, which we leave to future work. More recently, many proposed optimizing the input word embeddings in lieu of fine-tuning, akin to a continuous and differentiable generalization of prompt engineering (Li & Liang 2021; Lester et al. 2021; Hambardzumyan et al. 2020; Liu et al. 2021). We include comparisons with Li & Liang 2021 in our experiment section. However, this line of works can only scale up by using more special tokens in the prompt, which take up available sequence length for task tokens when positional embeddings are learned.

Parameter-Efficient Adaptation. 许多人提出在神经网络既有层之间插入 adapter 层(Houlsby et al. 2019; Rebuffi et al. 2017; Lin et al. 2020)。我们的方法使用类似瓶颈结构,对权重更新施加低秩约束。关键功能差别是:我们学到的权重可在推理时与主权重合并,因而不引入任何延迟,这对 adapter 层不成立(第 3 节)。同期的 adapter 扩展是 Compacter(Mahabadi et al. 2021),它本质上用带预定权重共享方案的 Kronecker 积参数化 adapter 层。类似地,把 LoRA 与其他基于张量积的方法结合有望进一步提升参数效率,我们留待未来工作。更近地,许多人提出优化输入词嵌入以代替微调,类似于 prompt engineering 的连续可微推广(Li & Liang 2021; Lester et al. 2021; Hambardzumyan et al. 2020; Liu et al. 2021)。实验部分纳入与 Li & Liang 2021 的比较。但这条工作线只能通过在提示中使用更多特殊 token 来扩展,而在学习位置嵌入时,这些 token 会占用可用于任务 token 的序列长度。

Low-Rank Structures in Deep Learning.  Low-rank structure is very common in machine learning. A lot of machine learning problems have certain intrinsic low-rank structure (Li et al. 2016; Cai et al. 2010; Li et al. 2018b; Grasedyck et al. 2013). Moreover, it is known that for many deep learning tasks, especially those with a heavily over-parametrized neural network, the learned neural network will enjoy low-rank properties after training (Oymak et al. 2019). Some prior works even explicitly impose the low-rank constraint when training the original neural network (Sainath et al. 2013; Povey et al. 2018; Zhang et al. 2014; Jaderberg et al. 2014; Zhao et al. 2016; Khodak et al. 2021; Denil et al. 2014); however, to the best of our knowledge, none of these works considers low-rank update to a frozen model for adaptation to downstream tasks. In theory literature, it is known that neural networks outperform other classical learning methods, including the corresponding (finite-width) neural tangent kernels (Allen-Zhu et al. 2019; Li & Liang 2018) when the underlying concept class has certain low-rank structure (Ghorbani et al. 2020; Allen-Zhu & Li 2019; Allen-Zhu & Li 2020a). Another theoretical result in Allen-Zhu & Li 2020b suggests that low-rank adaptations can be useful for adversarial training. In sum, we believe that our proposed low-rank adaptation update is well-motivated by the literature.

Low-Rank Structures in Deep Learning. 低秩结构在机器学习中非常常见。许多机器学习问题具有某种本征低秩结构(Li et al. 2016; Cai et al. 2010; Li et al. 2018b; Grasedyck et al. 2013)。此外,已知对许多深度学习任务——尤其是严重过参数化的神经网络——训练后学得的网络会具有低秩性质(Oymak et al. 2019)。一些先前工作甚至在训练原始神经网络时显式施加低秩约束(Sainath et al. 2013; Povey et al. 2018; Zhang et al. 2014; Jaderberg et al. 2014; Zhao et al. 2016; Khodak et al. 2021; Denil et al. 2014);但据我们所知,这些工作都未考虑对冻结模型做低秩更新以适配下游任务。在理论文献中,已知当底层概念类具有某些低秩结构时,神经网络优于包括对应(有限宽)神经正切核在内的其他经典学习方法(Allen-Zhu et al. 2019; Li & Liang 2018; Ghorbani et al. 2020; Allen-Zhu & Li 2019; Allen-Zhu & Li 2020a)。Allen-Zhu & Li 2020b 的另一理论结果暗示低秩适配可对抗训练有用。总之,我们相信所提出的低秩适配更新有充分的文献动机。

7 Understanding the Low-Rank Updates

Given the empirical advantage of LoRA, we hope to further explain the properties of the low-rank adaptation learned from downstream tasks. Note that the low-rank structure not only lowers the hardware barrier to entry which allows us to run multiple experiments in parallel, but also gives better interpretability of how the update weights are correlated with the pre-trained weights. We focus our study on GPT-3 175B, where we achieved the largest reduction of trainable parameters (up to 10,000×\times×) without adversely affecting task performances.

鉴于 LoRA 的经验优势,我们希望进一步解释从下游任务学到的低秩适配的性质。注意低秩结构不仅降低硬件门槛、使我们能并行跑多个实验,还使更新权重如何与预训练权重相关更具可解释性。我们把研究聚焦于 GPT-3 175B,在此我们实现了最大的可训练参数缩减(最高约 10,000×\times×)且未损害任务表现。

We perform a sequence of empirical studies to answer the following questions: 1) Given a parameter budget constraint, which subset of weight matrices in a pre-trained Transformer should we adapt to maximize downstream performance? 2) Is the “optimal” adaptation matrix ΔW\Delta WΔW really rank-deficient? If so, what is a good rank to use in practice? 3) What is the connection between ΔW\Delta WΔW and WWW? Does ΔW\Delta WΔW highly correlate with WWW? How large is ΔW\Delta WΔW comparing to WWW?

我们做一系列实证研究以回答下列问题:1)给定参数预算约束,应适配预训练 Transformer 中哪一子集的权重矩阵以最大化下游表现?2)“最优”适配矩阵 ΔW\Delta WΔW 是否真的秩亏?若是,实践中用多大的秩合适?3)ΔW\Delta WΔW 与 WWW 有何联系?ΔW\Delta WΔW 是否与 WWW 高度相关?相对 WWW,ΔW\Delta WΔW 有多大?

We believe that our answers to question (2) and (3) shed light on the fundamental principles of using pre-trained language models for downstream tasks, which is a critical topic in NLP.

我们相信对问题 (2) 与 (3) 的回答,有助于阐明把预训练语言模型用于下游任务的基本原理——这是 NLP 中的关键议题。

7.1 Which Weight Matrices in Transformer Should We Apply LoRA to?

Given a limited parameter budget, which types of weights should we adapt with LoRA to obtain the best performance on downstream tasks? As mentioned in Section 4.2, we only consider weight matrices in the self-attention module. We set a parameter budget of 18M (roughly 35MB if stored in FP16) on GPT-3 175B, which corresponds to r=8r=8r=8 if we adapt one type of attention weights or r=4r=4r=4 if we adapt two types, for all 96 layers. The result is presented in Table 5.

给定有限参数预算,应把 LoRA 用在哪类权重上,才能在下游任务上取得最佳表现?如第 4.2 节所述,我们只考虑自注意力模块中的权重矩阵。我们在 GPT-3 175B 上设定 18M 参数预算(以 FP16 存储约 35MB),对应:若适配一类注意力权重则 r=8r=8r=8,若适配两类则 r=4r=4r=4,覆盖全部 96 层。结果见表 5。

# of Trainable Parameters = 18M
Weight Type WqW_{q}Wq​ WkW_{k}Wk​ WvW_{v}Wv​ WoW_{o}Wo​ Wq,WkW_{q},W_{k}Wq​,Wk​ Wq,WvW_{q},W_{v}Wq​,Wv​ Wq,Wk,Wv,WoW_{q},W_{k},W_{v},W_{o}Wq​,Wk​,Wv​,Wo​
Rank rrr 8 8 8 8 4 4 2
WikiSQL (±0.5\pm 0.5±0.5%) 70.4 70.0 73.0 73.2 71.4 73.7 73.7
MultiNLI (±0.1\pm 0.1±0.1%) 91.0 90.8 91.0 91.3 91.3 91.3 91.7

Table 5: Validation accuracy on WikiSQL and MultiNLI after applying LoRA to different types of attention weights in GPT-3, given the same number of trainable parameters. Adapting both WqW_{q}Wq​ and WvW_{v}Wv​ gives the best performance overall. We find the standard deviation across random seeds to be consistent for a given dataset, which we report in the first column.

# of Trainable Parameters = 18M
Weight Type WqW_{q}Wq​ WkW_{k}Wk​ WvW_{v}Wv​ WoW_{o}Wo​ Wq,WkW_{q},W_{k}Wq​,Wk​ Wq,WvW_{q},W_{v}Wq​,Wv​ Wq,Wk,Wv,WoW_{q},W_{k},W_{v},W_{o}Wq​,Wk​,Wv​,Wo​
Rank rrr 8 8 8 8 4 4 2
WikiSQL (±0.5\pm 0.5±0.5%) 70.4 70.0 73.0 73.2 71.4 73.7 73.7
MultiNLI (±0.1\pm 0.1±0.1%) 91.0 90.8 91.0 91.3 91.3 91.3 91.7

表 5:在可训练参数数相同的条件下,对 GPT-3 不同类型注意力权重应用 LoRA 后在 WikiSQL 与 MultiNLI 上的验证准确率。同时适配 WqW_{q}Wq​ 与 WvW_{v}Wv​ 总体表现最好。我们发现给定数据集上跨随机种子的标准差一致,报告于第一列。

Note that putting all the parameters in ΔWq\Delta W_{q}ΔWq​ or ΔWk\Delta W_{k}ΔWk​ results in significantly lower performance, while adapting both WqW_{q}Wq​ and WvW_{v}Wv​ yields the best result. This suggests that even a rank of four captures enough information in ΔW\Delta WΔW such that it is preferable to adapt more weight matrices than adapting a single type of weights with a larger rank.

注意:把全部参数放在 ΔWq\Delta W_{q}ΔWq​ 或 ΔWk\Delta W_{k}ΔWk​ 上会导致显著更低的表现,而同时适配 WqW_{q}Wq​ 与 WvW_{v}Wv​ 给出最佳结果。这表明即便秩为四也足以捕捉 ΔW\Delta WΔW 中的足够信息,因而更宜适配更多权重矩阵,而非用更大的秩只适配单一类型权重。

7.2 What is the Optimal Rank rrr for LoRA?

We turn our attention to the effect of rank rrr on model performance. We adapt {Wq,Wv}\{W_{q},W_{v}\}{Wq​,Wv​}, {Wq,Wk,Wv,Wc}\{W_{q},W_{k},W_{v},W_{c}\}{Wq​,Wk​,Wv​,Wc​}, and just WqW_{q}Wq​ for a comparison.

我们转而关注秩 rrr 对模型表现的影响。我们适配 {Wq,Wv}\{W_{q},W_{v}\}{Wq​,Wv​}、{Wq,Wk,Wv,Wo}\{W_{q},W_{k},W_{v},W_{o}\}{Wq​,Wk​,Wv​,Wo​},以及仅 WqW_{q}Wq​ 以便比较。

Weight Type r=1r=1r=1 r=2r=2r=2 r=4r=4r=4 r=8r=8r=8 r=64r=64r=64
WikiSQL(±0.5\pm 0.5±0.5%) WqW_{q}Wq​ 68.8 69.6 70.5 70.4 70.0
Wq,WvW_{q},W_{v}Wq​,Wv​ 73.4 73.3 73.7 73.8 73.5
Wq,Wk,Wv,WoW_{q},W_{k},W_{v},W_{o}Wq​,Wk​,Wv​,Wo​ 74.1 73.7 74.0 74.0 73.9
MultiNLI (±0.1\pm 0.1±0.1%) WqW_{q}Wq​ 90.7 90.9 91.1 90.7 90.7
Wq,WvW_{q},W_{v}Wq​,Wv​ 91.3 91.4 91.3 91.6 91.4
Wq,Wk,Wv,WoW_{q},W_{k},W_{v},W_{o}Wq​,Wk​,Wv​,Wo​ 91.2 91.7 91.7 91.5 91.4

Table 6: Validation accuracy on WikiSQL and MultiNLI with different rank rrr. To our surprise, a rank as small as one suffices for adapting both WqW_{q}Wq​ and WvW_{v}Wv​ on these datasets while training WqW_{q}Wq​ alone needs a larger rrr. We conduct a similar experiment on GPT-2 in Section H.2.

Weight Type r=1r=1r=1 r=2r=2r=2 r=4r=4r=4 r=8r=8r=8 r=64r=64r=64
WikiSQL(±0.5\pm 0.5±0.5%) WqW_{q}Wq​ 68.8 69.6 70.5 70.4 70.0
Wq,WvW_{q},W_{v}Wq​,Wv​ 73.4 73.3 73.7 73.8 73.5
Wq,Wk,Wv,WoW_{q},W_{k},W_{v},W_{o}Wq​,Wk​,Wv​,Wo​ 74.1 73.7 74.0 74.0 73.9
MultiNLI (±0.1\pm 0.1±0.1%) WqW_{q}Wq​ 90.7 90.9 91.1 90.7 90.7
Wq,WvW_{q},W_{v}Wq​,Wv​ 91.3 91.4 91.3 91.6 91.4
Wq,Wk,Wv,WoW_{q},W_{k},W_{v},W_{o}Wq​,Wk​,Wv​,Wo​ 91.2 91.7 91.7 91.5 91.4

表 6:不同秩 rrr 在 WikiSQL 与 MultiNLI 上的验证准确率。令我们惊讶的是:在这些数据集上同时适配 WqW_{q}Wq​ 与 WvW_{v}Wv​ 时,小至 1 的秩已足够;而只训练 WqW_{q}Wq​ 需要更大的 rrr。我们在第 H.2 节对 GPT-2 做了类似实验。

Table 6shows that, surprisingly, LoRA already performs competitively with a very small rrr (more so for {Wq,Wv}\{W_{q},W_{v}\}{Wq​,Wv​} than just WqW_{q}Wq​). This suggests the update matrix ΔW\Delta WΔW could have a very small ‘‘intrinsic rank”.[^6] To further support this finding, we check the overlap of the subspaces learned by different choices of rrr and by different random seeds. We argue that increasing rrr does not cover a more meaningful subspace, which suggests that a low-rank adaptation matrix is sufficient.

表 6 表明:令人惊讶的是,极小的 rrr 已使 LoRA 表现具有竞争力(对 {Wq,Wv}\{W_{q},W_{v}\}{Wq​,Wv​} 尤甚于仅 WqW_{q}Wq​)。这暗示更新矩阵 ΔW\Delta WΔW 可能具有非常小的“本征秩”。[^6] 为进一步支持该发现,我们检查不同 rrr 选择以及不同随机种子所学子空间的重叠。我们主张增大 rrr 并不会覆盖更有意义的子空间,这表明低秩适配矩阵已足够。

Subspace similarity between different rrr.  Given Ar=8A_{r=8}Ar=8​ and Ar=64A_{r=64}Ar=64​ which are the learned adaptation matrices with rank r=8r=8r=8 and 646464 using the same pre-trained model, we perform singular value decomposition and obtain the right-singular unitary matrices UAr=8U_{A_{r=8}}UAr=8​​ and UAr=64U_{A_{r=64}}UAr=64​​.[^7] We hope to answer: how much of the subspace spanned by the top iii singular vectors in UAr=8U_{A_{r=8}}UAr=8​​ (for 1≤i≤81\leq i\leq 81≤i≤8) is contained in the subspace spanned by top jjj singular vectors of UAr=64U_{A_{r=64}}UAr=64​​ (for 1≤j≤641\leq j\leq 641≤j≤64)? We measure this quantity with a normalized subspace similarity based on the Grassmann distance (See Appendix G for a more formal discussion)

Subspace similarity between different rrr. 给定用同一预训练模型学到的秩 r=8r=8r=8 与 646464 的适配矩阵 Ar=8A_{r=8}Ar=8​ 与 Ar=64A_{r=64}Ar=64​,我们做奇异值分解并得到右奇异酉矩阵 UAr=8U_{A_{r=8}}UAr=8​​ 与 UAr=64U_{A_{r=64}}UAr=64​​。[^7] 我们希望回答:UAr=8U_{A_{r=8}}UAr=8​​ 中前 iii 个奇异向量张成的子空间(1≤i≤81\leq i\leq 81≤i≤8),有多少包含在 UAr=64U_{A_{r=64}}UAr=64​​ 前 jjj 个奇异向量张成的子空间中(1≤j≤641\leq j\leq 641≤j≤64)?我们用基于 Grassmann 距离的归一化子空间相似度衡量该量(更形式化讨论见附录 G)

ϕ(Ar=8,Ar=64,i,j)=∣∣UAr=8i⊤UAr=64j∣∣F2min⁡(i,j)∈[0,1](4)\phi(A_{r=8},A_{r=64},i,j)=\frac{||U_{A_{r=8}}^{i\top}U_{A_{r=64}}^{j}||_{F}^{2}}{\min(i,j)}\in[0,1] \tag{4}ϕ(Ar=8​,Ar=64​,i,j)=min(i,j)∣∣UAr=8​i⊤​UAr=64​j​∣∣F2​​∈[0,1](4)

where UAr=8iU_{A_{r=8}}^{i}UAr=8​i​ represents the columns of UAr=8U_{A_{r=8}}UAr=8​​ corresponding to the top-iii singular vectors.

其中 UAr=8iU_{A_{r=8}}^{i}UAr=8​i​ 表示 UAr=8U_{A_{r=8}}UAr=8​​ 中对应前 iii 个奇异向量的列。

ϕ(⋅)\phi(\cdot)ϕ(⋅) has a range of [0,1][0,1][0,1], where 111 represents a complete overlap of subspaces and 000 a complete separation. See Figure 3 for how ϕ\phiϕ changes as we vary iii and jjj. We only look at the 48th layer (out of 96) due to space constraint, but the conclusion holds for other layers as well, as shown in Section H.1.

ϕ(⋅)\phi(\cdot)ϕ(⋅) 取值范围为 [0,1][0,1][0,1],其中 111 表示子空间完全重叠,000 表示完全分离。见图 3 了解随 iii 与 jjj 变化时 ϕ\phiϕ 如何变化。受篇幅限制我们只看第 48 层(共 96 层),但结论对其余层同样成立,见第 H.1 节。

Figure 3

Figure 3: Subspace similarity between column vectors of Ar=8A_{r=8}Ar=8​ and Ar=64A_{r=64}Ar=64​ for both ΔWq\Delta W_{q}ΔWq​ and ΔWv\Delta W_{v}ΔWv​. The third and the fourth figures zoom in on the lower-left triangle in the first two figures. The top directions in r=8r=8r=8 are included in r=64r=64r=64, and vice versa.

图 3:Ar=8A_{r=8}Ar=8​ 与 Ar=64A_{r=64}Ar=64​ 列向量之间的子空间相似度(对 ΔWq\Delta W_{q}ΔWq​ 与 ΔWv\Delta W_{v}ΔWv​)。第三、四图放大前两图左下三角。r=8r=8r=8 的顶部方向包含在 r=64r=64r=64 中,反之亦然。

We make an important observation from Figure 3.

我们从图 3 得出重要观察。

Directions corresponding to the top singular vector overlap significantly between Ar=8A_{r=8}Ar=8​ and Ar=64A_{r=64}Ar=64​, while others do not. Specifically, ΔWv\Delta W_{v}ΔWv​ (resp. ΔWq\Delta W_{q}ΔWq​) of Ar=8A_{r=8}Ar=8​ and ΔWv\Delta W_{v}ΔWv​ (resp. ΔWq\Delta W_{q}ΔWq​) of Ar=64A_{r=64}Ar=64​ share a subspace of dimension 1 with normalized similarity >0.5>0.5>0.5, providing an explanation of why r=1r=1r=1 performs quite well in our downstream tasks for GPT-3.

对应顶部奇异向量的方向在 Ar=8A_{r=8}Ar=8​ 与 Ar=64A_{r=64}Ar=64​ 之间显著重叠,而其他方向则不然。具体地,Ar=8A_{r=8}Ar=8​ 的 ΔWv\Delta W_{v}ΔWv​(或 ΔWq\Delta W_{q}ΔWq​)与 Ar=64A_{r=64}Ar=64​ 的 ΔWv\Delta W_{v}ΔWv​(或 ΔWq\Delta W_{q}ΔWq​)共享归一化相似度 >0.5>0.5>0.5 的一维子空间,这解释了为何 r=1r=1r=1 在我们 GPT-3 下游任务上已表现相当好。

Since both Ar=8A_{r=8}Ar=8​ and Ar=64A_{r=64}Ar=64​ are learned using the same pre-trained model, Figure 3 indicates that the top singular-vector directions of Ar=8A_{r=8}Ar=8​ and Ar=64A_{r=64}Ar=64​ are the most useful, while other directions potentially contain mostly random noises accumulated during training. Hence, the adaptation matrix can indeed have a very low rank.

由于 Ar=8A_{r=8}Ar=8​ 与 Ar=64A_{r=64}Ar=64​ 用同一预训练模型学得,图 3 表明二者的顶部奇异向量方向最有用,而其他方向可能主要包含训练中累积的随机噪声。因此,适配矩阵确实可以具有很低的秩。

Figure 4

Figure 4: Left and Middle: Normalized subspace similarity between the column vectors of Ar=64A_{r=64}Ar=64​ from two random seeds, for both ΔWq\Delta W_{q}ΔWq​ and ΔWv\Delta W_{v}ΔWv​ in the 48-th layer. Right: the same heat-map between the column vectors of two random Gaussian matrices. See Section H.1 for other layers.

图 4:左与中:两个随机种子得到的 Ar=64A_{r=64}Ar=64​ 列向量之间的归一化子空间相似度(第 48 层的 ΔWq\Delta W_{q}ΔWq​ 与 ΔWv\Delta W_{v}ΔWv​)。右:两个随机高斯矩阵列向量之间的相同热图。其他层见第 H.1 节。

Subspace similarity between different random seeds.  We further confirm this by plotting the normalized subspace similarity between two randomly seeded runs with r=64r=64r=64, shown in Figure 4. ΔWq\Delta W_{q}ΔWq​ appears to have a higher “intrinsic rank” than ΔWv\Delta W_{v}ΔWv​, since more common singular value directions are learned by both runs for ΔWq\Delta W_{q}ΔWq​, which is in line with our empirical observation in Table 6. As a comparison, we also plot two random Gaussian matrices, which do not share any common singular value directions with each other.

Subspace similarity between different random seeds. 我们进一步通过绘制两个随机种子、r=64r=64r=64 运行之间的归一化子空间相似度来确认这一点,见图 4。ΔWq\Delta W_{q}ΔWq​ 似乎比 ΔWv\Delta W_{v}ΔWv​ 有更高的“本征秩”,因为两次运行对 ΔWq\Delta W_{q}ΔWq​ 学到更多共同奇异值方向,这与表 6 中的经验观察一致。作为对照,我们也绘制两个随机高斯矩阵,它们彼此不共享任何共同奇异值方向。

7.3 How Does the Adaptation Matrix ΔW\Delta WΔW Compare to WWW?

We further investigate the relationship between ΔW\Delta WΔW and WWW. In particular, does ΔW\Delta WΔW highly correlate with WWW? (Or mathematically, is ΔW\Delta WΔW mostly contained in the top singular directions of WWW?) Also, how “large” is ΔW\Delta WΔW comparing to its corresponding directions in WWW? This can shed light on the underlying mechanism for adapting pre-trained language models.

我们进一步考察 ΔW\Delta WΔW 与 WWW 的关系。特别地,ΔW\Delta WΔW 是否与 WWW 高度相关?(或在数学上,ΔW\Delta WΔW 是否主要落在 WWW 的顶部奇异方向中?)另外,相对 WWW 中对应方向,ΔW\Delta WΔW 有多“大”?这有助于阐明适配预训练语言模型的底层机制。

To answer these questions, we project WWW onto the rrr-dimensional subspace of ΔW\Delta WΔW by computing U⊤WV⊤U^{\top}WV^{\top}U⊤WV⊤, with UUU/VVV being the left/right singular-vector matrix of ΔW\Delta WΔW. Then, we compare the Frobenius norm between ∥U⊤WV⊤∥F\|U^{\top}WV^{\top}\|_{F}∥U⊤WV⊤∥F​ and ∥W∥F\|W\|_{F}∥W∥F​. As a comparison, we also compute ∥U⊤WV⊤∥F\|U^{\top}WV^{\top}\|_{F}∥U⊤WV⊤∥F​ by replacing U,VU,VU,V with the top rrr singular vectors of WWW or a random matrix.

为回答这些问题,我们通过计算 U⊤WV⊤U^{\top}WV^{\top}U⊤WV⊤ 把 WWW 投影到 ΔW\Delta WΔW 的 rrr 维子空间上,其中 UUU/VVV 为 ΔW\Delta WΔW 的左/右奇异向量矩阵。然后比较 ∥U⊤WV⊤∥F\|U^{\top}WV^{\top}\|_{F}∥U⊤WV⊤∥F​ 与 ∥W∥F\|W\|_{F}∥W∥F​。作为对照,我们也用 WWW 的前 rrr 个奇异向量或随机矩阵替换 U,VU,VU,V 来计算 ∥U⊤WV⊤∥F\|U^{\top}WV^{\top}\|_{F}∥U⊤WV⊤∥F​。

r=4r=4r=4 r=64r=64r=64
ΔWq\Delta W_{q}ΔWq​ WqW_{q}Wq​ Random ΔWq\Delta W_{q}ΔWq​ WqW_{q}Wq​ Random
∣∣U⊤WqV⊤∣∣F=||U^{\top}W_{q}V^{\top}||_{F}=∣∣U⊤Wq​V⊤∣∣F​= 0.32 21.67 0.02 1.90 37.71 0.33
∣∣Wq∣∣F=61.95||W_{q}||_{F}=61.95∣∣Wq​∣∣F​=61.95 ∣∣ΔWq∣∣F=6.91||\Delta W_{q}||_{F}=6.91∣∣ΔWq​∣∣F​=6.91 ∣∣ΔWq∣∣F=3.57||\Delta W_{q}||_{F}=3.57∣∣ΔWq​∣∣F​=3.57

Table 7: The Frobenius norm of U⊤WqV⊤U^{\top}W_{q}V^{\top}U⊤Wq​V⊤ where UUU and VVV are the left/right top rrr singular vector directions of either (1) ΔWq\Delta W_{q}ΔWq​, (2) WqW_{q}Wq​, or (3) a random matrix. The weight matrices are taken from the 48th layer of GPT-3.

r=4r=4r=4 r=64r=64r=64
ΔWq\Delta W_{q}ΔWq​ WqW_{q}Wq​ Random ΔWq\Delta W_{q}ΔWq​ WqW_{q}Wq​ Random
∣∣U⊤WqV⊤∣∣F=||U^{\top}W_{q}V^{\top}||_{F}=∣∣U⊤Wq​V⊤∣∣F​= 0.32 21.67 0.02 1.90 37.71 0.33
∣∣Wq∣∣F=61.95||W_{q}||_{F}=61.95∣∣Wq​∣∣F​=61.95 ∣∣ΔWq∣∣F=6.91||\Delta W_{q}||_{F}=6.91∣∣ΔWq​∣∣F​=6.91 ∣∣ΔWq∣∣F=3.57||\Delta W_{q}||_{F}=3.57∣∣ΔWq​∣∣F​=3.57

表 7:U⊤WqV⊤U^{\top}W_{q}V^{\top}U⊤Wq​V⊤ 的 Frobenius 范数,其中 UUU 与 VVV 分别为 (1) ΔWq\Delta W_{q}ΔWq​、(2) WqW_{q}Wq​ 或 (3) 随机矩阵的左/右前 rrr 奇异向量方向。权重矩阵取自 GPT-3 第 48 层。

We draw several conclusions from Table 7. First, ΔW\Delta WΔW has a stronger correlation with WWW compared to a random matrix, indicating that ΔW\Delta WΔW amplifies some features that are already in WWW. Second, instead of repeating the top singular directions of WWW, ΔW\Delta WΔW only amplifies directions that are not emphasized in WWW. Third, the amplification factor is rather huge: 21.5≈6.91/0.3221.5\approx 6.91/0.3221.5≈6.91/0.32 for r=4r=4r=4. See Section H.4 for why r=64r=64r=64 has a smaller amplification factor. We also provide a visualization in Section H.3 for how the correlation changes as we include more top singular directions from WqW_{q}Wq​. This suggests that the low-rank adaptation matrix potentially amplifies the important features for specific downstream tasks that were learned but not emphasized in the general pre-training model.

我们从表 7 得出若干结论。第一,相对随机矩阵,ΔW\Delta WΔW 与 WWW 有更强相关,表明 ΔW\Delta WΔW 放大了 WWW 中已有的某些特征。第二,ΔW\Delta WΔW 并非重复 WWW 的顶部奇异方向,而只放大在 WWW 中未被强调的方向。第三,放大因子相当大:对 r=4r=4r=4,21.5≈6.91/0.3221.5\approx 6.91/0.3221.5≈6.91/0.32。为何 r=64r=64r=64 有更小放大因子见第 H.4 节。我们还在第 H.3 节提供可视化,展示随纳入更多来自 WqW_{q}Wq​ 的顶部奇异方向,相关如何变化。这表明低秩适配矩阵有可能放大通用预训练模型已学到、但未强调的、对特定下游任务重要的特征。

8 Conclusion and Future Work

Fine-tuning enormous language models is prohibitively expensive in terms of the hardware required and the storage/switching cost for hosting independent instances for different tasks. We propose LoRA, an efficient adaptation strategy that neither introduces inference latency nor reduces input sequence length while retaining high model quality. Importantly, it allows for quick task-switching when deployed as a service by sharing the vast majority of the model parameters. While we focused on Transformer language models, the proposed principles are generally applicable to any neural networks with dense layers.

微调超大语言模型在硬件需求以及为不同任务托管独立实例的存储/切换成本上代价过高。我们提出 LoRA:一种既不引入推理延迟、也不缩短输入序列长度,同时保持高模型质量的高效适配策略。重要的是,它允许在作为服务部署时通过共享绝大多数模型参数实现快速任务切换。虽然我们聚焦 Transformer 语言模型,所提出的原则一般适用于任何含稠密层的神经网络。

There are many directions for future works. 1) LoRA can be combined with other efficient adaptation methods, potentially providing orthogonal improvement. 2) The mechanism behind fine-tuning or LoRA is far from clear – how are features learned during pre-training transformed to do well on downstream tasks? We believe that LoRA makes it more tractable to answer this than full fine-tuning. 3) We mostly depend on heuristics to select the weight matrices to apply LoRA to. Are there more principled ways to do it? 4) Finally, the rank-deficiency of ΔW\Delta WΔW suggests that WWW could be rank-deficient as well, which can also be a source of inspiration for future works.

未来工作有许多方向。1)LoRA 可与其他高效适配方法结合,潜在提供正交改进。2)微调或 LoRA 背后的机制远未清楚——预训练期间学到的特征如何被转化为在下游任务上表现良好?我们相信相对全量微调,LoRA 使回答该问题更可行。3)我们多依赖启发式选择应用 LoRA 的权重矩阵。是否有更有原则的做法?4)最后,ΔW\Delta WΔW 的秩亏缺暗示 WWW 也可能秩亏,这也可成为未来工作的灵感来源。

References

Aghajanyan et al. (2020) Armen Aghajanyan, Luke Zettlemoyer, and Sonal Gupta. Intrinsic Dimensionality Explains the Effectiveness of Language Model Fine-Tuning. arXiv:2012.13255 [cs] , December 2020. URL http://arxiv.org/abs/2012.13255 .

Allen-Zhu & Li (2019) Zeyuan Allen-Zhu and Yuanzhi Li. What Can ResNet Learn Efficiently, Going Beyond Kernels? In NeurIPS , 2019. Full version available at http://arxiv.org/abs/1905.10337 .

Allen-Zhu & Li (2020a) Zeyuan Allen-Zhu and Yuanzhi Li. Backward feature correction: How deep learning performs deep learning. arXiv preprint arXiv:2001.04413 , 2020a.

Allen-Zhu & Li (2020b) Zeyuan Allen-Zhu and Yuanzhi Li. Feature purification: How adversarial training performs robust deep learning. arXiv preprint arXiv:2005.10190 , 2020b.

Allen-Zhu et al. (2019) Zeyuan Allen-Zhu, Yuanzhi Li, and Zhao Song. A convergence theory for deep learning via over-parameterization. In ICML , 2019. Full version available at http://arxiv.org/abs/1811.03962 .

Ba et al. (2016) Jimmy Lei Ba, Jamie Ryan Kiros, and Geoffrey E. Hinton. Layer normalization, 2016.

Brown et al. (2020) Tom B. Brown, Benjamin Mann, Nick Ryder, Melanie Subbiah, Jared Kaplan, Prafulla Dhariwal, Arvind Neelakantan, Pranav Shyam, Girish Sastry, Amanda Askell, Sandhini Agarwal, Ariel Herbert-Voss, Gretchen Krueger, Tom Henighan, Rewon Child, Aditya Ramesh, Daniel M. Ziegler, Jeffrey Wu, Clemens Winter, Christopher Hesse, Mark Chen, Eric Sigler, Mateusz Litwin, Scott Gray, Benjamin Chess, Jack Clark, Christopher Berner, Sam McCandlish, Alec Radford, Ilya Sutskever, and Dario Amodei. Language Models are Few-Shot Learners. arXiv:2005.14165 [cs] , July 2020. URL http://arxiv.org/abs/2005.14165 .

Cai et al. (2010) Jian-Feng Cai, Emmanuel J Candès, and Zuowei Shen. A singular value thresholding algorithm for matrix completion. SIAM Journal on optimization , 20(4):1956–1982, 2010.

Cer et al. (2017) Daniel Cer, Mona Diab, Eneko Agirre, Inigo Lopez-Gazpio, and Lucia Specia. Semeval-2017 task 1: Semantic textual similarity multilingual and crosslingual focused evaluation. Proceedings of the 11th International Workshop on Semantic Evaluation (SemEval-2017) , 2017. doi: 10.18653/v1/s17-2001 . URL http://dx.doi.org/10.18653/v1/S17-2001 .

Collobert & Weston (2008) Ronan Collobert and Jason Weston. A unified architecture for natural language processing: deep neural networks with multitask learning. In Proceedings of the 25th international conference on Machine learning , ICML ’08, pp. 160–167, New York, NY, USA, July 2008. Association for Computing Machinery. ISBN 978-1-60558-205-4. doi: 10.1145/1390156.1390177 . URL https://doi.org/10.1145/1390156.1390177 .

Denil et al. (2014) Misha Denil, Babak Shakibi, Laurent Dinh, Marc’Aurelio Ranzato, and Nando de Freitas. Predicting parameters in deep learning, 2014.

Devlin et al. (2019a) Jacob Devlin, Ming-Wei Chang, Kenton Lee, and Kristina Toutanova. Bert: Pre-training of deep bidirectional transformers for language understanding, 2019a.

Devlin et al. (2019b) Jacob Devlin, Ming-Wei Chang, Kenton Lee, and Kristina Toutanova. BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding. arXiv:1810.04805 [cs] , May 2019b. URL http://arxiv.org/abs/1810.04805 . arXiv: 1810.04805.

Dolan & Brockett (2005) William B. Dolan and Chris Brockett. Automatically constructing a corpus of sentential paraphrases. In Proceedings of the Third International Workshop on Paraphrasing (IWP2005) , 2005. URL https://aclanthology.org/I05-5002 .

Gardent et al. (2017) Claire Gardent, Anastasia Shimorina, Shashi Narayan, and Laura Perez-Beltrachini. The webnlg challenge: Generating text from rdf data. In Proceedings of the 10th International Conference on Natural Language Generation , pp. 124–133, 2017.

Ghorbani et al. (2020) Behrooz Ghorbani, Song Mei, Theodor Misiakiewicz, and Andrea Montanari. When do neural networks outperform kernel methods? arXiv preprint arXiv:2006.13409 , 2020.

Gliwa et al. (2019) Bogdan Gliwa, Iwona Mochol, Maciej Biesek, and Aleksander Wawer. Samsum corpus: A human-annotated dialogue dataset for abstractive summarization. CoRR , abs/1911.12237, 2019. URL http://arxiv.org/abs/1911.12237 .

Grasedyck et al. (2013) Lars Grasedyck, Daniel Kressner, and Christine Tobler. A literature survey of low-rank tensor approximation techniques. GAMM-Mitteilungen , 36(1):53–78, 2013.

Ham & Lee (2008) Jihun Ham and Daniel D. Lee. Grassmann discriminant analysis: a unifying view on subspace-based learning. In ICML , pp. 376–383, 2008. URL https://doi.org/10.1145/1390156.1390204 .

Hambardzumyan et al. (2020) Karen Hambardzumyan, Hrant Khachatrian, and Jonathan May. WARP: Word-level Adversarial ReProgramming. arXiv:2101.00121 [cs] , December 2020. URL http://arxiv.org/abs/2101.00121 . arXiv: 2101.00121.

He et al. (2021) Pengcheng He, Xiaodong Liu, Jianfeng Gao, and Weizhu Chen. Deberta: Decoding-enhanced bert with disentangled attention, 2021.

Houlsby et al. (2019) Neil Houlsby, Andrei Giurgiu, Stanislaw Jastrzebski, Bruna Morrone, Quentin de Laroussilhe, Andrea Gesmundo, Mona Attariyan, and Sylvain Gelly. Parameter-Efficient Transfer Learning for NLP. arXiv:1902.00751 [cs, stat] , June 2019. URL http://arxiv.org/abs/1902.00751 .

Jaderberg et al. (2014) Max Jaderberg, Andrea Vedaldi, and Andrew Zisserman. Speeding up convolutional neural networks with low rank expansions. arXiv preprint arXiv:1405.3866 , 2014.

Khodak et al. (2021) Mikhail Khodak, Neil Tenenholtz, Lester Mackey, and Nicolò Fusi. Initialization and regularization of factorized neural layers, 2021.

Kingma & Ba (2017) Diederik P. Kingma and Jimmy Ba. Adam: A method for stochastic optimization, 2017.

Lepikhin et al. (2020) Dmitry Lepikhin, HyoukJoong Lee, Yuanzhong Xu, Dehao Chen, Orhan Firat, Yanping Huang, Maxim Krikun, Noam Shazeer, and Zhifeng Chen. Gshard: Scaling giant models with conditional computation and automatic sharding, 2020.

Lester et al. (2021) Brian Lester, Rami Al-Rfou, and Noah Constant. The Power of Scale for Parameter-Efficient Prompt Tuning. arXiv:2104.08691 [cs] , April 2021. URL http://arxiv.org/abs/2104.08691 . arXiv: 2104.08691.

Li et al. (2018a) Chunyuan Li, Heerad Farkhoor, Rosanne Liu, and Jason Yosinski. Measuring the Intrinsic Dimension of Objective Landscapes. arXiv:1804.08838 [cs, stat] , April 2018a. URL http://arxiv.org/abs/1804.08838 . arXiv: 1804.08838.

Li & Liang (2021) Xiang Lisa Li and Percy Liang. Prefix-Tuning: Optimizing Continuous Prompts for Generation. arXiv:2101.00190 [cs] , January 2021. URL http://arxiv.org/abs/2101.00190 .

Li & Liang (2018) Yuanzhi Li and Yingyu Liang. Learning overparameterized neural networks via stochastic gradient descent on structured data. In Advances in Neural Information Processing Systems , 2018.

Li et al. (2016) Yuanzhi Li, Yingyu Liang, and Andrej Risteski. Recovery guarantee of weighted low-rank approximation via alternating minimization. In International Conference on Machine Learning , pp. 2358–2367. PMLR, 2016.

Li et al. (2018b) Yuanzhi Li, Tengyu Ma, and Hongyang Zhang. Algorithmic regularization in over-parameterized matrix sensing and neural networks with quadratic activations. In Conference On Learning Theory , pp. 2–47. PMLR, 2018b.

Lin et al. (2020) Zhaojiang Lin, Andrea Madotto, and Pascale Fung. Exploring versatile generative language model via parameter-efficient transfer learning. In Findings of the Association for Computational Linguistics: EMNLP 2020 , pp. 441–459, Online, November 2020. Association for Computational Linguistics. doi: 10.18653/v1/2020.findings-emnlp.41 . URL https://aclanthology.org/2020.findings-emnlp.41 .

Liu et al. (2021) Xiao Liu, Yanan Zheng, Zhengxiao Du, Ming Ding, Yujie Qian, Zhilin Yang, and Jie Tang. GPT Understands, Too. arXiv:2103.10385 [cs] , March 2021. URL http://arxiv.org/abs/2103.10385 . arXiv: 2103.10385.

Liu et al. (2019) Yinhan Liu, Myle Ott, Naman Goyal, Jingfei Du, Mandar Joshi, Danqi Chen, Omer Levy, Mike Lewis, Luke Zettlemoyer, and Veselin Stoyanov. Roberta: A robustly optimized bert pretraining approach, 2019.

Loshchilov & Hutter (2017) Ilya Loshchilov and Frank Hutter. Decoupled weight decay regularization. arXiv preprint arXiv:1711.05101 , 2017.

Loshchilov & Hutter (2019) Ilya Loshchilov and Frank Hutter. Decoupled weight decay regularization, 2019.

Mahabadi et al. (2021) Rabeeh Karimi Mahabadi, James Henderson, and Sebastian Ruder. Compacter: Efficient low-rank hypercomplex adapter layers, 2021.

Nan et al. (2020) Linyong Nan, Dragomir Radev, Rui Zhang, Amrit Rau, Abhinand Sivaprasad, Chiachun Hsieh, Xiangru Tang, Aadit Vyas, Neha Verma, Pranav Krishna, et al. Dart: Open-domain structured data record to text generation. arXiv preprint arXiv:2007.02871 , 2020.

Novikova et al. (2017) Jekaterina Novikova, Ondřej Dušek, and Verena Rieser. The e2e dataset: New challenges for end-to-end generation. arXiv preprint arXiv:1706.09254 , 2017.

Oymak et al. (2019) Samet Oymak, Zalan Fabian, Mingchen Li, and Mahdi Soltanolkotabi. Generalization guarantees for neural networks via harnessing the low-rank structure of the jacobian. arXiv preprint arXiv:1906.05392 , 2019.

Pfeiffer et al. (2021) Jonas Pfeiffer, Aishwarya Kamath, Andreas Rücklé, Kyunghyun Cho, and Iryna Gurevych. Adapterfusion: Non-destructive task composition for transfer learning, 2021.

Povey et al. (2018) Daniel Povey, Gaofeng Cheng, Yiming Wang, Ke Li, Hainan Xu, Mahsa Yarmohammadi, and Sanjeev Khudanpur. Semi-orthogonal low-rank matrix factorization for deep neural networks. In Interspeech , pp. 3743–3747, 2018.

Radford et al. (a) Alec Radford, Karthik Narasimhan, Tim Salimans, and Ilya Sutskever. Improving Language Understanding by Generative Pre-Training. pp.  12, a.

Radford et al. (b) Alec Radford, Jeffrey Wu, Rewon Child, David Luan, Dario Amodei, and Ilya Sutskever. Language Models are Unsupervised Multitask Learners. pp.  24, b.

Rajpurkar et al. (2018) Pranav Rajpurkar, Robin Jia, and Percy Liang. Know what you don’t know: Unanswerable questions for squad. CoRR , abs/1806.03822, 2018. URL http://arxiv.org/abs/1806.03822 .

Rebuffi et al. (2017) Sylvestre-Alvise Rebuffi, Hakan Bilen, and Andrea Vedaldi. Learning multiple visual domains with residual adapters. arXiv:1705.08045 [cs, stat] , November 2017. URL http://arxiv.org/abs/1705.08045 . arXiv: 1705.08045.

Rücklé et al. (2020) Andreas Rücklé, Gregor Geigle, Max Glockner, Tilman Beck, Jonas Pfeiffer, Nils Reimers, and Iryna Gurevych. Adapterdrop: On the efficiency of adapters in transformers, 2020.

Sainath et al. (2013) Tara N Sainath, Brian Kingsbury, Vikas Sindhwani, Ebru Arisoy, and Bhuvana Ramabhadran. Low-rank matrix factorization for deep neural network training with high-dimensional output targets. In 2013 IEEE international conference on acoustics, speech and signal processing , pp. 6655–6659. IEEE, 2013.

Shoeybi et al. (2020) Mohammad Shoeybi, Mostofa Patwary, Raul Puri, Patrick LeGresley, Jared Casper, and Bryan Catanzaro. Megatron-lm: Training multi-billion parameter language models using model parallelism, 2020.

Socher et al. (2013) Richard Socher, Alex Perelygin, Jean Wu, Jason Chuang, Christopher D. Manning, Andrew Ng, and Christopher Potts. Recursive deep models for semantic compositionality over a sentiment treebank. In Proceedings of the 2013 Conference on Empirical Methods in Natural Language Processing , pp. 1631–1642, Seattle, Washington, USA, October 2013. Association for Computational Linguistics. URL https://aclanthology.org/D13-1170 .

Vaswani et al. (2017) Ashish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N Gomez, Łukasz Kaiser, and Illia Polosukhin. Attention is all you need. In Proceedings of the 31st International Conference on Neural Information Processing Systems , pp. 6000–6010, 2017.

Wang et al. (2019) Alex Wang, Amanpreet Singh, Julian Michael, Felix Hill, Omer Levy, and Samuel R. Bowman. Glue: A multi-task benchmark and analysis platform for natural language understanding, 2019.

Wang et al. (2020) Alex Wang, Yada Pruksachatkun, Nikita Nangia, Amanpreet Singh, Julian Michael, Felix Hill, Omer Levy, and Samuel R. Bowman. Superglue: A stickier benchmark for general-purpose language understanding systems, 2020.

Warstadt et al. (2018) Alex Warstadt, Amanpreet Singh, and Samuel R Bowman. Neural network acceptability judgments. arXiv preprint arXiv:1805.12471 , 2018.

Williams et al. (2018) Adina Williams, Nikita Nangia, and Samuel Bowman. A broad-coverage challenge corpus for sentence understanding through inference. In Proceedings of the 2018 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, Volume 1 (Long Papers) , pp. 1112–1122, New Orleans, Louisiana, June 2018. Association for Computational Linguistics. doi: 10.18653/v1/N18-1101 . URL https://www.aclweb.org/anthology/N18-1101 .

Wolf et al. (2020) Thomas Wolf, Lysandre Debut, Victor Sanh, Julien Chaumond, Clement Delangue, Anthony Moi, Pierric Cistac, Tim Rault, Rémi Louf, Morgan Funtowicz, Joe Davison, Sam Shleifer, Patrick von Platen, Clara Ma, Yacine Jernite, Julien Plu, Canwen Xu, Teven Le Scao, Sylvain Gugger, Mariama Drame, Quentin Lhoest, and Alexander M. Rush. Transformers: State-of-the-art natural language processing. In Proceedings of the 2020 Conference on Empirical Methods in Natural Language Processing: System Demonstrations , pp. 38–45, Online, October 2020. Association for Computational Linguistics. URL https://www.aclweb.org/anthology/2020.emnlp-demos.6 .

Yang & Hu (2021) Greg Yang and Edward J. Hu. Feature Learning in Infinite-Width Neural Networks. arXiv:2011.14522 [cond-mat] , May 2021. URL http://arxiv.org/abs/2011.14522 . arXiv: 2011.14522.

Zaken et al. (2021) Elad Ben Zaken, Shauli Ravfogel, and Yoav Goldberg. Bitfit: Simple parameter-efficient fine-tuning for transformer-based masked language-models, 2021.

Zhang et al. (2014) Yu Zhang, Ekapol Chuangsuwanich, and James Glass. Extracting deep neural network bottleneck features using low-rank matrix factorization. In 2014 IEEE international conference on acoustics, speech and signal processing (ICASSP) , pp. 185–189. IEEE, 2014.

Zhao et al. (2016) Yong Zhao, Jinyu Li, and Yifan Gong. Low-rank plus diagonal adaptation for deep neural networks. In 2016 IEEE International Conference on Acoustics, Speech and Signal Processing (ICASSP) , pp. 5005–5009. IEEE, 2016.

Zhong et al. (2017) Victor Zhong, Caiming Xiong, and Richard Socher. Seq2sql: Generating structured queries from natural language using reinforcement learning. CoRR , abs/1709.00103, 2017. URL http://arxiv.org/abs/1709.00103 .

Appendix A Large Language Models Still Need Parameter Updates

Few-shot learning, or prompt engineering, is very advantageous when we only have a handful of training samples. However, in practice, we can often afford to curate a few thousand or more training examples for performance-sensitive applications. As shown in Table 8, fine-tuning improves the model performance drastically compared to few-shot learning on datasets large and small. We take the GPT-3 few-shot result on RTE from the GPT-3 paper (Brown et al. 2020). For MNLI-matched, we use two demonstrations per class and six in-context examples in total.

当只有少量训练样本时,少样本学习或 prompt engineering 很有优势。但实践中,对性能敏感的应用我们往往能负担整理数千甚至更多训练样本。如表 8 所示,相对少样本学习,微调在或大或小的数据集上都大幅提升模型表现。我们取 GPT-3 论文(Brown et al. 2020)中 RTE 上的 GPT-3 少样本结果。对 MNLI-matched,我们每类用两个示范,上下文中共六个例子。

Method MNLI-m (Val. Acc./%) RTE (Val. Acc./%)
GPT-3 Few-Shot 40.6 69.0
GPT-3 Fine-Tuned 89.5 85.4

Table 8: Fine-tuning significantly outperforms few-shot learning on GPT-3 (Brown et al. 2020).

Method MNLI-m (Val. Acc./%) RTE (Val. Acc./%)
GPT-3 Few-Shot 40.6 69.0
GPT-3 Fine-Tuned 89.5 85.4

表 8:相对少样本学习,微调在 GPT-3(Brown et al. 2020)上显著更好。

Appendix B Inference Latency Introduced by Adapter Layers

Adapter layers are external modules added to a pre-trained model in a sequential manner, whereas our proposal, LoRA, can be seen as external modules added in a parallel manner. Consequently, adapter layers must be computed in addition to the base model, inevitably introducing additional latency. While as pointed out in Rücklé et al. 2020, the latency introduced by adapter layers can be mitigated when the model batch size and/or sequence length is large enough to full utilize the hardware parallelism. We confirm their observation with a similar latency study on GPT-2 medium and point out that there are scenarios, notably online inference where the batch size is small, where the added latency can be significant.

Adapter 层是以串行方式加到预训练模型上的外部模块,而我们的提议 LoRA 可视为以并行方式加入的外部模块。因此,adapter 层必须在基座模型之外额外计算,不可避免引入额外延迟。尽管如 Rücklé et al. 2020 所指出,当模型 batch size 和/或序列长度足够大以充分利用硬件并行时,adapter 层引入的延迟可被缓解。我们在 GPT-2 medium 上用类似延迟研究确认了他们的观察,并指出在某些场景——尤其是 batch size 很小的在线推理——增加的延迟可能显著。

We measure the latency of a single forward pass on an NVIDIA Quadro RTX8000 by averaging over 100 trials. We vary the input batch size, sequence length, and the adapter bottleneck dimension rrr. We test two adapter designs: the original one by Houlsby et al. 2019, which we call AdapterH\text{Adapter}^{\text{H}}AdapterH, and a recent, more efficient variant by Lin et al. 2020, which we call AdapterL\text{Adapter}^{\text{L}}AdapterL. See Section 5.1 for more details on the designs. We plot the slow-down in percentage compared to the no-adapter baseline in Figure 5.

我们在 NVIDIA Quadro RTX8000 上对单次前向延迟做 100 次试验平均。我们改变输入 batch size、序列长度与 adapter 瓶颈维 rrr。我们测试两种 adapter 设计:Houlsby et al. 2019 的原始设计,称为 AdapterH\text{Adapter}^{\text{H}}AdapterH;以及 Lin et al. 2020 更近、更高效的变体,称为 AdapterL\text{Adapter}^{\text{L}}AdapterL。设计细节见第 5.1 节。我们在图 5 中绘制相对无 adapter 基线的百分比减速。

Figure 5

Figure 5: Percentage slow-down of inference latency compared to the no-adapter (r=0r=0r=0) baseline. The top row shows the result for AdapterH\text{Adapter}^{\text{H}}AdapterH and the bottom row AdapterL\text{Adapter}^{\text{L}}AdapterL. Larger batch size and sequence length help to mitigate the latency, but the slow-down can be as high as over 30% in an online, short-sequence-length scenario. We tweak the colormap for better visibility.

图 5:相对无 adapter(r=0r=0r=0)基线的推理延迟百分比减速。上行是 AdapterH\text{Adapter}^{\text{H}}AdapterH,下行是 AdapterL\text{Adapter}^{\text{L}}AdapterL。更大的 batch size 与序列长度有助于缓解延迟,但在在线、短序列场景中减速可超过 30%。我们调整色图以更清晰。

Appendix C Dataset Details

GLUE Benchmark is a wide-ranging collection of natural language understanding tasks. It includes MNLI (inference, Williams et al. 2018), SST-2 (sentiment analysis, Socher et al. 2013), MRPC (paraphrase detection, Dolan & Brockett 2005), CoLA (linguistic acceptability, Warstadt et al. 2018), QNLI (inference, Rajpurkar et al. 2018), QQP[^8] (question-answering), RTE (inference), and STS-B (textual similarity, Cer et al. 2017). The broad coverage makes GLUE benchmark a standard metric to evaluate NLU models such as RoBERTa and DeBERTa. The individual datasets are released under different permissive licenses.

GLUE Benchmark 是覆盖广泛的自然语言理解任务集合。它包括 MNLI(推理,Williams et al. 2018)、SST-2(情感分析,Socher et al. 2013)、MRPC(释义检测,Dolan & Brockett 2005)、CoLA(语言可接受性,Warstadt et al. 2018)、QNLI(推理,Rajpurkar et al. 2018)、QQP[^8](问答)、RTE(推理)与 STS-B(文本相似度,Cer et al. 2017)。广泛覆盖使 GLUE 成为评估 RoBERTa、DeBERTa 等 NLU 模型的标准指标。各数据集以不同宽松许可证发布。

WikiSQL is introduced in  Zhong et al. 2017 and contains 56,35556,35556,355/8,4218,4218,421 training/validation examples. The task is to generate SQL queries from natural language questions and table schemata. We encode context as x={table schema,query}x=\{\text{table schema},\text{query}\}x={table schema,query} and target as y={SQL}y=\{\text{SQL}\}y={SQL}. The dataset is release under the BSD 3-Clause License.

WikiSQL 由 Zhong et al. 2017 引入,含 56,35556,35556,355/8,4218,4218,421 个训练/验证样本。任务是从自然语言问题与表模式生成 SQL 查询。我们把上下文编码为 x={table schema,query}x=\{\text{table schema},\text{query}\}x={table schema,query},目标为 y={SQL}y=\{\text{SQL}\}y={SQL}。数据集以 BSD 3-Clause 许可证发布。

SAMSum is introduced in  Gliwa et al. 2019 and contains 14,73214,73214,732/819819819 training/test examples. It consists of staged chat conversations between two people and corresponding abstractive summaries written by linguists. We encode context as ”\n” concatenated utterances followed by a ”\n\n”, and target as y={summary}y=\{\text{summary}\}y={summary}. The dataset is released under the non-commercial licence: Creative Commons BY-NC-ND 4.0.

SAMSum 由 Gliwa et al. 2019 引入,含 14,73214,73214,732/819819819 个训练/测试样本。它由两个人之间的编排聊天对话,以及语言学家撰写的对应抽象摘要组成。我们把上下文编码为用 ”\n” 拼接的话语后接 ”\n\n”,目标为 y={summary}y=\{\text{summary}\}y={summary}。数据集以非商业许可证 Creative Commons BY-NC-ND 4.0 发布。

E2E NLG Challenge was first introduced in  Novikova et al. 2017 as a dataset for training end-to-end, data-driven natural language generation systems and is commonly used for data-to-text evaluation. The E2E dataset consists of roughly 42,00042,00042,000 training, 4,6004,6004,600 validation, and 4,6004,6004,600 test examples from the restaurant domain. Each source table used as input can have multiple references. Each sample input (x,y)(x,y)(x,y) consists of a sequence of slot-value pairs, along with a corresponding natural language reference text. The dataset is released under Creative Commons BY-NC-SA 4.0.

E2E NLG Challenge 最早由 Novikova et al. 2017 引入,用作训练端到端、数据驱动自然语言生成系统的数据集,并常用于 data-to-text 评估。E2E 数据集约有 42,00042,00042,000 训练、4,6004,6004,600 验证与 4,6004,6004,600 测试样本,来自餐厅领域。用作输入的每个源表可有多个参考。每个样本输入 (x,y)(x,y)(x,y) 由一串槽–值对以及对应的自然语言参考文本组成。数据集以 Creative Commons BY-NC-SA 4.0 发布。

DART is an open-domain data-to-text dataset described in Nan et al. 2020. DART inputs are structured as sequences of ENTITY — RELATION — ENTITY triples. With  82K~82K 82K examples in total, DART is a significantly larger and more complex data-to-text task compared to E2E. The dataset is released under the MIT license.

DART 是 Nan et al. 2020 描述的开放域 data-to-text 数据集。DART 输入被组织为 ENTITY — RELATION — ENTITY 三元组序列。总计约 82K82K82K 样本,相对 E2E,DART 是显著更大且更复杂的 data-to-text 任务。数据集以 MIT 许可证发布。

WebNLG is another commonly used dataset for data-to-text evaluation (Gardent et al. 2017). With  22K~22K 22K examples in total WebNLG comprises 14 distinct categories, nine of which are seen during training. Since five of the 14 total categories are not seen during training, but are represented in the test set, evaluation is typically broken out by “seen” categories (S), “unseen” categories (U) and “all” (A). Each input example is represented by a sequence of SUBJECT — PROPERTY — OBJECT triples. The dataset is released under Creative Commons BY-NC-SA 4.0.

WebNLG 是另一常用的 data-to-text 评估数据集(Gardent et al. 2017)。总计约 22K22K22K 样本,涵盖 14 个不同类别,其中 9 个在训练中见过。由于 14 类中有 5 类训练未见但出现在测试集,评估通常按“已见”类别(S)、“未见”类别(U)与“全部”(A)分别报告。每个输入样本表示为 SUBJECT — PROPERTY — OBJECT 三元组序列。数据集以 Creative Commons BY-NC-SA 4.0 发布。

Appendix D Hyperparameters Used in Experiments

D.1 RoBERTa

We train using AdamW with a linear learning rate decay schedule. We sweep learning rate, number of training epochs, and batch size for LoRA. Following Liu et al. 2019, we initialize the LoRA modules to our best MNLI checkpoint when adapting to MRPC, RTE, and STS-B, instead of the usual initialization; the pre-trained model stays frozen for all tasks. We report the median over 5 random seeds; the result for each run is taken from the best epoch. For a fair comparison with the setup in Houlsby et al. 2019 and Pfeiffer et al. 2021, we restrict the model sequence length to 128 and used a fixed batch size for all tasks. Importantly, we start with the pre-trained RoBERTa large model when adapting to MRPC, RTE, and STS-B, instead of a model already adapted to MNLI. The runs with this restricted setup are marked with †\dagger†. See the hyperparameters used in our runs in Table 9.

我们用 AdamW 与线性学习率衰减日程训练。对 LoRA 扫描学习率、训练 epoch 数与 batch size。遵循 Liu et al. 2019,适配 MRPC、RTE 与 STS-B 时把 LoRA 模块初始化为我们最好的 MNLI 检查点,而非通常初始化;预训练模型对所有任务保持冻结。我们报告 5 个随机种子的中位数;每次运行取最佳 epoch 的结果。为与 Houlsby et al. 2019 与 Pfeiffer et al. 2021 的设定公平比较,我们把模型序列长度限制为 128,并对所有任务使用固定 batch size。重要的是,适配 MRPC、RTE 与 STS-B 时从预训练 RoBERTa large 起步,而非已适配到 MNLI 的模型。该受限设定下的运行标以 †\dagger†。所用超参见表 9。

Method Dataset MNLI SST-2 MRPC CoLA QNLI QQP RTE STS-B
Optimizer AdamW
Warmup Ratio 0.06
LR Schedule Linear
RoBERTa base LoRA Batch Size 16 16 16 32 32 16 32 16
# Epochs 30 60 30 80 25 25 80 40
Learning Rate 5E-04 5E-04 4E-04 4E-04 4E-04 5E-04 5E-04 4E-04
LoRA Config. rq=rv=8r_{q}=r_{v}=8rq​=rv​=8
LoRA α\alphaα 8
Max Seq. Len. 512
RoBERTa large LoRA Batch Size 4 4 4 4 4 4 8 8
# Epochs 10 10 20 20 10 20 20 30
Learning Rate 3E-04 4E-04 3E-04 2E-04 2E-04 3E-04 4E-04 2E-04
LoRA Config. rq=rv=8r_{q}=r_{v}=8rq​=rv​=8
LoRA α\alphaα 16
Max Seq. Len. 128 128 512 128 512 512 512 512
RoBERTa large LoRA†\dagger† Batch Size 4
# Epochs 10 10 20 20 10 20 20 10
Learning Rate 3E-04 4E-04 3E-04 2E-04 2E-04 3E-04 4E-04 2E-04
LoRA Config. rq=rv=8r_{q}=r_{v}=8rq​=rv​=8
LoRA α\alphaα 16
Max Seq. Len. 128
RoBERTa large AdptP\text{Adpt}^{\text{P}}AdptP (3M)†\dagger† Batch Size 32
# Epochs 10 20 20 20 10 20 20 20
Learning Rate 3E-05 3E-05 3E-04 3E-04 3E-04 3E-04 3E-04 3E-04
Bottleneck rrr 64
Max Seq. Len. 128
RoBERTa large AdptP\text{Adpt}^{\text{P}}AdptP (0.8M)†\dagger† Batch Size 32
# Epochs 5 20 20 20 10 20 20 20
Learning Rate 3E-04 3E-04 3E-04 3E-04 3E-04 3E-04 3E-04 3E-04
Bottleneck rrr 16
Max Seq. Len. 128
RoBERTa large AdptH\text{Adpt}^{\text{H}}AdptH (6M)†\dagger† Batch Size 32
# Epochs 10 5 10 10 5 20 20 10
Learning Rate 3E-05 3E-04 3E-04 3E-04 3E-04 3E-04 3E-04 3E-04
Bottleneck rrr 64
Max Seq. Len. 128
RoBERTa large AdptH\text{Adpt}^{\text{H}}AdptH (0.8M)†\dagger† Batch Size 32
# Epochs 10 5 10 10 5 20 20 10
Learning Rate 3E-04 3E-04 3E-04 3E-04 3E-04 3E-04 3E-04 3E-04
Bottleneck rrr 8
Max Seq. Len. 128

Table 9: The hyperparameters we used for RoBERTa on the GLUE benchmark.

Method Dataset MNLI SST-2 MRPC CoLA QNLI QQP RTE STS-B
Optimizer AdamW
Warmup Ratio 0.06
LR Schedule Linear
RoBERTa base LoRA Batch Size 16 16 16 32 32 16 32 16
# Epochs 30 60 30 80 25 25 80 40
Learning Rate 5E-04 5E-04 4E-04 4E-04 4E-04 5E-04 5E-04 4E-04
LoRA Config. rq=rv=8r_{q}=r_{v}=8rq​=rv​=8
LoRA α\alphaα 8
Max Seq. Len. 512
RoBERTa large LoRA Batch Size 4 4 4 4 4 4 8 8
# Epochs 10 10 20 20 10 20 20 30
Learning Rate 3E-04 4E-04 3E-04 2E-04 2E-04 3E-04 4E-04 2E-04
LoRA Config. rq=rv=8r_{q}=r_{v}=8rq​=rv​=8
LoRA α\alphaα 16
Max Seq. Len. 128 128 512 128 512 512 512 512
RoBERTa large LoRA†\dagger† Batch Size 4
# Epochs 10 10 20 20 10 20 20 10
Learning Rate 3E-04 4E-04 3E-04 2E-04 2E-04 3E-04 4E-04 2E-04
LoRA Config. rq=rv=8r_{q}=r_{v}=8rq​=rv​=8
LoRA α\alphaα 16
Max Seq. Len. 128
RoBERTa large AdptP\text{Adpt}^{\text{P}}AdptP (3M)†\dagger† Batch Size 32
# Epochs 10 20 20 20 10 20 20 20
Learning Rate 3E-05 3E-05 3E-04 3E-04 3E-04 3E-04 3E-04 3E-04
Bottleneck rrr 64
Max Seq. Len. 128
RoBERTa large AdptP\text{Adpt}^{\text{P}}AdptP (0.8M)†\dagger† Batch Size 32
# Epochs 5 20 20 20 10 20 20 20
Learning Rate 3E-04 3E-04 3E-04 3E-04 3E-04 3E-04 3E-04 3E-04
Bottleneck rrr 16
Max Seq. Len. 128
RoBERTa large AdptH\text{Adpt}^{\text{H}}AdptH (6M)†\dagger† Batch Size 32
# Epochs 10 5 10 10 5 20 20 10
Learning Rate 3E-05 3E-04 3E-04 3E-04 3E-04 3E-04 3E-04 3E-04
Bottleneck rrr 64
Max Seq. Len. 128
RoBERTa large AdptH\text{Adpt}^{\text{H}}AdptH (0.8M)†\dagger† Batch Size 32
# Epochs 10 5 10 10 5 20 20 10
Learning Rate 3E-04 3E-04 3E-04 3E-04 3E-04 3E-04 3E-04 3E-04
Bottleneck rrr 8
Max Seq. Len. 128

表 9: The hyperparameters we used for RoBERTa on the GLUE benchmark.

D.2 DeBERTa

We again train using AdamW with a linear learning rate decay schedule. Following He et al. 2021, we tune learning rate, dropout probability, warm-up steps, and batch size. We use the same model sequence length used by (He et al. 2021) to keep our comparison fair. Following He et al. 2021, we initialize the LoRA modules to our best MNLI checkpoint when adapting to MRPC, RTE, and STS-B, instead of the usual initialization; the pre-trained model stays frozen for all tasks. We report the median over 5 random seeds; the result for each run is taken from the best epoch. See the hyperparameters used in our runs in Table 10.

我们再次用 AdamW 与线性学习率衰减日程训练。遵循 He et al. 2021,调节学习率、dropout 概率、warm-up 步数与 batch size。使用与(He et al. 2021)相同的模型序列长度以保持比较公平。遵循 He et al. 2021,适配 MRPC、RTE 与 STS-B 时把 LoRA 模块初始化为我们最好的 MNLI 检查点,而非通常初始化;预训练模型对所有任务保持冻结。我们报告 5 个随机种子的中位数;每次运行取最佳 epoch 的结果。所用超参见表 10。

Method Dataset MNLI SST-2 MRPC CoLA QNLI QQP RTE STS-B
Optimizer AdamW
Warmup Ratio 0.1
LR Schedule Linear
DeBERTa XXL LoRA Batch Size 8 8 32 4 6 8 4 4
# Epochs 5 16 30 10 8 11 11 10
Learning Rate 1E-04 6E-05 2E-04 1E-04 1E-04 1E-04 2E-04 2E-04
Weight Decay 0 0.01 0.01 0 0.01 0.01 0.01 0.1
CLS Dropout 0.15 0 0 0.1 0.1 0.2 0.2 0.2
LoRA Config. rq=rv=8r_{q}=r_{v}=8rq​=rv​=8
LoRA α\alphaα 8
Max Seq. Len. 256 128 128 64 512 320 320 128

Table 10: The hyperparameters for DeBERTa XXL on tasks included in the GLUE benchmark.

Method Dataset MNLI SST-2 MRPC CoLA QNLI QQP RTE STS-B
Optimizer AdamW
Warmup Ratio 0.1
LR Schedule Linear
DeBERTa XXL LoRA Batch Size 8 8 32 4 6 8 4 4
# Epochs 5 16 30 10 8 11 11 10
Learning Rate 1E-04 6E-05 2E-04 1E-04 1E-04 1E-04 2E-04 2E-04
Weight Decay 0 0.01 0.01 0 0.01 0.01 0.01 0.1
CLS Dropout 0.15 0 0 0.1 0.1 0.2 0.2 0.2
LoRA Config. rq=rv=8r_{q}=r_{v}=8rq​=rv​=8
LoRA α\alphaα 8
Max Seq. Len. 256 128 128 64 512 320 320 128

表 10:DeBERTa XXL 在 GLUE 基准所含任务上的超参。

D.3 GPT-2

We train all of our GPT-2 models using AdamW (Loshchilov & Hutter 2017) with a linear learning rate schedule for 5 epochs. We use the batch size, learning rate, and beam search beam size described in Li & Liang 2021. Accordingly, we also tune the above hyperparameters for LoRA. We report the mean over 3 random seeds; the result for each run is taken from the best epoch. The hyperparameters used for LoRA in GPT-2 are listed in Table 11. For those used for other baselines, see Li & Liang 2021.

我们用 AdamW(Loshchilov & Hutter 2017)与线性学习率日程训练全部 GPT-2 模型,共 5 个 epoch。使用 Li & Liang 2021 所述的 batch size、学习率与束搜索束宽。相应地,我们也为 LoRA 调节上述超参。报告 3 个随机种子的均值;每次运行取最佳 epoch。GPT-2 上 LoRA 所用超参见表 11。其他基线所用超参见 Li & Liang 2021。

Dataset E2E WebNLG DART
Training
Optimizer AdamW
Weight Decay 0.01 0.01 0.0
Dropout Prob 0.1 0.1 0.0
Batch Size 8
# Epoch 5
Warmup Steps 500
Learning Rate Schedule Linear
Label Smooth 0.1 0.1 0.0
Learning Rate 0.0002
Adaptation rq=rv=4r_{q}=r_{v}=4rq​=rv​=4
LoRA α\alphaα 32
Inference
Beam Size 10
Length Penalty 0.9 0.8 0.8
no repeat ngram size 4

Table 11: The hyperparameters for GPT-2 LoRA on E2E, WebNLG and DART.

Dataset E2E WebNLG DART
Training
Optimizer AdamW
Weight Decay 0.01 0.01 0.0
Dropout Prob 0.1 0.1 0.0
Batch Size 8
# Epoch 5
Warmup Steps 500
Learning Rate Schedule Linear
Label Smooth 0.1 0.1 0.0
Learning Rate 0.0002
Adaptation rq=rv=4r_{q}=r_{v}=4rq​=rv​=4
LoRA α\alphaα 32
Inference
Beam Size 10
Length Penalty 0.9 0.8 0.8
no repeat ngram size 4

表 11:GPT-2 LoRA 在 E2E、WebNLG 与 DART 上的超参。

D.4 GPT-3

For all GPT-3 experiments, we train using AdamW (Loshchilov & Hutter 2017) for 2 epochs with a batch size of 128 samples and a weight decay factor of 0.1. We use a sequence length of 384 for WikiSQL (Zhong et al. 2017), 768 for MNLI (Williams et al. 2018), and 2048 for SAMSum (Gliwa et al. 2019). We tune learning rate for all method-dataset combinations. See Section D.4 for more details on the hyperparameters used. For prefix-embedding tuning, we find the optimal lpl_{p}lp​ and lil_{i}li​ to be 256 and 8, respectively, totalling 3.2M3.2M3.2M trainable parameters. We use lp=8l_{p}=8lp​=8 and li=8l_{i}=8li​=8 for prefix-layer tuning with 20.2M20.2M20.2M trainable parameters to obtain the overall best performance. We present two parameter budgets for LoRA: 4.7M (rq=rv=1r_{q}=r_{v}=1rq​=rv​=1 or rv=2r_{v}=2rv​=2) and 37.7M (rq=rv=8r_{q}=r_{v}=8rq​=rv​=8 or rq=rk=rv=ro=2r_{q}=r_{k}=r_{v}=r_{o}=2rq​=rk​=rv​=ro​=2). We report the best validation performance from each run. The training hyperparameters used in our GPT-3 experiments are listed in Table 12.

对所有 GPT-3 实验,我们用 AdamW(Loshchilov & Hutter 2017)训练 2 个 epoch,batch size 为 128 样本,权重衰减因子为 0.1。WikiSQL(Zhong et al. 2017)序列长度 384,MNLI(Williams et al. 2018)为 768,SAMSum(Gliwa et al. 2019)为 2048。我们对所有方法–数据集组合调节学习率。对 prefix-embedding tuning,我们发现最优 lpl_{p}lp​ 与 lil_{i}li​ 分别为 256 与 8,合计 3.2M3.2M3.2M 可训练参数。对 prefix-layer tuning 我们用 lp=8l_{p}=8lp​=8 与 li=8l_{i}=8li​=8,共 20.2M20.2M20.2M 可训练参数以获得总体最佳表现。我们为 LoRA 给出两个参数预算:4.7M(rq=rv=1r_{q}=r_{v}=1rq​=rv​=1 或 rv=2r_{v}=2rv​=2)与 37.7M(rq=rv=8r_{q}=r_{v}=8rq​=rv​=8 或 rq=rk=rv=ro=2r_{q}=r_{k}=r_{v}=r_{o}=2rq​=rk​=rv​=ro​=2)。我们报告每次运行的最佳验证表现。

Hyperparameters Fine-Tune PreEmbed PreLayer BitFit AdapterH\text{Adapter}^{\text{H}}AdapterH LoRA
Optimizer AdamW
Batch Size 128
# Epoch 2
Warmup Tokens 250,000
LR Schedule Linear
Learning Rate 5.00E-06 5.00E-04 1.00E-04 1.6E-03 1.00E-04 2.00E-04

Table 12: The training hyperparameters used for different GPT-3 adaption methods. We use the same hyperparameters for all datasets after tuning learning rate.

Hyperparameters Fine-Tune PreEmbed PreLayer BitFit AdapterH\text{Adapter}^{\text{H}}AdapterH LoRA
Optimizer AdamW
Batch Size 128
# Epoch 2
Warmup Tokens 250,000
LR Schedule Linear
Learning Rate 5.00E-06 5.00E-04 1.00E-04 1.6E-03 1.00E-04 2.00E-04

表 12:不同 GPT-3 适配方法所用训练超参。调节学习率后,所有数据集使用相同超参。

Appendix E Combining LoRA with Prefix Tuning

LoRA can be naturally combined with existing prefix-based approaches. In this section, we evaluate two combinations of LoRA and variants of prefix-tuning on WikiSQL and MNLI.

LoRA 可自然与现有基于 prefix 的方法结合。本节我们在 WikiSQL 与 MNLI 上评估 LoRA 与 prefix-tuning 变体的两种组合。

LoRA+PrefixEmbed (LoRA+PE) combines LoRA with prefix-embedding tuning, where we insert lp+lil_{p}+l_{i}lp​+li​ special tokens whose embeddings are treated as trainable parameters. For more on prefix-embedding tuning, see Section 5.1.

LoRA+PrefixEmbed (LoRA+PE) 把 LoRA 与 prefix-embedding tuning 结合:插入 lp+lil_{p}+l_{i}lp​+li​ 个特殊 token,其嵌入视为可训练参数。关于 prefix-embedding tuning 见第 5.1 节。

LoRA+PrefixLayer (LoRA+PL) combines LoRA with prefix-layer tuning. We also insert lp+lil_{p}+l_{i}lp​+li​ special tokens; however, instead of letting the hidden representations of these tokens evolve naturally, we replace them after every Transformer block with an input agnostic vector. Thus, both the embeddings and subsequent Transformer block activations are treated as trainable parameters. For more on prefix-layer tuning, see Section 5.1.

LoRA+PrefixLayer (LoRA+PL) 把 LoRA 与 prefix-layer tuning 结合。同样插入 lp+lil_{p}+l_{i}lp​+li​ 个特殊 token;但不是让这些 token 的隐表示自然演化,而是在每个 Transformer 块之后用与输入无关的向量替换它们。因此,嵌入以及后续 Transformer 块激活都被视为可训练参数。关于 prefix-layer tuning 见第 5.1 节。

In Table 15, we show the evaluation results of LoRA+PE and LoRA+PL on WikiSQL and MultiNLI. First of all, LoRA+PE significantly outperforms both LoRA and prefix-embedding tuning on WikiSQL, which indicates that LoRA is somewhat orthogonal to prefix-embedding tuning. On MultiNLI, the combination of LoRA+PE doesn’t perform better than LoRA, possibly because LoRA on its own already achieves performance comparable to the human baseline. Secondly, we notice that LoRA+PL performs slightly worse than LoRA even with more trainable parameters. We attribute this to the fact that prefix-layer tuning is very sensitive to the choice of learning rate and thus makes the optimization of LoRA weights more difficult in LoRA+PL.

表 15 给出 LoRA+PE 与 LoRA+PL 在 WikiSQL 与 MultiNLI 上的评估结果。首先,LoRA+PE 在 WikiSQL 上显著超过 LoRA 与 prefix-embedding tuning,表明 LoRA 与 prefix-embedding tuning 在一定程度上正交。在 MultiNLI 上,LoRA+PE 组合未超过 LoRA,可能因为单独 LoRA 已达到与人类基线可比的表现。其次,我们注意到即便可训练参数更多,LoRA+PL 仍略差于 LoRA。我们将其归因于:prefix-layer tuning 对学习率选择非常敏感,从而使 LoRA+PL 中 LoRA 权重的优化更困难。

Appendix F Additional Empirical Experiments

F.1 Additional Experiments on GPT-2

We also repeat our experiment on DART (Nan et al. 2020) and WebNLG (Gardent et al. 2017) following the setup of Li & Liang 2021. The result is shown in Table 13. Similar to our result on E2E NLG Challenge, reported in Section 5, LoRA performs better than or at least on-par with prefix-based approaches given the same number of trainable parameters.

我们还按 Li & Liang 2021 的设定在 DART(Nan et al. 2020)与 WebNLG(Gardent et al. 2017)上重复实验。结果见表 13。与第 5 节报告的 E2E NLG Challenge 结果类似,在可训练参数数相同的条件下,LoRA 表现优于或至少持平基于 prefix 的方法。

Method # Trainable DART
Parameters BLEU↑\uparrow↑ MET↑\uparrow↑ TER↓\downarrow↓
GPT-2 Medium
Fine-Tune 354M 46.2 0.39 0.46
AdapterL\text{Adapter}^{\text{L}}AdapterL 0.37M 42.4 0.36 0.48
AdapterL\text{Adapter}^{\text{L}}AdapterL 11M 45.2 0.38 0.46
FTTop2\text{FT}^{\text{Top2}}FTTop2 24M 41.0 0.34 0.56
PrefLayer 0.35M 46.4 0.38 0.46
LoRA 0.35M 47.1±\pm±.2 0.39 0.46
GPT-2 Large
Fine-Tune 774M 47.0 0.39 0.46
AdapterL\text{Adapter}^{\text{L}}AdapterL 0.88M 45.7±\pm±.1 0.38 0.46
AdapterL\text{Adapter}^{\text{L}}AdapterL 23M 47.1±\pm±.1 0.39 0.45
PrefLayer 0.77M 46.7 0.38 0.45
LoRA 0.77M 47.5±\pm±.1 0.39 0.45

Table 13: GPT-2 with different adaptation methods on DART. The variances of MET and TER are less than 0.010.010.01 for all adaption approaches.

Method # Trainable DART
Parameters BLEU↑\uparrow↑ MET↑\uparrow↑ TER↓\downarrow↓
GPT-2 Medium
Fine-Tune 354M 46.2 0.39 0.46
AdapterL\text{Adapter}^{\text{L}}AdapterL 0.37M 42.4 0.36 0.48
AdapterL\text{Adapter}^{\text{L}}AdapterL 11M 45.2 0.38 0.46
FTTop2\text{FT}^{\text{Top2}}FTTop2 24M 41.0 0.34 0.56
PrefLayer 0.35M 46.4 0.38 0.46
LoRA 0.35M 47.1±\pm±.2 0.39 0.46
GPT-2 Large
Fine-Tune 774M 47.0 0.39 0.46
AdapterL\text{Adapter}^{\text{L}}AdapterL 0.88M 45.7±\pm±.1 0.38 0.46
AdapterL\text{Adapter}^{\text{L}}AdapterL 23M 47.1±\pm±.1 0.39 0.45
PrefLayer 0.77M 46.7 0.38 0.45
LoRA 0.77M 47.5±\pm±.1 0.39 0.45

表 13:GPT-2 在 DART 上不同适配方法的结果。

Method WebNLG
BLEU↑\uparrow↑ MET↑\uparrow↑ TER↓\downarrow↓
U S A U S A U S A
GPT-2 Medium
Fine-Tune (354M) 27.7 64.2 46.5 .30 .45 .38 .76 .33 .53
AdapterL\text{Adapter}^{\text{L}}AdapterL (0.37M) 45.1 54.5 50.2 .36 .39 .38 .46 .40 .43
AdapterL\text{Adapter}^{\text{L}}AdapterL (11M) 48.3 60.4 54.9 .38 .43 .41 .45 .35 .39
FTTop2\text{FT}^{\text{Top2}}FTTop2 (24M) 18.9 53.6 36.0 .23 .38 .31 .99 .49 .72
Prefix (0.35M) 45.6 62.9 55.1 .38 .44 .41 .49 .35 .40
LoRA (0.35M) 46.7±\pm±.4 62.1±\pm±.2 55.3±\pm±.2 .38 .44 .41 .46 .33 .39
GPT-2 Large
Fine-Tune (774M) 43.1 65.3 55.5 .38 .46 .42 .53 .33 .42
AdapterL\text{Adapter}^{\text{L}}AdapterL (0.88M) 49.8±\pm±.0 61.1±\pm±.0 56.0±\pm±.0 .38 .43 .41 .44 .35 .39
AdapterL\text{Adapter}^{\text{L}}AdapterL (23M) 49.2±\pm±.1 64.7±\pm±.2 57.7±\pm±.1 .39 .46 .43 .46 .33 .39
Prefix (0.77M) 47.7 63.4 56.3 .39 .45 .42 .48 .34 .40
LoRA (0.77M) 48.4±\pm±.3 64.0±\pm±.3 57.0±\pm±.1 .39 .45 .42 .45 .32 .38

Table 14: GPT-2 with different adaptation methods on WebNLG. The variances of MET and TER are less than 0.010.010.01 for all the experiments we ran. “U” indicates unseen categories, “S” indicates seen categories, and “A” indicates all categories in the test set of WebNLG.

Method WebNLG
BLEU↑\uparrow↑ MET↑\uparrow↑ TER↓\downarrow↓
U S A U S A U S A
GPT-2 Medium
Fine-Tune (354M) 27.7 64.2 46.5 .30 .45 .38 .76 .33 .53
AdapterL\text{Adapter}^{\text{L}}AdapterL (0.37M) 45.1 54.5 50.2 .36 .39 .38 .46 .40 .43
AdapterL\text{Adapter}^{\text{L}}AdapterL (11M) 48.3 60.4 54.9 .38 .43 .41 .45 .35 .39
FTTop2\text{FT}^{\text{Top2}}FTTop2 (24M) 18.9 53.6 36.0 .23 .38 .31 .99 .49 .72
Prefix (0.35M) 45.6 62.9 55.1 .38 .44 .41 .49 .35 .40
LoRA (0.35M) 46.7±\pm±.4 62.1±\pm±.2 55.3±\pm±.2 .38 .44 .41 .46 .33 .39
GPT-2 Large
Fine-Tune (774M) 43.1 65.3 55.5 .38 .46 .42 .53 .33 .42
AdapterL\text{Adapter}^{\text{L}}AdapterL (0.88M) 49.8±\pm±.0 61.1±\pm±.0 56.0±\pm±.0 .38 .43 .41 .44 .35 .39
AdapterL\text{Adapter}^{\text{L}}AdapterL (23M) 49.2±\pm±.1 64.7±\pm±.2 57.7±\pm±.1 .39 .46 .43 .46 .33 .39
Prefix (0.77M) 47.7 63.4 56.3 .39 .45 .42 .48 .34 .40
LoRA (0.77M) 48.4±\pm±.3 64.0±\pm±.3 57.0±\pm±.1 .39 .45 .42 .45 .32 .38

表 14:GPT-2 在 WebNLG 上不同适配方法的结果(U/S/A 分别为未见/已见/全部)。

F.2 Additional Experiments on GPT-3

We present additional runs on GPT-3 with different adaptation methods in Table 15. The focus is on identifying the trade-off between performance and the number of trainable parameters.

我们在表 15 中给出 GPT-3 上不同适配方法的额外运行。重点在于识别表现与可训练参数数之间的权衡。

Method Hyperparameters # Trainable Parameters WikiSQL MNLI-m
Fine-Tune - 175B 73.8 89.5
PrefixEmbed lp=32,li=8l_{p}=32,l_{i}=8lp​=32,li​=8 0.4 M 55.9 84.9
lp=64,li=8l_{p}=64,l_{i}=8lp​=64,li​=8 0.9 M 58.7 88.1
lp=128,li=8l_{p}=128,l_{i}=8lp​=128,li​=8 1.7 M 60.6 88.0
lp=256,li=8l_{p}=256,l_{i}=8lp​=256,li​=8 3.2 M 63.1 88.6
lp=512,li=8l_{p}=512,l_{i}=8lp​=512,li​=8 6.4 M 55.9 85.8
PrefixLayer lp=2,li=2l_{p}=2,l_{i}=2lp​=2,li​=2 5.1 M 68.5 89.2
lp=8,li=0l_{p}=8,l_{i}=0lp​=8,li​=0 10.1 M 69.8 88.2
lp=8,li=8l_{p}=8,l_{i}=8lp​=8,li​=8 20.2 M 70.1 89.5
lp=32,li=4l_{p}=32,l_{i}=4lp​=32,li​=4 44.1 M 66.4 89.6
lp=64,li=0l_{p}=64,l_{i}=0lp​=64,li​=0 76.1 M 64.9 87.9
AdapterH\text{Adapter}^{\text{H}}AdapterH r=1r=1r=1 7.1 M 71.9 89.8
r=4r=4r=4 21.2 M 73.2 91.0
r=8r=8r=8 40.1 M 73.2 91.5
r=16r=16r=16 77.9 M 73.2 91.5
r=64r=64r=64 304.4 M 72.6 91.5
LoRA rv=2r_{v}=2rv​=2 4.7 M 73.4 91.7
rq=rv=1r_{q}=r_{v}=1rq​=rv​=1 4.7 M 73.4 91.3
rq=rv=2r_{q}=r_{v}=2rq​=rv​=2 9.4 M 73.3 91.4
rq=rk=rv=ro=1r_{q}=r_{k}=r_{v}=r_{o}=1rq​=rk​=rv​=ro​=1 9.4 M 74.1 91.2
rq=rv=4r_{q}=r_{v}=4rq​=rv​=4 18.8 M 73.7 91.3
rq=rk=rv=ro=2r_{q}=r_{k}=r_{v}=r_{o}=2rq​=rk​=rv​=ro​=2 18.8 M 73.7 91.7
rq=rv=8r_{q}=r_{v}=8rq​=rv​=8 37.7 M 73.8 91.6
rq=rk=rv=ro=4r_{q}=r_{k}=r_{v}=r_{o}=4rq​=rk​=rv​=ro​=4 37.7 M 74.0 91.7
rq=rv=64r_{q}=r_{v}=64rq​=rv​=64 301.9 M 73.6 91.4
rq=rk=rv=ro=64r_{q}=r_{k}=r_{v}=r_{o}=64rq​=rk​=rv​=ro​=64 603.8 M 73.9 91.4
LoRA+PE rq=rv=8,lp=8,li=4r_{q}=r_{v}=8,l_{p}=8,l_{i}=4rq​=rv​=8,lp​=8,li​=4 37.8 M 75.0 91.4
rq=rv=32,lp=8,li=4r_{q}=r_{v}=32,l_{p}=8,l_{i}=4rq​=rv​=32,lp​=8,li​=4 151.1 M 75.9 91.1
rq=rv=64,lp=8,li=4r_{q}=r_{v}=64,l_{p}=8,l_{i}=4rq​=rv​=64,lp​=8,li​=4 302.1 M 76.2 91.3
LoRA+PL rq=rv=8,lp=8,li=4r_{q}=r_{v}=8,l_{p}=8,l_{i}=4rq​=rv​=8,lp​=8,li​=4 52.8 M 72.9 90.2

Table 15: Hyperparameter analysis of different adaptation approaches on WikiSQL and MNLI. Both prefix-embedding tuning (PrefixEmbed) and prefix-layer tuning (PrefixLayer) perform worse as we increase the number of trainable parameters, while LoRA’s performance stabilizes. Performance is measured in validation accuracy.

Method Hyperparameters # Trainable Parameters WikiSQL MNLI-m
Fine-Tune - 175B 73.8 89.5
PrefixEmbed lp=32,li=8l_{p}=32,l_{i}=8lp​=32,li​=8 0.4 M 55.9 84.9
lp=64,li=8l_{p}=64,l_{i}=8lp​=64,li​=8 0.9 M 58.7 88.1
lp=128,li=8l_{p}=128,l_{i}=8lp​=128,li​=8 1.7 M 60.6 88.0
lp=256,li=8l_{p}=256,l_{i}=8lp​=256,li​=8 3.2 M 63.1 88.6
lp=512,li=8l_{p}=512,l_{i}=8lp​=512,li​=8 6.4 M 55.9 85.8
PrefixLayer lp=2,li=2l_{p}=2,l_{i}=2lp​=2,li​=2 5.1 M 68.5 89.2
lp=8,li=0l_{p}=8,l_{i}=0lp​=8,li​=0 10.1 M 69.8 88.2
lp=8,li=8l_{p}=8,l_{i}=8lp​=8,li​=8 20.2 M 70.1 89.5
lp=32,li=4l_{p}=32,l_{i}=4lp​=32,li​=4 44.1 M 66.4 89.6
lp=64,li=0l_{p}=64,l_{i}=0lp​=64,li​=0 76.1 M 64.9 87.9
AdapterH\text{Adapter}^{\text{H}}AdapterH r=1r=1r=1 7.1 M 71.9 89.8
r=4r=4r=4 21.2 M 73.2 91.0
r=8r=8r=8 40.1 M 73.2 91.5
r=16r=16r=16 77.9 M 73.2 91.5
r=64r=64r=64 304.4 M 72.6 91.5
LoRA rv=2r_{v}=2rv​=2 4.7 M 73.4 91.7
rq=rv=1r_{q}=r_{v}=1rq​=rv​=1 4.7 M 73.4 91.3
rq=rv=2r_{q}=r_{v}=2rq​=rv​=2 9.4 M 73.3 91.4
rq=rk=rv=ro=1r_{q}=r_{k}=r_{v}=r_{o}=1rq​=rk​=rv​=ro​=1 9.4 M 74.1 91.2
rq=rv=4r_{q}=r_{v}=4rq​=rv​=4 18.8 M 73.7 91.3
rq=rk=rv=ro=2r_{q}=r_{k}=r_{v}=r_{o}=2rq​=rk​=rv​=ro​=2 18.8 M 73.7 91.7
rq=rv=8r_{q}=r_{v}=8rq​=rv​=8 37.7 M 73.8 91.6
rq=rk=rv=ro=4r_{q}=r_{k}=r_{v}=r_{o}=4rq​=rk​=rv​=ro​=4 37.7 M 74.0 91.7
rq=rv=64r_{q}=r_{v}=64rq​=rv​=64 301.9 M 73.6 91.4
rq=rk=rv=ro=64r_{q}=r_{k}=r_{v}=r_{o}=64rq​=rk​=rv​=ro​=64 603.8 M 73.9 91.4
LoRA+PE rq=rv=8,lp=8,li=4r_{q}=r_{v}=8,l_{p}=8,l_{i}=4rq​=rv​=8,lp​=8,li​=4 37.8 M 75.0 91.4
rq=rv=32,lp=8,li=4r_{q}=r_{v}=32,l_{p}=8,l_{i}=4rq​=rv​=32,lp​=8,li​=4 151.1 M 75.9 91.1
rq=rv=64,lp=8,li=4r_{q}=r_{v}=64,l_{p}=8,l_{i}=4rq​=rv​=64,lp​=8,li​=4 302.1 M 76.2 91.3
LoRA+PL rq=rv=8,lp=8,li=4r_{q}=r_{v}=8,l_{p}=8,l_{i}=4rq​=rv​=8,lp​=8,li​=4 52.8 M 72.9 90.2

表 15:GPT-3 上不同适配方法在 WikiSQL 与 MNLI-m 上相对可训练参数数的额外结果。

F.3 Low-Data Regime

To evaluate the performance of different adaptation approaches in the low-data regime. we randomly sample 100, 1k and 10k training examples from the full training set of MNLI to form the low-data MNLI-nnn tasks. In Table 16, we show the performance of different adaptation approaches on MNLI-nnn. To our surprise, PrefixEmbed and PrefixLayer performs very poorly on MNLI-100 dataset, with PrefixEmbed performing only slightly better than random chance (37.6% vs. 33.3%). PrefixLayer performs better than PrefixEmbed but is still significantly worse than Fine-Tune or LoRA on MNLI-100. The gap between prefix-based approaches and LoRA/Fine-tuning becomes smaller as we increase the number of training examples, which might suggest that prefix-based approaches are not suitable for low-data tasks in GPT-3. LoRA achieves better performance than fine-tuning on both MNLI-100 and MNLI-Full, and comparable results on MNLI-1k and MNLI-10K considering the (±0.3\pm 0.3±0.3) variance due to random seeds.

为评估低数据设定下不同适配方法的表现,我们从 MNLI 完整训练集随机采样 100、1k 与 10k 个训练样本,构成低数据 MNLI-nnn 任务。表 16 给出不同适配方法在 MNLI-nnn 上的表现。令我们惊讶的是,PrefixEmbed 与 PrefixLayer 在 MNLI-100 上表现很差,PrefixEmbed 仅略好于随机猜测(37.6% vs. 33.3%)。PrefixLayer 好于 PrefixEmbed,但在 MNLI-100 上仍显著差于 Fine-Tune 或 LoRA。随着训练样本增多,基于 prefix 的方法与 LoRA/微调之间的差距缩小。

Method MNLI(m)-100 MNLI(m)-1k MNLI(m)-10k MNLI(m)-392K
GPT-3 (Fine-Tune) 60.2 85.8 88.9 89.5
GPT-3 (PrefixEmbed) 37.6 75.2 79.5 88.6
GPT-3 (PrefixLayer) 48.3 82.5 85.9 89.6
GPT-3 (LoRA) 63.8 85.6 89.2 91.7

Table 16: Validation accuracy of different methods on subsets of MNLI using GPT-3 175B. MNLI-nnn describes a subset with nnn training examples. We evaluate with the full validation set. LoRA performs exhibits favorable sample-efficiency compared to other methods, including fine-tuning.

Method MNLI(m)-100 MNLI(m)-1k MNLI(m)-10k MNLI(m)-392K
GPT-3 (Fine-Tune) 60.2 85.8 88.9 89.5
GPT-3 (PrefixEmbed) 37.6 75.2 79.5 88.6
GPT-3 (PrefixLayer) 48.3 82.5 85.9 89.6
GPT-3 (LoRA) 63.8 85.6 89.2 91.7

表 16:用 GPT-3 175B 在 MNLI 子集上不同方法的验证准确率。MNLI-nnn 表示含 nnn 个训练样本的子集。我们用完整验证集评估。相对其他方法(含微调),LoRA 展现有利的样本效率。

The training hyperparameters of different adaptation approaches on MNLI-n are reported in Table 17. We use a smaller learning rate for PrefixLayer on the MNLI-100 set, as the training loss does not decrease with a larger learning rate.

不同适配方法在 MNLI-n 上的训练超参见表 17。对 MNLI-100 上的 PrefixLayer 我们使用更小学习率,因为更大的学习率下训练损失不下降。

Hyperparameters Adaptation MNLI-100 MNLI-1k MNLI-10K MNLI-392K
Optimizer - AdamW
Warmup Tokens - 250,000
LR Schedule - Linear
Batch Size - 20 20 100 128
# Epoch - 40 40 4 2
Learning Rate FineTune 5.00E-6
PrefixEmbed 2.00E-04 2.00E-04 4.00E-04 5.00E-04
PrefixLayer 5.00E-05 5.00E-05 5.00E-05 1.00E-04
LoRA 2.00E-4
PrefixEmbed lpl_{p}lp​ 16 32 64 256
Adaptation- PrefixEmbed lil_{i}li​ 8
Specific PrefixTune lp=li=8l_{p}=l_{i}=8lp​=li​=8
LoRA rq=rv=8r_{q}=r_{v}=8rq​=rv​=8

Table 17: The hyperparameters used for different GPT-3 adaptation methods on MNLI(m)-nnn.

Hyperparameters Adaptation MNLI-100 MNLI-1k MNLI-10K MNLI-392K
Optimizer - AdamW
Warmup Tokens - 250,000
LR Schedule - Linear
Batch Size - 20 20 100 128
# Epoch - 40 40 4 2
Learning Rate FineTune 5.00E-6
PrefixEmbed 2.00E-04 2.00E-04 4.00E-04 5.00E-04
PrefixLayer 5.00E-05 5.00E-05 5.00E-05 1.00E-04
LoRA 2.00E-4
PrefixEmbed lpl_{p}lp​ 16 32 64 256
Adaptation- PrefixEmbed lil_{i}li​ 8
Specific PrefixTune lp=li=8l_{p}=l_{i}=8lp​=li​=8
LoRA rq=rv=8r_{q}=r_{v}=8rq​=rv​=8

表 17:MNLI-nnn 上不同适配方法的训练超参。

Appendix G Measuring Similarity Between Subspaces

In this paper we use the measure ϕ(A,B,i,j)=ψ(UAi,UBj)=∥UAi⊤UB∥F2min⁡{i,j}\phi(A,B,i,j)=\psi(U_{A}^{i},U_{B}^{j})=\frac{\|U_{A}^{i\top}U_{B}\|_{F}^{2}}{\min\{i,j\}}ϕ(A,B,i,j)=ψ(UAi​,UBj​)=min{i,j}∥UAi⊤​UB​∥F2​​ to measure the subspace similarity between two column orthonormal matrices UAi∈Rd×iU_{A}^{i}\in\mathbb{R}^{d\times i}UAi​∈Rd×i and UBj∈Rd×jU_{B}^{j}\in\mathbb{R}^{d\times j}UBj​∈Rd×j, obtained by taking columns of the left singular matrices of AAA and BBB. We point out that this similarity is simply a reverse of the standard Projection Metric that measures distance between subspaces Ham & Lee 2008.

本文使用度量 ϕ(A,B,i,j)=ψ(UAi,UBj)=∥UAi⊤UB∥F2min⁡{i,j}\phi(A,B,i,j)=\psi(U_{A}^{i},U_{B}^{j})=\frac{\|U_{A}^{i\top}U_{B}\|_{F}^{2}}{\min\{i,j\}}ϕ(A,B,i,j)=ψ(UAi​,UBj​)=min{i,j}∥UAi⊤​UB​∥F2​​ 来衡量两个列正交矩阵 UAi∈Rd×iU_{A}^{i}\in\mathbb{R}^{d\times i}UAi​∈Rd×i 与 UBj∈Rd×jU_{B}^{j}\in\mathbb{R}^{d\times j}UBj​∈Rd×j 之间的子空间相似度;二者分别取自 AAA 与 BBB 左奇异矩阵的列。我们指出:该相似度只是衡量子空间距离的标准投影度量(Projection Metric,Ham & Lee 2008)的反转。

To be concrete, let the singular values of UAi⊤UBjU_{A}^{i\top}U_{B}^{j}UAi⊤​UBj​ to be σ1,σ2,⋯ ,σp\sigma_{1},\sigma_{2},\cdots,\sigma_{p}σ1​,σ2​,⋯,σp​ where p=min⁡{i,j}p=\min\{i,j\}p=min{i,j}. We know that the Projection Metric Ham & Lee 2008 is defined as:

具体地,设 UAi⊤UBjU_{A}^{i\top}U_{B}^{j}UAi⊤​UBj​ 的奇异值为 σ1,σ2,⋯ ,σp\sigma_{1},\sigma_{2},\cdots,\sigma_{p}σ1​,σ2​,⋯,σp​,其中 p=min⁡{i,j}p=\min\{i,j\}p=min{i,j}。我们知道投影度量(Ham & Lee 2008)定义为:

d(UAi,UBj)=p−∑i=1pσi2∈[0,p]d(U_{A}^{i},U_{B}^{j})=\sqrt{p-\sum_{i=1}^{p}\sigma_{i}^{2}}\in[0,\sqrt{p}]d(UAi​,UBj​)=p−i=1∑p​σi2​​∈[0,p​]

where our similarity is defined as:

而我们的相似度定义为:

ϕ(A,B,i,j)=ψ(UAi,UBj)=∑i=1pσi2p=1p(1−d(UAi,UBj)2)\phi(A,B,i,j)=\psi(U_{A}^{i},U_{B}^{j})=\frac{\sum_{i=1}^{p}\sigma_{i}^{2}}{p}=\frac{1}{p}\left(1-d(U_{A}^{i},U_{B}^{j})^{2}\right)ϕ(A,B,i,j)=ψ(UAi​,UBj​)=p∑i=1p​σi2​​=p1​(1−d(UAi​,UBj​)2)

This similarity satisfies that if UAiU_{A}^{i}UAi​ and UBjU_{B}^{j}UBj​ share the same column span, then ϕ(A,B,i,j)=1\phi(A,B,i,j)=1ϕ(A,B,i,j)=1. If they are completely orthogonal, then ϕ(A,B,i,j)=0\phi(A,B,i,j)=0ϕ(A,B,i,j)=0. Otherwise, ϕ(A,B,i,j)∈(0,1)\phi(A,B,i,j)\in(0,1)ϕ(A,B,i,j)∈(0,1).

该相似度满足:若 UAiU_{A}^{i}UAi​ 与 UBjU_{B}^{j}UBj​ 共享相同列空间,则 ϕ(A,B,i,j)=1\phi(A,B,i,j)=1ϕ(A,B,i,j)=1;若完全正交,则 ϕ(A,B,i,j)=0\phi(A,B,i,j)=0ϕ(A,B,i,j)=0;否则 ϕ(A,B,i,j)∈(0,1)\phi(A,B,i,j)\in(0,1)ϕ(A,B,i,j)∈(0,1)。

Appendix H Additional Experiments on Low-Rank Matrices

We present additional results from our investigation into the low-rank update matrices.

我们给出对低秩更新矩阵调查的额外结果。

H.1 Correlation between LoRA Modules

See Figure 6 and Figure 7 for how the results presented in Figure 3 and Figure 4 generalize to other layers.

见图 6 与图 7:图 3 与图 4 所示结果如何推广到其他层。

Figure 6

Figure 6: Normalized subspace similarity between the column vectors of Ar=8A_{r=8}Ar=8​ and Ar=64A_{r=64}Ar=64​ for both ΔWq\Delta W_{q}ΔWq​ and ΔWv\Delta W_{v}ΔWv​ from the 1st, 32nd, 64th, and 96th layers in a 96-layer Transformer.

图 6:96 层 Transformer 中第 1、32、64、96 层上,Ar=8A_{r=8}Ar=8​ 与 Ar=64A_{r=64}Ar=64​ 列向量之间的归一化子空间相似度(对 ΔWq\Delta W_{q}ΔWq​ 与 ΔWv\Delta W_{v}ΔWv​)。

Figure 7

Figure 7: Normalized subspace similarity between the column vectors of Ar=64A_{r=64}Ar=64​ from two randomly seeded runs, for both ΔWq\Delta W_{q}ΔWq​ and ΔWv\Delta W_{v}ΔWv​ from the 1st, 32nd, 64th, and 96th layers in a 96-layer Transformer.

图 7:96 层 Transformer 中第 1、32、64、96 层上,两个随机种子运行得到的 Ar=64A_{r=64}Ar=64​ 列向量之间的归一化子空间相似度(对 ΔWq\Delta W_{q}ΔWq​ 与 ΔWv\Delta W_{v}ΔWv​)。

H.2 Effect of rrr on GPT-2

We repeat our experiment on the effect of rrr (Section 7.2) in GPT-2. Using the E2E NLG Challenge dataset as an example, we report the validation loss and test metrics achieved by different choices of rrr after training for 26,000 steps. We present our result in Table 18. The optimal rank for GPT-2 Medium is between 4 and 16 depending on the metric used, which is similar to that for GPT-3 175B. Note that the relationship between model size and the optimal rank for adaptation is still an open question.

我们在 GPT-2 上重复关于 rrr 影响的实验(第 7.2 节)。以 E2E NLG Challenge 数据集为例,我们报告训练 26,000 步后不同 rrr 选择达到的验证损失与测试指标。结果见表 18。GPT-2 Medium 的最优秩依所用指标约在 4 到 16 之间,与 GPT-3 175B 相近。注意模型规模与适配最优秩之间的关系仍是开放问题。

Rank rrr val_loss BLEU NIST METEOR ROUGE_L CIDEr
1 1.23 68.72 8.7215 0.4565 0.7052 2.4329
2 1.21 69.17 8.7413 0.4590 0.7052 2.4639
4 1.18 70.38 8.8439 0.4689 0.7186 2.5349
8 1.17 69.57 8.7457 0.4636 0.7196 2.5196
16 1.16 69.61 8.7483 0.4629 0.7177 2.4985
32 1.16 69.33 8.7736 0.4642 0.7105 2.5255
64 1.16 69.24 8.7174 0.4651 0.7180 2.5070
128 1.16 68.73 8.6718 0.4628 0.7127 2.5030
256 1.16 68.92 8.6982 0.4629 0.7128 2.5012
512 1.16 68.78 8.6857 0.4637 0.7128 2.5025
1024 1.17 69.37 8.7495 0.4659 0.7149 2.5090

Table 18: Validation loss and test set metrics on E2E NLG Challenge achieved by LoRA with different rank rrr using GPT-2 Medium. Unlike on GPT-3 where r=1r=1r=1 suffices for many tasks, here the performance peaks at r=16r=16r=16 for validation loss and r=4r=4r=4 for BLEU, suggesting the GPT-2 Medium has a similar intrinsic rank for adaptation compared to GPT-3 175B. Note that some of our hyperparameters are tuned on r=4r=4r=4, which matches the parameter count of another baseline, and thus might not be optimal for other choices of rrr.

Rank rrr val_loss BLEU NIST METEOR ROUGE_L CIDEr
1 1.23 68.72 8.7215 0.4565 0.7052 2.4329
2 1.21 69.17 8.7413 0.4590 0.7052 2.4639
4 1.18 70.38 8.8439 0.4689 0.7186 2.5349
8 1.17 69.57 8.7457 0.4636 0.7196 2.5196
16 1.16 69.61 8.7483 0.4629 0.7177 2.4985
32 1.16 69.33 8.7736 0.4642 0.7105 2.5255
64 1.16 69.24 8.7174 0.4651 0.7180 2.5070
128 1.16 68.73 8.6718 0.4628 0.7127 2.5030
256 1.16 68.92 8.6982 0.4629 0.7128 2.5012
512 1.16 68.78 8.6857 0.4637 0.7128 2.5025
1024 1.17 69.37 8.7495 0.4659 0.7149 2.5090

表 18:GPT-2 Medium 上不同秩 rrr 在 E2E 上的验证损失与测试指标。

H.3 Correlation between WWW and ΔW\Delta WΔW

See Figure 8 for the normalized subspace similarity between WWW and ΔW\Delta WΔW with varying rrr.

见图 8:WWW 与 ΔW\Delta WΔW 在不同 rrr 下的归一化子空间相似度。

Note again that ΔW\Delta WΔW does not contain the top singular directions of WWW, since the similarity between the top 4 directions in ΔW\Delta WΔW and the top-10% of those in WWW barely exceeds 0.2. This gives evidence that ΔW\Delta WΔW contains those “task-specific” directions that are otherwise not emphasized in WWW.

再次注意:ΔW\Delta WΔW 并不包含 WWW 的顶部奇异方向,因为 ΔW\Delta WΔW 前 4 个方向与 WWW 前 10% 方向之间的相似度几乎不超过 0.2。这给出证据:ΔW\Delta WΔW 包含那些在 WWW 中未被强调的“任务特定”方向。

An interesting next question to answer, is how “strong” do we need to amplify those task-specific directions, in order for the model adaptation to work well?

下一个有趣的问题是:为使模型适配表现良好,我们需要把这些任务特定方向放大到多“强”?

Figure 8

Figure 8: Normalized subspace similarity between the singular directions of WqW_{q}Wq​ and those of ΔWq\Delta W_{q}ΔWq​ with varying rrr and a random baseline. ΔWq\Delta W_{q}ΔWq​ amplifies directions that are important but not emphasized in WWW. ΔW\Delta WΔW with a larger rrr tends to pick up more directions that are already emphasized in WWW.

图 8:WqW_{q}Wq​ 与 ΔWq\Delta W_{q}ΔWq​ 奇异方向之间的归一化子空间相似度(随 rrr 变化,并含随机基线)。ΔWq\Delta W_{q}ΔWq​ 放大在 WWW 中重要但未被强调的方向。更大 rrr 的 ΔW\Delta WΔW 倾向于拾取更多已在 WWW 中被强调的方向。

H.4 Amplification Factor

One can naturally consider a feature amplification factor as the ratio ∥ΔW∥F∥U⊤WV⊤∥F\frac{\|\Delta W\|_{F}}{\|U^{\top}WV^{\top}\|_{F}}∥U⊤WV⊤∥F​∥ΔW∥F​​, where UUU and VVV are the left- and right-singular matrices of the SVD decomposition of ΔW\Delta WΔW. (Recall UU⊤WV⊤VUU^{\top}WV^{\top}VUU⊤WV⊤V gives the “projection” of WWW onto the subspace spanned by ΔW\Delta WΔW.)

人们可自然考虑特征放大因子为比值 ∥ΔW∥F∥U⊤WV⊤∥F\frac{\|\Delta W\|_{F}}{\|U^{\top}WV^{\top}\|_{F}}∥U⊤WV⊤∥F​∥ΔW∥F​​,其中 UUU 与 VVV 为 ΔW\Delta WΔW 的 SVD 分解的左、右奇异矩阵。(回想 UU⊤WV⊤VUU^{\top}WV^{\top}VUU⊤WV⊤V 给出 WWW 到 ΔW\Delta WΔW 张成子空间上的“投影”。)

Intuitively, when ΔW\Delta WΔW mostly contains task-specific directions, this quantity measures how much of them are amplified by ΔW\Delta WΔW. As shown in Section 7.3, for r=4r=4r=4, this amplification factor is as large as 20. In other words, there are (generally speaking) four feature directions in each layer (out of the entire feature space from the pre-trained model WWW), that need to be amplified by a very large factor 20, in order to achieve our reported accuracy for the downstream specific task. And, one should expect a very different set of feature directions to be amplified for each different downstream task.

直观上,当 ΔW\Delta WΔW 主要包含任务特定方向时,该量衡量它们被 ΔW\Delta WΔW 放大了多少。如第 7.3 节所示,对 r=4r=4r=4,该放大因子可高达 20。换言之,(一般而言)每层有四个特征方向(来自预训练模型 WWW 的整个特征空间),需要被放大约 20 倍的很大因子,才能达到我们报告的下游特定任务准确率。并且,对每个不同下游任务,应预期被放大的特征方向集合非常不同。

One may notice, however, for r=64r=64r=64, this amplification factor is only around 2, meaning that most directions learned in ΔW\Delta WΔW with r=64r=64r=64 are not being amplified by much. This should not be surprising, and in fact gives evidence (once again) that the intrinsic rank needed to represent the “task-specific directions” (thus for model adaptation) is low. In contrast, those directions in the rank-4 version of ΔW\Delta WΔW (corresponding to r=4r=4r=4) are amplified by a much larger factor 20.

然而人们可能注意到:对 r=64r=64r=64,该放大因子仅约 2,意味着用 r=64r=64r=64 在 ΔW\Delta WΔW 中学到的大多数方向并未被大幅放大。这并不令人惊讶,事实上再次给出证据:表示“任务特定方向”(从而用于模型适配)所需的本征秩是低的。相比之下,ΔW\Delta WΔW 的秩-4 版本(对应 r=4r=4r=4)中的那些方向被放大了大得多的因子 20。