LoRA Learns Less and Forgets Less
These are model checkpoints and LoRA adapters from the research paper "LoRA Learns Less and Forgets Less" (Biderman et al. TMLR, 2024). This work was done in collaboration with Databricks Mosaic AI Research.
Model Details
- Developed by: Databricks Mosaic AI
- Model type: Research Artifacts
- Language(s) (NLP): English
- License: cc-by-nc-4.0
- Finetuned from model: Llama-2-7b
We trained Llama-2-7B using full finetuning and LoRA. Model checkpoints and LoRA adapters can be found on HuggingFace here: LoRA-TMLR-2024. Intermediate checkpoints can be found in the branches of the respective models.
Setting | Dataset | HuggingFace Collection |
---|---|---|
Continued Pretraining - Code | StarCoder-Python | LoRA-TMLR-2024/continued-pretraining-code-starcoder-python |
Continued Pretraing - Math | OpenWebMath | LoRA-TMLR-2024/continued-pretraining-math-openwebmath |
Instruction Finetuning - Code | Magicoder-Evol-Instruct-110K | LoRA-TMLR-2024/instruction-finetuning-code-magicoder-evol-instruct-110k |
Instruction Finetuning - Math | MetaMathQA | LoRA-TMLR-2024/instruction-finetuning-math-metamathqa |
All training was done using the Databricks MosaicML composer, streaming, and llm-foundry repositories, as well as the HuggingFace peft library.
Model Sources
- Repository: https://github.com/danbider/lora-tradeoffs
- Paper: LoRA Learns Less and Forgets Less
Abstract
Low-Rank Adaptation (LoRA) is a widely-used parameter-efficient finetuning method for large language models. LoRA saves memory by training only low rank perturbations to selected weight matrices. In this work, we compare the performance of LoRA and full finetuning on two target domains, programming and mathematics. We consider both the instruction finetuning (≈100K prompt-response pairs) and continued pretraining (≈20B unstructured tokens) data regimes. Our results show that, in the standard low-rank settings, LoRA substantially underperforms full finetuning. Nevertheless, LoRA better maintains the base model’s performance on tasks outside the target domain. We show that LoRA mitigates forgetting more than common regularization techniques such as weight decay and dropout; it also helps maintain more diverse generations. Finally, we show that full finetuning learns perturbations with a rank that is 10-100× greater than typical LoRA configurations, possibly explaining some of the reported gaps. We conclude by proposing best practices for finetuning with LoRA.
Uses
These are research artifacts that are intended for research purposes only.
Training Details
Training Data
The following datasets were used:
Setting | Dataset |
---|---|
Continued Pretraining - Code | StarCoder-Python |
Continued Pretraing - Math | OpenWebMath |
Instruction Finetuning - Code | Magicoder-Evol-Instruct-110K |
Instruction Finetuning - Math | MetaMathQA |
Training Procedure
In all four scenarios below, we use the Llama-2-7B base model meta-llama/Llama-2-7b-hf. For the CPT runs, we use the meta-llama/Llama-2-7b-hf tokenizer, while for the IFT runs we use the meta-llama/Llama-2-7b-chat-hf tokenizer.
Code CPT (StarCoder-Python)
StarCoder-Python (Li et al., 2023a) This dataset consists of permissively licensed repositories from GitHub, including Git commits, in 80+ programming languages. We chose the Python subset and sub-sampled it to 20B tokens.
Parameter | Value |
---|---|
seq_len | 4096 |
optimizer | decoupled_lionw (betas=[0.9, 0.95]) |
learning_rate | 1.0e-05 for LoRA and Full Finetuning |
scheduler | inv_sqrt_with_warmup (t_scale=1000ba, t_warmup=1000ba, t_cooldown=5086ba, alpha_f_decay=1, alpha_f_cooldown=0) |
weight_decay | 1.0e-06 |
precision | amp_bf16 |
global_train_batch_size | 192 |
device_train_microbatch_size | 6 |
gradient_clipping | norm (threshold=1) |
num_gpus | 32 |
We trained models for 0.25B, 0.5B, 1B, 2B, 4B, 8B, 16B and 20B tokens. These checkpoints can be found for each LoRA and full finetuning setting in the HuggingFace model branches.
Math CPT (OpenWebMath)
OpenWebMath (Paster et al., 2023) - This dataset contains 14.7B tokens derived from mathematical web pages from Common Crawl, correctly formatted to preserve mathematical content such as LaTeX equations. To match with the StarCoder-Python dataset, we trained on up to 20B tokens, repeating tokens beyond the first 14.7B. An analysis of this dataset shows that it contains a considerable amount of full English sentences.
Parameter | Value |
---|---|
max_seq_len | 4096 |
optimizer | decoupled_lionw (betas=[0.9, 0.95]) |
learning_rate | 1.0e-05 for full finetuning, 4.0e-05 for LoRA |
scheduler | inv_sqrt_with_warmup (t_scale=1000ba, t_warmup=1000ba, t_cooldown=5086ba, alpha_f_decay=1, alpha_f_cooldown=0) |
weight_decay | 0 |
precision | amp_bf16 |
global_train_batch_size | 192 |
device_train_microbatch_size | 6 |
gradient_clipping | norm (threshold=1) |
num_gpus | 32 |
We trained models for 0.25B, 0.5B, 1B, 2B, 4B, 8B, 16B and 20B tokens. These checkpoints can be found for each LoRA and full finetuning setting in the HuggingFace model branches.
Code IFT (Magicoder-Evol-Instruct-110K)
Magicoder-Evol-Instruct-110K (Wei et al., 2023) This dataset contains 72.97M tokens of programming questions and answers. It reproduces the “Evol-Instruct” dataset of WizardCoder (Luo et al., 2023b) by iteratively prompting an LLM (GPT-4) to increase the difficulty of a set of question-answer pairs from Code Alpaca (Chaudhary, 2023).
Parameter | Value |
---|---|
max_seq_len | 4096 |
optimizer | decoupled_lionw (betas=[0.9, 0.95]) |
learning_rate | 5e-5 for full finetuning; 2e-4 for rank r = 16, 64 and 1e-4 for r = 256 α = 2r = 512 (due to instabilities/loss spikes at 2e-4) |
scheduler | cosine_with_warmup (alpha_f=0.01, t_warmup=0.1dur) |
weight_decay | 0 |
precision | amp_bf16 |
global_train_batch_size | 192 |
device_train_microbatch_size | 6 |
gradient_clipping | norm (threshold=1) |
num_gpus | 32 |
Each model was finetuned separately for 1, 2, 4, 8 and 16 epochs.
Epoch | Number of Batches | Estimated Tokens |
---|---|---|
1 | 193 | 72,970,000 |
2 | 386 | 145,940,000 |
4 | 772 | 291,880,000 |
8 | 1544 | 583,760,000 |
16 | 3088 | 1,167,520,000 |
Math IFT (MetaMathQA)
MetaMathQA (Yu et al., 2023) This dataset was built by bootstrapping mathematical word problems from the training sets of GSM8K (Cobbe et al., 2021) and MATH (Hendrycks et al., 2021) by rewriting the questions with variations using GPT-3.5. This dataset contains 395K question-answer pairs and roughly 103M tokens.
Parameter | Value |
---|---|
seq_len | 1024 |
optimizer | decoupled_lionw (betas=[0.9, 0.95]) |
learning_rate | Full finetuning: 1e-5, LoRA: 1e-4 for r = 16, 64, 5e-5 for r = 256 due to instabilities |
scheduler | cosine_with_warmup (alpha_f=0.01, t_warmup=0.1dur) |
weight_decay | 0 |
precision | amp_bf16 |
global_train_batch_size | 768 |
device_train_microbatch_size | 24 |
gradient_clipping | norm (threshold=1) |
num_gpus | 32 |
Each model was finetuned separately for 1, 2, 4, 8 and 16 epochs.
Epoch | Estimated Tokens |
---|---|
1 | 103,000,000 |
2 | 206,000,000 |
4 | 412,000,000 |
8 | 824,000,000 |
16 | 1,648,000,000 |
Evaluation
Model performance can be found in the paper LoRA Learns Less and Forgets Less. See Appendix for relevant tables.
Citation
BibTeX:
@article{
biderman2024lora,
title={Lo{RA} Learns Less and Forgets Less},
author={Dan Biderman and Jacob Portes and Jose Javier Gonzalez Ortiz and Mansheej Paul and Philip Greengard and Connor Jennings and Daniel King and Sam Havens and Vitaliy Chiley and Jonathan Frankle and Cody Blakeney and John Patrick Cunningham},
journal={Transactions on Machine Learning Research},
issn={2835-8856},
year={2024},
url={https://openreview.net/forum?id=aloEru2qCG},
note={Featured Certification}
}
Framework versions
- PEFT 0.11.1
- Downloads last month
- 0
Model tree for LoRA-TMLR-2024/magicoder-full-finetuning-lr-5e-05
Base model
meta-llama/Llama-2-7b-hf