{"notes":[{"id":"model-tuning/lora","category":"model-tuning","legacyPath":"model-tuning/2106-lora","legacySlug":"2106-lora","legacyPaths":[],"title":"LoRA","subtitle":"One in Ten Thousand LLM","author":"Z. Yuan","paperDate":"2021-06-17","publishedOn":"2024-10-26","paperTitle":"LoRA: Low-Rank Adaptation of Large Language Models","paperUrl":"https://arxiv.org/abs/2106.09685","bibliography":{"title":"LoRA: Low-Rank Adaptation of Large Language Models","authors":["Edward J. Hu","Yelong Shen","Phillip Wallis","Zeyuan Allen-Zhu","Yuanzhi Li","Shean Wang","Lu Wang","Weizhu Chen"],"url":"https://arxiv.org/abs/2106.09685","pdfUrl":"https://arxiv.org/pdf/2106.09685","codeUrl":null,"preprint":{"id":"2106.09685","submittedOn":"2021-06-17","url":"https://arxiv.org/abs/2106.09685"},"publication":{"venue":"ICLR","year":2022,"kind":"conference","url":"https://openreview.net/pdf?id=nZeVKeeFYf9"},"citation":"@misc{modeltuninglora2021,\n  title = {{LoRA: Low-Rank Adaptation of Large Language Models}},\n  author = {Edward J. Hu and Yelong Shen and Phillip Wallis and Zeyuan Allen-Zhu and Yuanzhi Li and Shean Wang and Lu Wang and Weizhu Chen},\n  year = {2021},\n  eprint = {2106.09685},\n  archivePrefix = {arXiv},\n  url = {https://arxiv.org/abs/2106.09685}\n}\n","citationPath":"/content/papers/citations/model-tuning/lora.e23eb465372e.bib"},"thumbnail":{"src":"/content/papers/assets/547204d875b324a959dc2fb7c92601337563d9262cd3612847a3a772d092c53f.jpg","width":516,"height":472},"locale":"en","path":"/content/papers/en/model-tuning/lora.2b41c1123168.md","headings":[{"id":"defining-the-problem","text":"Defining the Problem","depth":2},{"id":"solving-the-problem","text":"Solving the Problem","depth":2},{"id":"rank-full-rank-and-low-rank","text":"Rank, Full Rank, and Low Rank","depth":3},{"id":"why-are-low-rank-matrices-useful","text":"Why Are Low-Rank Matrices Useful?","depth":3},{"id":"low-rank-decomposition-lora","text":"Low-Rank Decomposition: LoRA","depth":3},{"id":"lora-on-transformer-models","text":"LoRA on Transformer Models","depth":3},{"id":"discussion","text":"Discussion","depth":2},{"id":"experimental-baselines","text":"Experimental Baselines","depth":3},{"id":"comparison-with-other-fine-tuning-methods","text":"Comparison with Other Fine-Tuning Methods","depth":3},{"id":"fine-tuning-gpt-3","text":"Fine-Tuning GPT-3","depth":3},{"id":"which-weight-matrices-should-lora-target-in-transformers","text":"Which Weight Matrices Should LoRA Target in Transformers?","depth":3},{"id":"what-is-the-optimal-rank-r-for-lora","text":"What is the Optimal Rank r for LoRA?","depth":3},{"id":"subspace-similarity-analysis","text":"Subspace Similarity Analysis","depth":3},{"id":"conclusion","text":"Conclusion","depth":2}],"anchorAliases":{},"guide":null,"relatedReading":[{"id":"model-tuning/adapter","relation":"comparison","topic":"Adapting a model with fewer trainable parameters"},{"id":"model-tuning/prefix-tuning","relation":"comparison","topic":"Adapting a model with fewer trainable parameters"}]},{"id":"model-tuning/adapter","category":"model-tuning","legacyPath":"model-tuning/1902-adapter","legacySlug":"1902-adapter","legacyPaths":[],"title":"Adapter","subtitle":"Saving 96% of Parameters","author":"Z. Yuan","paperDate":"2019-02-02","publishedOn":"2024-05-16","paperTitle":"Parameter-Efficient Transfer Learning for NLP","paperUrl":"https://arxiv.org/abs/1902.00751","bibliography":{"title":"Parameter-Efficient Transfer Learning for NLP","authors":["Neil Houlsby","Andrei Giurgiu","Stanislaw Jastrzebski","Bruna Morrone","Quentin de Laroussilhe","Andrea Gesmundo","Mona Attariyan","Sylvain Gelly"],"url":"https://arxiv.org/abs/1902.00751","pdfUrl":"https://arxiv.org/pdf/1902.00751","codeUrl":null,"preprint":{"id":"1902.00751","submittedOn":"2019-02-02","url":"https://arxiv.org/abs/1902.00751"},"publication":{"venue":"ICML","year":2019,"kind":"conference","url":"https://proceedings.mlr.press/v97/houlsby19a.html"},"citation":"@misc{modeltuningadapter2019,\n  title = {{Parameter-Efficient Transfer Learning for NLP}},\n  author = {Neil Houlsby and Andrei Giurgiu and Stanislaw Jastrzebski and Bruna Morrone and Quentin de Laroussilhe and Andrea Gesmundo and Mona Attariyan and Sylvain Gelly},\n  year = {2019},\n  eprint = {1902.00751},\n  archivePrefix = {arXiv},\n  url = {https://arxiv.org/abs/1902.00751}\n}\n","citationPath":"/content/papers/citations/model-tuning/adapter.fa08e84b43d7.bib"},"thumbnail":{"src":"/content/papers/assets/8bca77531dbddb82e18f6dedd27d962405dc5c7a0f976c6c0d09a501c918c122.jpg","width":980,"height":712},"locale":"en","path":"/content/papers/en/model-tuning/adapter.0bd929e0bef7.md","headings":[{"id":"defining-the-problem","text":"Defining the Problem","depth":2},{"id":"wastefulness","text":"Wastefulness","depth":3},{"id":"solving-the-problem","text":"Solving the Problem","depth":2},{"id":"discussion","text":"Discussion","depth":2},{"id":"glue-evaluation","text":"GLUE Evaluation","depth":3},{"id":"ablation-study","text":"Ablation Study","depth":3},{"id":"conclusion","text":"Conclusion","depth":2}],"anchorAliases":{},"guide":null,"relatedReading":[{"id":"model-tuning/lora","relation":"comparison","topic":"Adapting a model with fewer trainable parameters"},{"id":"model-tuning/prefix-tuning","relation":"comparison","topic":"Adapting a model with fewer trainable parameters"}]},{"id":"model-tuning/prefix-tuning","category":"model-tuning","legacyPath":"model-tuning/2101-prefix-tuning","legacySlug":"2101-prefix-tuning","legacyPaths":[],"title":"Prefix-Tuning","subtitle":"Is it the Same or Different?","author":"Z. Yuan","paperDate":"2021-01-01","publishedOn":"2024-10-30","paperTitle":"Prefix-Tuning: Optimizing Continuous Prompts for Generation","paperUrl":"https://arxiv.org/abs/2101.00190","bibliography":{"title":"Prefix-Tuning: Optimizing Continuous Prompts for Generation","authors":["Xiang Lisa Li","Percy Liang"],"url":"https://arxiv.org/abs/2101.00190","pdfUrl":"https://arxiv.org/pdf/2101.00190","codeUrl":null,"preprint":{"id":"2101.00190","submittedOn":"2021-01-01","url":"https://arxiv.org/abs/2101.00190"},"publication":{"venue":"ACL-IJCNLP","year":2021,"kind":"conference","url":"https://doi.org/10.18653/v1/2021.acl-long.353"},"citation":"@misc{modeltuningprefixtuning2021,\n  title = {{Prefix-Tuning: Optimizing Continuous Prompts for Generation}},\n  author = {Xiang Lisa Li and Percy Liang},\n  year = {2021},\n  eprint = {2101.00190},\n  archivePrefix = {arXiv},\n  url = {https://arxiv.org/abs/2101.00190}\n}\n","citationPath":"/content/papers/citations/model-tuning/prefix-tuning.fda64a808b55.bib"},"thumbnail":{"src":"/content/papers/assets/21f9834f78ef22b11e57cdbfd5c39edca8f15b7ba5ce59a699bd30d0a6c1bc7c.jpg","width":1834,"height":620},"locale":"en","path":"/content/papers/en/model-tuning/prefix-tuning.a33d1eeb4a83.md","headings":[{"id":"defining-the-problem","text":"Defining the Problem","depth":2},{"id":"solving-the-problem","text":"Solving the Problem","depth":2},{"id":"model-architecture","text":"Model Architecture","depth":3},{"id":"implementation-details","text":"Implementation Details","depth":3},{"id":"dataset-setup","text":"Dataset Setup","depth":3},{"id":"discussion","text":"Discussion","depth":2},{"id":"performance-on-table-to-text-generation","text":"Performance on Table-to-Text Generation","depth":3},{"id":"performance-on-summarization","text":"Performance on Summarization","depth":3},{"id":"low-resource-settings","text":"Low-Resource Settings","depth":3},{"id":"extrapolation-ability","text":"Extrapolation Ability","depth":3},{"id":"how-long-should-the-prefix-be","text":"How Long Should the Prefix Be?","depth":3},{"id":"initialization-strategies","text":"Initialization Strategies","depth":3},{"id":"suitable-use-cases","text":"Suitable Use Cases","depth":3},{"id":"why-does-prefix-tuning-perform-well-on-unseen-topics","text":"Why Does Prefix-Tuning Perform Well on Unseen Topics?","depth":3},{"id":"conclusion","text":"Conclusion","depth":2}],"anchorAliases":{},"guide":null,"relatedReading":[{"id":"model-tuning/adapter","relation":"comparison","topic":"Adapting a model with fewer trainable parameters"},{"id":"model-tuning/lora","relation":"comparison","topic":"Adapting a model with fewer trainable parameters"},{"id":"model-tuning/autoprompt","relation":"comparison","topic":"Discrete prompts, soft prompts and prefixes"}]}],"text":"We have to admit it: at the scale of GPT-3 175B in 2021, most people could not train an LLM like that.\n\nThe world is large, but the companies able to train and iterate on a model of that size could be counted on one hand.\n\nResearchers urgently wanted to use these huge models to solve all kinds of problems, so finding an efficient way to fine-tune them became important.\n\n## Defining the Problem\n\nIf you aim to fine-tune an entire model, the process would typically involve the following steps:\n\n1. **Initialize the model** with pretrained weights $\\Phi_0$.\n2. **Update the model** through gradient optimization to $\\Phi_0 + \\Delta \\Phi$, maximizing the conditional language model objective:\n\n   $$\n   \\max_\\Phi \\sum_{(x,y) \\in Z} \\sum_{t=1}^{|y|} \\log P_\\Phi(y_t | x, y_{<t})\n   $$\n\nEach downstream task requires learning a different set of parameters $\\Delta \\Phi$, with the size of $|\\Delta \\Phi|$ equal to that of the original model $|\\Phi_0|$. For large models like GPT-3, which contains **175 billion parameters**, storing and deploying multiple fine-tuned versions becomes a daunting task.\n\nIn previous research, the mainstream approach to address this issue was **Adapters**, which we have previously discussed:\n\n- [**[19.02] Adapter: Reducing Parameters by 96%**](/blog/papers/model-tuning/adapter)\n\nHowever, the exploration does not stop there. Here are a few additional studies that are worth a look:\n\n- [**[20.04] Exploring Versatile Generative Language Models with Parameter-Efficient Transfer Learning**](https://arxiv.org/abs/2004.03829)\n- [**[20.05] AdapterFusion: Non-Destructive Task Composition for Transfer Learning**](https://arxiv.org/abs/2005.00247)\n- [**[21.04] The Power of Scale for Parameter-Efficient Prompt Tuning**](https://arxiv.org/abs/2104.08691)\n\nHowever, these methods still face certain limitations, particularly in large-scale, latency-sensitive production environments. They increase the parameter count and may interfere with parallel computation during model deployment. For example, adding an Adapter to GPT-2 results in a noticeable increase in latency, as shown in the following table:\n\n\n\n![gpt2-adapter](/content/papers/assets/89996d6465ee266aa366602c374aeb2391bb4bf74d33cf9d6843a48301b7cc50.jpg)\n\n\n\nNonlinear adapter layers add sequential work, so few additional FLOPs can still increase latency. Parameter count depends on bottleneck width; some settings are below 1%, but this is not universal. The table measures a single GPT-2 Medium forward pass on a Quadro RTX8000, not a hardware-independent rule.\n\nIn theory, this should not significantly increase the computational load (measured in FLOPs), right?\n\nUnfortunately, it still does.\n\nThis is because large neural networks rely heavily on **parallel hardware** to maintain low latency. However, Adapters require sequential processing, which can lead to significant delays during **online inference**, where batch sizes are typically set to 1.\n\nWhat About Prefix-Tuning?\n\nAnother potential solution is **Prefix-Tuning**:\n\n- [**[21.01] Prefix-Tuning: Optimizing Continuous Prompts for Generation**](https://arxiv.org/abs/2101.00190)\n\nPrefix-Tuning represents a different strategy for adaptation. However, it has some issues: parameter performance tends to fluctuate non-monotonically during optimization, making the process challenging. Additionally, Prefix-Tuning reserves part of the input sequence length for the prefix, which reduces the available length for downstream tasks.\n\nThis makes things even worse.\n\nTo address these challenges, the authors propose **low-rank decomposition of parameters**. Task-specific parameter updates $\\Delta \\Phi$ are encoded as a much smaller parameter set $\\Theta$, such that:\n\n$$\n|\\Theta| \\ll |\\Phi_0|\n$$\n\nThe optimization objective is redefined to focus on this smaller set $\\Theta$:\n\n$$\n\\max_\\Theta \\sum_{(x,y) \\in Z} \\sum_{t=1}^{|y|} \\log P_{\\Phi_0 + \\Delta \\Phi(\\Theta)}(y_t | x, y_{<t})\n$$\n\n\n> [!TIP]\n> \n> The small parameter set represents the task’s **weight update**, not a replacement for the pretrained model. Some GPT-3 settings train roughly one ten-thousandth as many parameters, but inference still requires the large base model.\n> \n> However, finding such a parameter set is not straightforward, and this paper outlines the approach to do so effectively.\n\n\n## Solving the Problem\n\nBefore diving into the methodology, let’s first review some high-school math concepts.\n\n### Rank, Full Rank, and Low Rank\n\nIn mathematics, a **matrix** is a table of numbers arranged in rows and columns. For example:\n\n$$\n\\mathbf{A} = \\begin{bmatrix}\n1 & 2 & 3 \\\\\n4 & 5 & 6 \\\\\n7 & 8 & 9\n\\end{bmatrix}\n$$\n\nMatrices play a crucial role in data processing and computation, and one of the key concepts associated with matrices is **rank**.\n\n---\n\n1. **What is Rank?**\n\n   Rank refers to the number of **independent rows or columns** in a matrix.\n\n   Independence means that a row (or column) cannot be represented as a linear combination of other rows (or columns). If some rows or columns can be expressed as combinations of others, they are not independent. In other words, the rank of a matrix tells us how much **useful, independent information** it contains.\n\n   For a matrix $A$ of size $m \\times n$ (with $m$ rows and $n$ columns), its rank is the largest number of independent rows or columns. The rank cannot exceed the smaller dimension of the matrix:\n\n   $$\n   \\text{rank}(A) \\leq \\min(m, n)\n   $$\n\n---\n\n2. **Full-Rank Matrices**\n\n   A matrix is called **full-rank** when its rank equals the smaller of the number of rows or columns:\n\n   $$\n   \\text{rank}(A) = \\min(m, n)\n   $$\n\n   If $m\\le n$, full rank means all rows are linearly independent; if $n\\le m$, all columns are independent. Both hold for square full-rank matrices. This concerns linear dependence, not semantic usefulness. For example:\n\n   $$\n   \\mathbf{I} = \\begin{bmatrix}\n   1 & 0 \\\\\n   0 & 1\n   \\end{bmatrix}\n   $$\n\n   This is a $2 \\times 2$ identity matrix, where both rows are independent. The rank of this matrix is 2 (equal to $\\min(2, 2)$), making it a **full-rank matrix**. Each row or column provides new information that cannot be expressed using other rows or columns.\n\n---\n\n3. **Low-Rank Matrices**\n\n   A matrix is rank-deficient when its rank is below $\\min(m,n)$: some rows or columns can be expressed as combinations of others. In low-rank adaptation, $r$ is usually much smaller still. Storage savings come from keeping low-rank factors, not simply from a densely stored matrix having low mathematical rank.\n\n   For example:\n\n   $$\n   \\mathbf{B} = \\begin{bmatrix}\n   1 & 2 \\\\\n   2 & 4\n   \\end{bmatrix}\n   $$\n\n   Here, the second row is simply the first row multiplied by 2. Therefore, the matrix’s rank is 1 (only one independent row), not 2. This is a **low-rank matrix**. Since the rank is low, we can use a smaller matrix to approximate or describe it.\n\n### Why Are Low-Rank Matrices Useful?\n\nIn many applications, we encounter large matrices that contain redundant information. In such cases, we can use **low-rank matrices** to approximate the original matrix and achieve several benefits:\n\n1. **Reduced Computational Cost**: Computing with low-rank factors can require fewer operations and speed up algorithms.\n2. **Lower Storage Requirements**: Keeping the factors can use less memory, which is useful for large datasets.\n3. **Dimensionality Reduction**: High-dimensional data can be projected onto a lower-dimensional space while retaining essential information (e.g., PCA).\n4. **Capacity control**: A low-rank constraint can regularize, but can also underfit; improved generalization is not guaranteed.\n\nSVD itself is an exact factorization. Keeping only leading singular values and vectors gives truncated SVD, a low-rank approximation useful in areas such as image compression and recommender systems. LoRA directly trains update factors; it does not first fully fine-tune and then run SVD.\n\n### Low-Rank Decomposition: LoRA\n\n\n\n![lora](/content/papers/assets/547204d875b324a959dc2fb7c92601337563d9262cd3612847a3a772d092c53f.jpg)\n\n\n\nIn neural networks, **dense layers** rely on matrix multiplication, where the weight matrices are typically full-rank. Previous research has shown that language-model fine-tuning can remain effective even when updates are constrained to a small random subspace, suggesting **low intrinsic dimensionality**.\n\n- [**[20.12] Intrinsic Dimensionality Explains the Effectiveness of Language Model Fine-Tuning**](https://arxiv.org/abs/2012.13255)\n\nBased on this, the authors hypothesize that weight updates during fine-tuning also exhibit **low intrinsic rank**. In other words, for a pretrained weight matrix $W_0 \\in \\mathbb{R}^{d \\times k}$, the update can be expressed as a **low-rank decomposition**:\n\n$$\nW_0 + \\Delta W = W_0 + BA\n$$\n\nwhere $B \\in \\mathbb{R}^{d \\times r}$ and $A \\in \\mathbb{R}^{r \\times k}$, with $r \\ll \\min(d, k)$.\n\nDuring training, the **pretrained weight matrix $W_0$** remains frozen, meaning its gradients are not updated. Only $A$ and $B$ are **trainable parameters**. These matrices are multiplied by the input vector $x$, and the results are summed element-wise:\n\n$$\nh = W_0 x + \\Delta W x = W_0 x + BA x\n$$\n\nMatrix $A$ is initialized with values from a **Gaussian distribution**, while $B$ is initialized with zeros. Thus, at the start of training, $\\Delta W = BA$ is zero.\n\nFor stability, the update $\\Delta W x$ is scaled by:\n\n$$\n\\frac{\\alpha}{r} \\cdot \\Delta W x\n$$\n\nThe coefficient $\\alpha$ is held fixed when varying $r$. The paper sets it to the first rank tried, rather than enforcing $\\alpha=r$ for every experiment. The learning-rate analogy depends on Adam and appropriately scaled initialization.\n\nWith sufficient rank on all relevant matrices and training of biases and remaining parameters, the update can recover the expressiveness of full fine-tuning. Optimization, convergence, and final quality require separate evaluation; adapting only $W_q,W_v$ is not full-model fine-tuning.\n\n### LoRA on Transformer Models\n\nLoRA can be applied to any neural network weight matrix. In **Transformer architectures**, it primarily targets the **self-attention module** matrices:\n\n- Four key matrices: $W_q$, $W_k$, $W_v$, and $W_o$.\n- Each matrix has dimensions $d_{\\text{model}} \\times d_{\\text{model}}$, even though their outputs are often split across multiple attention heads.\n\nIn the paper, the authors only fine-tune the **attention weights**, while freezing the **MLP modules** to reduce the parameter count.\n\nThis approach provides several benefits:\n\n- **Reduced Memory and Storage Requirements**:\n\n  - For large Transformer models (e.g., GPT-3 with 175B parameters), **VRAM usage** decreases from **1.2TB** to **350GB** (if $r \\ll d_{\\text{model}}$).\n  - If $r = 4$ and only the query and value projection matrices are fine-tuned, the checkpoint size shrinks from 350GB to **35MB** (a **10,000x reduction**).\n  - The 35MB contains only the task update. Deployment still needs the approximately 350GB FP16 backbone. The quoted training memory is the reported aggregate requirement, not capacity that fits on one consumer GPU.\n\n- **Lower GPU Utilization and Avoiding I/O Bottlenecks**: With smaller storage needs, fewer GPUs are required for training.\n\n- **Faster Task Switching**: Tasks can be switched simply by swapping LoRA weights without reloading the entire model.\n\n- **Training efficiency**: The text reports about 25% speedup, while its footnote gives 32.5 versus 43.1 tokens/s per V100. Those numbers imply about 32.6% greater throughput or 24.6% less time for a fixed token count; these are different measures.\n\nHowever, there are some drawbacks. If the matrices $A$ and $B$ are merged back into the original weight matrix $W$ to eliminate inference delays, handling **batch inputs across different tasks** becomes challenging. In latency-insensitive scenarios, one can avoid merging the weights and dynamically select the appropriate LoRA module for each task.\n\n\n> [!TIP]\n> \n> This is a form of reparameterization: the task-specific factors sit alongside the original model and can be merged when needed. For one task, compute $W=W_0+(\\alpha/r)BA$ and run the original linear operation. Merging does not inherently reduce quality; keeping modules separate is more flexible for switching tasks or mixing different updates in one batch. Numerical precision remains implementation-dependent.\n\n\n## Discussion\n\n### Experimental Baselines\n\nThe authors conducted experiments on **RoBERTa**, **DeBERTa**, **GPT-2**, and **GPT-3**, using the following baselines:\n\n1. **Fine-Tuning (FT)**\n\n   - **Full-Model Fine-Tuning**: All parameters, initialized from the pretrained weights and biases, are updated during training.\n   - **Partial-Layer Fine-Tuning (FTTop2)**: Only the last two layers of GPT-2 are updated (Li & Liang, 2021).\n   - **Bias Fine-Tuning (BitFit)**: Only bias vectors are trainable, while all other parameters remain frozen (Zaken et al., 2021).\n\n---\n\n2. **Prefix-Embedding Tuning (PreEmbed)**\n\n   Special tokens are added before or after the task input, and their embeddings are trainable.\n\n   - **Strategies**:\n     - **Prefix**: Special tokens are added before the task input.\n     - **Infix**: Special tokens are added after the task input.\n   - **Parameter Count**:\n     $$\n     |\\Theta| = d_{\\text{model}} \\times (l_p + l_i)\n     $$\n     where $l_p$ and $l_i$ are the numbers of prefix and infix tokens, respectively.\n\n---\n\n3. **Prefix-Layer Tuning (PreLayer)**\n\n   Instead of tuning embeddings, the activation values for each Transformer layer are learned.\n\n   - **Parameter Count**:\n     $$\n     |\\Theta| = L \\times d_{\\text{model}} \\times (l_p + l_i)\n     $$\n     where $L$ is the number of Transformer layers.\n\n---\n\n4. **Adapter Tuning**\n\n   - **AdapterH**: The Houlsby design has two adapters per block, after attention and after the MLP, each before its corresponding residual addition.\n   - **AdapterL**: Applied only after the MLP module and LayerNorm (Lin et al., 2020).\n   - **AdapterP**: Similar to AdapterL (Pfeiffer et al., 2021).\n   - **AdapterD**: Some Adapters are removed for efficiency (Rücklé et al., 2020).\n   - **Parameter Count**:\n     $$\n     |\\Theta| = \\hat{L}_{\\text{Adpt}} \\times (2 \\times d_{\\text{model}} \\times r + r + d_{\\text{model}}) + 2 \\times \\hat{L}_{\\text{LN}} \\times d_{\\text{model}}\n     $$\n     where $\\hat{L}_{\\text{Adpt}}$ is the number of Adapter layers and $\\hat{L}_{\\text{LN}}$ is the number of trainable LayerNorms.\n\n---\n\n5. **LoRA Tuning**\n\n   LoRA introduces **low-rank matrices** alongside the original weight matrices, which are updated in parallel. In most experiments, LoRA is applied only to the **query matrix $W_q$** and **value matrix $W_v$**.\n\n   - **Parameter Count**:\n     $$\n     |\\Theta| = 2 \\times \\hat{L}_{\\text{LoRA}} \\times d_{\\text{model}} \\times r\n     $$\n     where $\\hat{L}_{\\text{LoRA}}$ is the number of matrices with LoRA applied, and $r$ is the rank.\n\n---\n\n### Comparison with Other Fine-Tuning Methods\n\n![comparison](/content/papers/assets/0920a423be0f29928b20037eb7a3864ea008c68ababf2fa9f88fce4160f3b697.jpg)\n\nThe authors evaluated **RoBERTa Base (125M)** and **RoBERTa Large (355M)** models from HuggingFace for their experiments.\n\n\n> [!TIP]\n> \n> **What is RoBERTa?**\n> \n> RoBERTa is an optimized version of BERT, with improved training procedures to enhance performance. We’ve previously covered RoBERTa in:\n> \n> - [**[19.07] RoBERTa: A Guide to Training BERT**](/blog/papers/transformers/roberta)\n\n\nRows marked † use the following two adjustments for comparison with adapters; they do not apply to every row in the table:\n\n1. **Same Batch Size and Sequence Length**: All tasks used the same batch size, with the sequence length set to 128 to match the Adapter baseline.\n2. **Model Initialization**: For MRPC, RTE, and STS-B tasks, the models were initialized from pretrained weights, not from MNLI-adapted models (as in other fine-tuning baselines).\n\nThe results show that **LoRA** performs similarly to full-model fine-tuning on both **RoBERTa Base** and **RoBERTa Large**. In most cases, LoRA outperforms both **Adapters** and other parameter-efficient tuning methods.\n\n**DeBERTa** is a more advanced variant of BERT with larger training scales and competitive performance on benchmarks like **GLUE** and **SuperGLUE**. The authors also tested LoRA on DeBERTa, with the results (shown in the table above) indicating that LoRA often outperforms **full-model fine-tuning**.\n\n### Fine-Tuning GPT-3\n\n\n\n![gpt3](/content/papers/assets/25d4d4f5111866a0d806f79d7f730b5336a11b44508f44b41f030a78dc44079b.jpg)\n\n\n\nFinally, we have reached the **GPT-3** fine-tuning results! On WikiSQL, MultiNLI-matched and SAMSum in the reported settings, LoRA performs better overall than the tested Adapters and other efficient tuning methods, while matching or exceeding full fine-tuning.\n\nHowever, increasing the number of trainable parameters does not always lead to improved performance, as seen in the following chart:\n\n![tuning](/content/papers/assets/af04d5e40b20251f4ab222166cd239939bd3ab737f37867dc667cc025c143c24.jpg)\n\nWith **prefix-embedding tuning**, performance drops when using more than **256 special tokens**. Similarly, **prefix-layer tuning** shows degraded performance beyond **32 special tokens**. This decline could be due to the input distribution diverging from the pretrained data distribution when too many special tokens are used.\n\n### Which Weight Matrices Should LoRA Target in Transformers?\n\n![table5](/content/papers/assets/5ef57b1c4813959fac74f50ab56db9c19eea2d35bb48e724ce124a76e558fdae.jpg)\n\nGiven a limited parameter budget, which weight matrices should be adapted to achieve optimal performance in downstream tasks?\n\nThe authors conducted experiments on **GPT-3 (175B)**, setting the number of trainable parameters to **18 million** (approximately **35MB** with FP16 precision). Across all **96 layers**, if LoRA is applied to one type of attention weight, the rank is set to $r = 8$. If two types are adapted, the rank is reduced to $r = 4$.\n\nThese are validation accuracies on WikiSQL and MultiNLI. The results in the table suggest:\n\n- **Adapting only $\\Delta W_q$ or $\\Delta W_k$** leads to a significant drop in performance.\n- **Adapting $W_q,W_v$** gives 73.7% on WikiSQL and 91.3% on MultiNLI. Adapting all four matrix types at $r=2$ gives 73.7% and 91.7%. Table 5 therefore supports distributing adaptation within this budget, not a unique or universal Q/V optimum.\n\nEven with a small rank $r = 4$, $\\Delta W$ can capture sufficient information. This suggests that adapting **more types of weight matrices with a smaller rank** is more effective than adapting only one type with a higher rank.\n\n### What is the Optimal Rank $r$ for LoRA?\n\n![table6](/content/papers/assets/1c2c8d06e22e35dbda36c148cd37bbd59eae4bcffebc2b63a9b6fedf231e3355.jpg)\n\nLoRA achieves excellent performance even with **very small ranks**, especially when applied to $\\{W_q, W_v\\}$.\n\nSmall ranks are competitive in these GPT-3 experiments on WikiSQL and MultiNLI, and increasing rank does not consistently improve scores. The authors explicitly caution that other languages, tasks or datasets may need higher ranks; $r=1$ is not a universal optimum.\n\n### Subspace Similarity Analysis\n\nThe authors also explored the similarity between subspaces for different values of $r$ and across different random seeds. They performed Singular Value Decomposition (SVD) on these matrices to obtain the right singular matrices:\n\n$$\nU_{A_{r=8}} \\quad \\text{and} \\quad U_{A_{r=64}}\n$$\n\nTheir goal was to determine how much of the subspace formed by the top $i$ singular vectors of $U_{A_{r=8}}$ overlaps with the subspace formed by the top $j$ singular vectors of $U_{A_{r=64}}$.\n\nThey measured the similarity using normalized subspace similarity based on Grassmann distance:\n\n$$\n\\phi(A_{r=8}, A_{r=64}, i, j) = \\frac{\\left\\| \\left(U_{A_{r=8}}^{i}\\right)^\\top U_{A_{r=64}}^{j} \\right\\|_F^2}{\\min(i, j)} \\in [0, 1]\n$$\n\nHere, $U_{A_{r=8}}^{i}$ represents the first $i$ columns of the singular matrix $U_{A_{r=8}}$.\n\nHere the paper calls the right-singular-vector matrix $U_A$. In the usual SVD notation $A=U\\Sigma V^\\top$, these vectors are columns of $V$. For $A\\in\\mathbb R^{r\\times k}$, the compared bases lie in the same $k$-dimensional input space.\n\nThe resulting comparison is shown below:\n\n![subspace](/content/papers/assets/9525db0b519ce8f052409b48b46ce378c065c115b7784167cac2272fca38ed2b.jpg)\n\nThe directions of the top singular vectors overlap significantly between $A_{r=8}$ and $A_{r=64}$, while the overlap is smaller for other directions. Overall, the subspaces of $A_{r=8}$ and $A_{r=64}$ for $\\Delta W_v$ (or $\\Delta W_q$) share a dimension with similarity $\\phi > 0.5$.\n\nThis may help explain why rank $r = 1$ works well on these downstream tasks: useful information may be concentrated in the top singular-vector directions.\n\n---\n\nLet’s summarize the key takeaways from the paper:\n\n1. **Low-Rank Adaptation Matrices Can Be Sufficient**: On the tasks tested here, LoRA remains comparable to full-model fine-tuning even with very small ranks.\n2. **Adapting More Types of Weight Matrices Can Be More Effective than Increasing Rank**: Under Table 5's tasks and parameter budget, **adapting more types** (e.g., both $W_q$ and $W_v$) with a smaller rank works better than focusing on one type with a higher rank.\n\n## Conclusion\n\nCompared with other fine-tuning methods, LoRA gives us a lot!\n\nIn the GPT-3 experiment, it cuts trainable task-specific parameters by roughly **10,000 times** while keeping performance comparable in the tested tasks. That saving applies to the task update and its checkpoint; the large frozen backbone and substantial training memory are still needed.\n\n- **At last, more of us can fine-tune an LLM!**\n\nIn 2021, adapting a shared large model to many applications became more achievable, even if a 175B model still required serious hardware. It is exciting to think how many more settings could benefit from such models.\n\nThe next decade should be lively. Let's see what other interesting research appears!\n","imageSizes":{"/content/papers/assets/89996d6465ee266aa366602c374aeb2391bb4bf74d33cf9d6843a48301b7cc50.jpg":{"width":1224,"height":312},"/content/papers/assets/547204d875b324a959dc2fb7c92601337563d9262cd3612847a3a772d092c53f.jpg":{"width":516,"height":472},"/content/papers/assets/0920a423be0f29928b20037eb7a3864ea008c68ababf2fa9f88fce4160f3b697.jpg":{"width":1446,"height":716},"/content/papers/assets/25d4d4f5111866a0d806f79d7f730b5336a11b44508f44b41f030a78dc44079b.jpg":{"width":1224,"height":520},"/content/papers/assets/af04d5e40b20251f4ab222166cd239939bd3ab737f37867dc667cc025c143c24.jpg":{"width":1484,"height":496},"/content/papers/assets/5ef57b1c4813959fac74f50ab56db9c19eea2d35bb48e724ce124a76e558fdae.jpg":{"width":1778,"height":380},"/content/papers/assets/1c2c8d06e22e35dbda36c148cd37bbd59eae4bcffebc2b63a9b6fedf231e3355.jpg":{"width":1720,"height":490},"/content/papers/assets/9525db0b519ce8f052409b48b46ce378c065c115b7784167cac2272fca38ed2b.jpg":{"width":1586,"height":464}}}
