Home

Awesome

<h1 align="center"> <p> DoRA: Weight-Decomposed Low-Rank Adaptation <br> [ICML2024 (Oral)]</p> </h1> <h1 align="center"> <img src="./imgs/dora.png" width="600"> </h1>

The Official PyTorch implementation of DoRA: Weight-Decomposed Low-Rank Adaptation [ICML2024 (Oral, acceptance rate: 1.5%)].

Star on GitHub

Shih-Yang Liu*, Chien-Yi Wang, Hongxu Yin, Pavlo Molchanov, Yu-Chiang Frank Wang, Kwang-Ting Cheng, Min-Hung Chen <br> (*Work done during the internship at NVIDIA Research)

[Paper] [Website] [NV Blog] [BibTeX]

DoRA decomposes the pre-trained weight into two components, magnitude and direction, for fine-tuning, specifically employing LoRA for directional updates to minimize the number of trainable parameters efficiently. By employing DoRA, we enhance both the learning capacity and training stability of LoRA while avoiding any additional inference overhead. DoRA 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.

For business inquiries, please visit our website and submit the form: NVIDIA Research Licensing.

šŸ’„ News šŸ’„

Useful Links

Quick Start and some tricks regarding finetuning with DoRA

HuggingFace PEFT

DoRA is now supported by the Huggingface PEFT package. You can install the PEFT package using

pip install git+https://github.com/huggingface/peft.git -q

After PEFT is installed, you can simply set the use_dora argument of LoraConfig() to True for applying DoRA.

An example could be as follows:

from peft import LoraConfig

# Initialize DoRA configuration
config = (
    use_dora=True, ...
)

Please refer to the official documentation for more details.

HuggingFace Diffusers

You can also toy with DoRA on finetuning diffusion models. See huggingface/diffusers. Another good tutorial would be this Colab notebook from Linoy Tsaban.

In general, DoRA finetuning on diffusion models is still experimental and is likely to require different hyperparameter values to perform best compared to LoRA.

Specifically, people have noticed 2 differences to take into account in your training:

  1. LoRA seem to converge faster than DoRA (so a set of parameters that may lead to overfitting when training a LoRA may be working well for a DoRA)
  2. DoRA quality superior to LoRA especially in lower ranks: The difference in quality of DoRA of rank 8 and LoRA of rank 8 appears to be more significant than when training ranks of 32 or 64 for example.

Some DoRA vs. LoRA diffusion finetuning results

<h1 align="center"> <img src="./imgs/dora_lora_yoda_emoji.jpg" width="500"> </h1> <h1 align="center"> <img src="./imgs/dora_lora_lego.jpeg" width="500"> </h1>

DoRA hyperparameters settings

[!NOTE] šŸ’” While fine-tuning with DoRA, utilizing the configuration of LoRA can already achieve better results most of the time, achieving optimal performance compared to LoRA still requires adjustments to the hyperparameters.

We suggest starting with a slightly lower learning rate than that of LoRA, and users may also experiment with varying LoRA dropout ratios.

User may also start with half of the rank of the LoRA configuration which oftentimes can already result in comparable or even superior accuracy compared to that of LoRA.

Reproducing the results in the paper

This repo contains four directories:

./commonsense_reasoning contains the code to finetune LLaMA-7B/13B using DoRA on the commonsense reasoning tasks. This directory is modified based on LLM-Adapter.

./instruction_tuning_dvora contains the code to finetune LLaMA-7B and LLaMA2-7B using DoRA and DVoRA (DoRA+VeRA) with the cleaned Alpaca instruction tuning dataset. This directory is modified based on VeRA.

./image_video_text_understanding contains the code to finetune VL-BART using DoRA for the image/video-text understanding tasks. This directory is modified based on VL-Adapter.

./visual_instruction_tuning contains the code to finetune LLaVA-1.5-7B on the visual instruction tuning tasks with DoRA. This directory is modified based on LLaVA.

DoRA vs LoRA on the commonsense reasoning tasks

ModelrBoolQPIQASIQAHellaSWinoGARC-eARC-cOBQAAverage
LLaMA-7B-LoRA3267.580.878.283.480.478.062.679.176.3
LLaMA-7B-DoRA(ours)1670.082.679.783.280.680.665.477.677.5
LLaMA-7B-DoRA(ours)3269.783.478.687.281.081.966.279.278.4
LLaMA2-7B-LoRA3269.879.979.583.682.679.864.781.077.6
LLaMA2-7B-DoRA(ours)1672.083.179.989.183.084.571.081.280.5
LLaMA2-7B-DoRA(ours)3271.883.776.089.182.683.768.282.479.7
LLaMA3-8B-LoRA3270.885.279.991.784.384.271.279.080.8
LLaMA3-8B-DoRA(ours)1674.588.880.395.584.790.179.187.285.0
LLaMA3-8B-DoRA(ours)3274.689.379.995.585.690.580.485.885.2

Star History

Star History Chart

Contact

Shih-Yang Liu: shihyangl@nvidia.com or sliuau@connect.ust.hk

Citation

If you find DoRA useful, please consider giving a star and citation:

@article{liu2024dora,
  title={DoRA: Weight-Decomposed Low-Rank Adaptation},
  author={Liu, Shih-Yang and Wang, Chien-Yi and Yin, Hongxu and Molchanov, Pavlo and Wang, Yu-Chiang Frank and Cheng, Kwang-Ting and Chen, Min-Hung},
  journal={arXiv preprint arXiv:2402.09353},
  year={2024}
}

Licenses

Copyright Ā© 2024, NVIDIA Corporation. All rights reserved.

This work is made available under the NVIDIA Source Code License-NC. Click here to view a copy of this license.