Papers
Topics
Authors
Recent
Search
2000 character limit reached

DoRA: Weight-Decomposed Low-Rank Adaptation

Published 14 Feb 2024 in cs.CL and cs.CV | (2402.09353v6)

Abstract: Among the widely used parameter-efficient fine-tuning (PEFT) methods, LoRA and its variants have gained considerable popularity because of avoiding additional inference costs. However, there still often exists an accuracy gap between these methods and full fine-tuning (FT). In this work, we first introduce a novel weight decomposition analysis to investigate the inherent differences between FT and LoRA. Aiming to resemble the learning capacity of FT from the findings, we propose Weight-Decomposed Low-Rank Adaptation (DoRA). DoRA decomposes the pre-trained weight into two components, magnitude and direction, for fine-tuning, specifically employing LoRA for directional updates to efficiently minimize the number of trainable parameters. By employing \ours, we enhance both the learning capacity and training stability of LoRA while avoiding any additional inference overhead. \ours~consistently outperforms LoRA on fine-tuning LLaMA, LLaVA, and VL-BART on various downstream tasks, such as commonsense reasoning, visual instruction tuning, and image/video-text understanding. Code is available at https://github.com/NVlabs/DoRA.

Citations (209)

Summary

  • The paper introduces DoRA, a parameter-efficient method that decomposes pre-trained weight matrices into magnitude and directional components to better mimic full fine-tuning behavior.
  • DoRA directly fine-tunes magnitude vectors and applies low-rank updates to the directional component, improving accuracy by up to 3.7% over standard LoRA on models like LLaMA-7B.
  • The approach supports merging adapted weights for zero inference overhead and extends to quantized models, enabling efficient fine-tuning on resource-constrained hardware.

This paper introduces DoRA (Weight-Decomposed Low-Rank Adaptation), a parameter-efficient fine-tuning (PEFT) method designed to bridge the performance gap between standard LoRA and full fine-tuning (FT) while retaining LoRA's efficiency benefits.

The core idea of DoRA stems from an analysis of how FT and LoRA update model weights. The authors propose decomposing a pre-trained weight matrix W0W_0 into a magnitude component mm and a directional component VV, such that W0=mV∣∣V∣∣cW_0 = m \frac{V}{||V||_c}, where ∣∣V∣∣c||V||_c is the vector-wise norm across columns. By analyzing the changes in magnitude (ΔM\Delta M) and direction (ΔD\Delta D) during fine-tuning, they observe that FT exhibits a distinct learning pattern compared to LoRA, characterized by a different correlation between magnitude and directional updates (negative for FT, positive for LoRA in their analysis). This difference is hypothesized to contribute to LoRA's lower learning capacity compared to FT.

DoRA leverages this insight by explicitly decomposing the pre-trained weight W0W_0 into its magnitude m=∣∣W0∣∣cm = ||W_0||_c and direction V=W0V = W_0 at initialization. Instead of directly adding a low-rank update mm0 to mm1 as in standard LoRA, DoRA fine-tunes the magnitude component mm2 directly and applies the low-rank update mm3 to the directional component mm4. The fine-tuned weight mm5 is then constructed as:

mm6

where mm7 and the low-rank matrices mm8 and mm9 are trainable parameters, and VV0 (initialized as VV1) is kept frozen. This allows DoRA to separately manage magnitude and directional updates, aiming to replicate FT's learning behavior more closely.

Practical Implementation:

  1. Weight Decomposition: For each weight matrix VV2 in the pre-trained model where PEFT is applied (typically attention and sometimes feed-forward layers in Transformers), calculate the initial magnitude vector VV3 where each element VV4 (L2 norm of the i-th column). The initial directional matrix VV5 is simply VV6. VV7 is initialized as a trainable parameter, while VV8 remains fixed.
  2. LoRA Application: Standard LoRA matrices VV9 and W0=mV∣∣V∣∣cW_0 = m \frac{V}{||V||_c}0 are introduced. They are initialized as in standard LoRA (W0=mV∣∣V∣∣cW_0 = m \frac{V}{||V||_c}1 with Kaiming uniform, W0=mV∣∣V∣∣cW_0 = m \frac{V}{||V||_c}2 with zeros) so that W0=mV∣∣V∣∣cW_0 = m \frac{V}{||V||_c}3 initially, making W0=mV∣∣V∣∣cW_0 = m \frac{V}{||V||_c}4 equal to W0=mV∣∣V∣∣cW_0 = m \frac{V}{||V||_c}5. These matrices are trainable.
  3. Forward Pass: To compute the output of a layer with weight W0=mV∣∣V∣∣cW_0 = m \frac{V}{||V||_c}6 and input W0=mV∣∣V∣∣cW_0 = m \frac{V}{||V||_c}7:
    • Compute the updated directional component: W0=mV∣∣V∣∣cW_0 = m \frac{V}{||V||_c}8.
    • Compute the column-wise norms of W0=mV∣∣V∣∣cW_0 = m \frac{V}{||V||_c}9: ∣∣V∣∣c||V||_c0.
    • Compute the fine-tuned weight: ∣∣V∣∣c||V||_c1 (where ∣∣V∣∣c||V||_c2 denotes element-wise multiplication after broadcasting ∣∣V∣∣c||V||_c3).
    • Compute the output: ∣∣V∣∣c||V||_c4.
    • Note that the magnitude ∣∣V∣∣c||V||_c5 is a ∣∣V∣∣c||V||_c6 vector, and ∣∣V∣∣c||V||_c7 is ∣∣V∣∣c||V||_c8. The magnitude is applied element-wise to the columns of the normalized directional matrix.
  4. Backward Pass (Gradient Calculation): Standard gradient calculations apply to ∣∣V∣∣c||V||_c9, ΔM\Delta M0, and ΔM\Delta M1. To reduce memory overhead during backpropagation, the authors propose treating ΔM\Delta M2 as a constant (detaching it from the gradient graph). This means ΔM\Delta M3 is computed based on the current values of ΔM\Delta M4 and ΔM\Delta M5, but its gradient is not backpropagated through. The gradient w.r.t ΔM\Delta M6 is ΔM\Delta M7, where ΔM\Delta M8 is treated as a constant. This modification reduces memory usage with minimal impact on accuracy, as shown in ablation studies (e.g., 24.4% memory reduction for LLaMA tuning with 0.2 accuracy drop).
  5. Inference: Like LoRA, DoRA allows merging the trained parameters (ΔM\Delta M9) into the original weight matrix ΔD\Delta D0 before deployment. The merged weight ΔD\Delta D1 can be pre-calculated, resulting in a standard ΔD\Delta D2 matrix. This means DoRA introduces no additional inference latency compared to the original pre-trained model or merged LoRA.

Real-world Applications and Performance:

The paper demonstrates DoRA's effectiveness across various tasks and model architectures:

  • Commonsense Reasoning (LLaMA, LLaMA2, LLaMA3): DoRA consistently outperforms LoRA across multiple benchmarks. On LLaMA-7B, DoRA improves average accuracy by 3.7% over LoRA. Even with half the parameters (ΔD\Delta D3), DoRA surpasses LoRA. This indicates improved learning capacity with comparable or fewer parameters.
  • Image/Video-Text Understanding (VL-BART): DoRA shows better performance than LoRA (nearly 1% average improvement on image-text, 2% on video-text), reaching performance levels comparable to full fine-tuning but with significantly fewer trainable parameters.
  • Visual Instruction Tuning (LLaVA-1.5-7B): DoRA achieves higher average accuracy than both LoRA and FT.
  • Instruction Tuning (LLaMA, LLaMA2): DoRA is compatible with other LoRA variants like VeRA, creating DoVA. DoVA significantly improves over VeRA (which uses very few parameters) and achieves accuracy comparable to or better than standard LoRA with substantially fewer parameters.
  • Robustness: DoRA consistently outperforms LoRA across different numbers of training samples and varying LoRA ranks, demonstrating its stability and improved performance, particularly at lower ranks where LoRA's performance degrades significantly.
  • Tuning Granularity: By selectively applying directional updates (LoRA part) only to certain modules (e.g., QKV layers in attention) while updating magnitude for more modules, DoRA can achieve better accuracy than LoRA with a smaller total number of trainable parameters.

Broader Impact (QDoRA):

DoRA's concept has been extended to quantized models. QDoRA combines 4-bit quantization (from QLoRA) with DoRA. Early results on fine-tuning LLaMA2-7B on Orca-Math (Mitra et al., 2024) show that QDoRA not only outperforms QLoRA significantly but can even surpass the accuracy of the non-quantized full fine-tuning baseline, all while requiring substantially less GPU memory. This suggests QDoRA is a promising approach for efficiently fine-tuning large models on consumer hardware.

Implementation Considerations:

  • Implementing DoRA requires modifying the forward and backward passes for the layers where PEFT is applied to incorporate the magnitude and directional decomposition and updates.
  • The gradient modification (treating ΔD\Delta D4 as constant) is crucial for practical memory efficiency during training.
  • The trainable parameters are the magnitude vector ΔD\Delta D5 (size ΔD\Delta D6) and the LoRA matrices ΔD\Delta D7 (ΔD\Delta D8) and ΔD\Delta D9 (W0W_00). The total trainable parameters are W0W_01. Compared to LoRA (W0W_02), DoRA adds W0W_03 parameters for the magnitude vector per modified weight matrix.
  • For deployment, the trained W0W_04 are merged into the original W0W_05 to form the final weight matrix W0W_06, which can then be used like any standard weight matrix without special DoRA computation, ensuring zero inference overhead.

In summary, DoRA is a practical and effective PEFT method that improves upon LoRA by explicitly handling magnitude and directional updates based on insights from FT. It achieves better performance with similar or fewer trainable parameters than LoRA, is compatible with LoRA variants, is robust to varying ranks and data sizes, and can be merged for inference, incurring no additional latency. Its extension to quantized fine-tuning (QDoRA) further highlights its practical significance for training large models on resource-constrained hardware.

Paper to Video (Beta)

No one has generated a video about this paper yet.

Whiteboard

No one has generated a whiteboard explanation for this paper yet.

Open Problems

We found no open problems mentioned in this paper.

Collections

Sign up for free to add this paper to one or more collections.

Tweets

Sign up for free to view the 64 tweets with 6490 likes about this paper.

Reddit