Improve model card for LoRI-D_code_llama3_rank_32: Add details, usage, and license

#1
by nielsr HF Staff - opened
Files changed (1) hide show
  1. README.md +129 -118
README.md CHANGED
@@ -2,192 +2,203 @@
2
  base_model: meta-llama/Meta-Llama-3-8B
3
  library_name: peft
4
  pipeline_tag: text-generation
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  ---
6
 
7
  # Model Card for LoRI-D_code_llama3_rank_32
8
 
9
- This model is part of [LoRI: Reducing Cross-Task Interference in Multi-Task Low-Rank Adaptation](https://arxiv.org/abs/2504.07448).
10
-
11
- <!-- Provide a quick summary of what the model is/does. -->
12
 
 
13
 
 
 
 
14
 
15
  ## Model Details
16
 
17
  ### Model Description
18
 
19
- <!-- Provide a longer summary of what this model is. -->
20
-
21
-
22
 
23
- - **Developed by:** [More Information Needed]
24
- - **Funded by [optional]:** [More Information Needed]
25
- - **Shared by [optional]:** [More Information Needed]
26
- - **Model type:** [More Information Needed]
27
- - **Language(s) (NLP):** [More Information Needed]
28
- - **License:** [More Information Needed]
29
- - **Finetuned from model [optional]:** [More Information Needed]
30
 
31
- ### Model Sources [optional]
 
 
 
 
32
 
33
- <!-- Provide the basic links for the model. -->
34
 
35
- - **Repository:** [More Information Needed]
36
- - **Paper [optional]:** [More Information Needed]
37
- - **Demo [optional]:** [More Information Needed]
38
 
39
  ## Uses
40
 
41
- <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
42
-
43
  ### Direct Use
44
 
45
- <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
46
-
47
- [More Information Needed]
 
 
48
 
49
- ### Downstream Use [optional]
50
 
51
- <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
52
 
53
- [More Information Needed]
54
 
55
  ### Out-of-Scope Use
56
 
57
- <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
58
-
59
- [More Information Needed]
60
 
61
  ## Bias, Risks, and Limitations
62
 
63
- <!-- This section is meant to convey both technical and sociotechnical limitations. -->
64
-
65
- [More Information Needed]
66
 
67
  ### Recommendations
68
 
69
- <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
70
-
71
- Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
72
 
73
  ## How to Get Started with the Model
74
 
75
  Use the code below to get started with the model.
76
 
77
- [More Information Needed]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
 
79
  ## Training Details
80
 
 
 
81
  ### Training Data
82
 
83
- <!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
 
 
 
 
84
 
85
- [More Information Needed]
86
 
87
  ### Training Procedure
88
 
89
- <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
90
-
91
- #### Preprocessing [optional]
92
-
93
- [More Information Needed]
94
-
95
 
96
  #### Training Hyperparameters
97
 
98
- - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
99
-
100
- #### Speeds, Sizes, Times [optional]
101
-
102
- <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
103
-
104
- [More Information Needed]
105
 
106
  ## Evaluation
107
 
108
- <!-- This section describes the evaluation protocols and provides the results. -->
109
-
110
- ### Testing Data, Factors & Metrics
111
-
112
- #### Testing Data
113
-
114
- <!-- This should link to a Dataset Card if possible. -->
115
-
116
- [More Information Needed]
117
-
118
- #### Factors
119
-
120
- <!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
121
-
122
- [More Information Needed]
123
 
124
- #### Metrics
125
-
126
- <!-- These are the evaluation metrics being used, ideally with a description of why. -->
127
-
128
- [More Information Needed]
129
-
130
- ### Results
131
-
132
- [More Information Needed]
133
-
134
- #### Summary
135
-
136
-
137
-
138
- ## Model Examination [optional]
139
-
140
- <!-- Relevant interpretability work for the model goes here -->
141
-
142
- [More Information Needed]
143
-
144
- ## Technical Specifications [optional]
145
 
146
  ### Model Architecture and Objective
147
 
148
- [More Information Needed]
 
 
 
149
 
150
  ### Compute Infrastructure
151
 
152
- [More Information Needed]
153
-
154
- #### Hardware
155
-
156
- [More Information Needed]
157
 
158
  #### Software
159
 
160
- [More Information Needed]
161
-
162
- ## Citation [optional]
163
-
164
- <!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
165
-
166
- **BibTeX:**
167
-
168
- [More Information Needed]
169
-
170
- **APA:**
171
-
172
- [More Information Needed]
173
-
174
- ## Glossary [optional]
175
-
176
- <!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
177
-
178
- [More Information Needed]
179
 
180
- ## More Information [optional]
181
 
182
- [More Information Needed]
183
 
184
- ## Model Card Authors [optional]
 
 
 
 
 
 
 
185
 
186
- [More Information Needed]
187
 
188
- ## Model Card Contact
189
 
190
- [More Information Needed]
191
  ### Framework versions
192
 
193
  - PEFT 0.12.0
 
2
  base_model: meta-llama/Meta-Llama-3-8B
3
  library_name: peft
4
  pipeline_tag: text-generation
5
+ license: apache-2.0
6
+ tags:
7
+ - lora
8
+ - peft
9
+ - fine-tuning
10
+ - language-model
11
+ - code-generation
12
+ - natural-language-understanding
13
+ - mathematical-reasoning
14
+ - safety-alignment
15
+ - multi-task
16
+ - continual-learning
17
+ - llama
18
+ - llama-3
19
  ---
20
 
21
  # Model Card for LoRI-D_code_llama3_rank_32
22
 
23
+ This model is part of [LoRI: Reducing Cross-Task Interference in Multi-Task Low-Rank Adaptation](https://huggingface.co/papers/2504.07448).
 
 
24
 
25
+ LoRI (LoRA with Reduced Interference) is a simple yet effective approach that freezes the projection matrices $A$ as random projections and sparsifies the matrices $B$ using task-specific masks. This design substantially reduces the number of trainable parameters while maintaining strong task performance. Moreover, LoRI minimizes cross-task interference in adapter merging by leveraging the orthogonality between adapter subspaces, and supports continual learning by using sparsity to mitigate catastrophic forgetting. Extensive experiments across natural language understanding, mathematical reasoning, code generation, and safety alignment tasks demonstrate that LoRI outperforms full fine-tuning and existing PEFT methods, while using up to 95% fewer trainable parameters than LoRA. In multi-task experiments, LoRI enables effective adapter merging and continual learning with reduced cross-task interference.
26
 
27
+ <div align="center">
28
+ <img src="https://github.com/juzhengz/LoRI/raw/main/LoRI.png" alt="LoRI" width="80%">
29
+ </div>
30
 
31
  ## Model Details
32
 
33
  ### Model Description
34
 
35
+ LoRI (LoRA with Reduced Interference) is a novel parameter-efficient fine-tuning (PEFT) method designed to address the overhead and parameter interference often encountered in multi-task scenarios for Large Language Models (LLMs). By freezing projection matrices `A` as random projections and sparsifying matrices `B` with task-specific masks, LoRI significantly reduces trainable parameters while preserving strong task performance and minimizing cross-task interference. This approach also supports continual learning by leveraging sparsity to mitigate catastrophic forgetting.
 
 
36
 
37
+ This specific model, `LoRI-D_code_llama3_rank_32`, is a LoRI adapter based on the `meta-llama/Meta-Llama-3-8B` model, specifically fine-tuned for code generation tasks.
 
 
 
 
 
 
38
 
39
+ - **Developed by:** Juzheng Zhang, Jiacheng You, Ashwinee Panda, Tom Goldstein
40
+ - **Model type:** Parameter-Efficient Fine-Tuning (PEFT) adapter; a variant of Low-Rank Adaptation (LoRA).
41
+ - **Language(s) (NLP):** English (as the primary language for the base model and tasks such as NLU, mathematical reasoning, code generation, and safety alignment).
42
+ - **License:** Apache-2.0
43
+ - **Finetuned from model:** `meta-llama/Meta-Llama-3-8B`
44
 
45
+ ### Model Sources
46
 
47
+ - **Repository:** [https://github.com/juzhengz/LoRI/](https://github.com/juzhengz/LoRI/)
48
+ - **Paper:** [https://huggingface.co/papers/2504.07448](https://huggingface.co/papers/2504.07448)
49
+ - **Hugging Face Collection:** [https://huggingface.co/collections/tomg-group-umd/lori-adapters-67f795549d792613e1290011](https://huggingface.co/collections/tomg-group-umd/lori-adapters-67f795549d792613e1290011)
50
 
51
  ## Uses
52
 
 
 
53
  ### Direct Use
54
 
55
+ LoRI adapters are intended for efficient fine-tuning of Large Language Models on various downstream tasks, including:
56
+ - Natural Language Understanding (NLU)
57
+ - Mathematical Reasoning
58
+ - Code Generation
59
+ - Safety Alignment
60
 
61
+ They can be loaded as PEFT adapters on top of a base LLM to enhance performance with reduced parameter overhead.
62
 
63
+ ### Downstream Use
64
 
65
+ LoRI enables effective adapter merging for multi-task applications, allowing a single model to perform well across several distinct tasks without significant performance degradation. It also supports continual learning, facilitating model adaptation to new tasks sequentially while mitigating catastrophic forgetting.
66
 
67
  ### Out-of-Scope Use
68
 
69
+ This model is not intended for generating harmful, biased, or unethical content. Users should ensure compliance with the ethical guidelines of the base models and apply appropriate content filtering. It is not suitable for standalone use without a compatible base LLM or for tasks outside its trained domains without further adaptation.
 
 
70
 
71
  ## Bias, Risks, and Limitations
72
 
73
+ As an adapter for Large Language Models, LoRI inherits potential biases and limitations from its base model (`meta-llama/Meta-Llama-3-8B`) and the datasets it was fine-tuned on. Users should be aware that results might reflect biases present in the training data. While LoRI aims to reduce cross-task interference, complete elimination of such interference or catastrophic forgetting is not guaranteed. Performance on highly out-of-distribution tasks may be limited.
 
 
74
 
75
  ### Recommendations
76
 
77
+ Users (both direct and downstream) should be made aware of the risks, biases, and limitations of the model. It is recommended to perform further evaluation on specific target datasets and contexts to understand its performance and potential biases relevant to the application. Implement appropriate safeguards and content filtering when deploying the model in production environments.
 
 
78
 
79
  ## How to Get Started with the Model
80
 
81
  Use the code below to get started with the model.
82
 
83
+ ```python
84
+ import torch
85
+ from transformers import AutoModelForCausalLM, AutoTokenizer
86
+ from peft import PeftModel
87
+
88
+ # Load the base model
89
+ base_model_path = "meta-llama/Meta-Llama-3-8B"
90
+ base_model = AutoModelForCausalLM.from_pretrained(
91
+ base_model_path,
92
+ torch_dtype=torch.bfloat16, # Use torch.float16 if bfloat16 is not supported
93
+ device_map="auto" # Distributes the model across available devices
94
+ )
95
+
96
+ # Load the LoRI adapter (this model is for code generation)
97
+ lori_adapter_path = "tomg-group-umd/LoRI-D_code_llama3_rank_32"
98
+ model = PeftModel.from_pretrained(base_model, lori_adapter_path)
99
+
100
+ # Load the tokenizer
101
+ tokenizer = AutoTokenizer.from_pretrained(base_model_path)
102
+
103
+ # Example usage for code generation
104
+ prompt = "def factorial(n):
105
+ if n == 0:
106
+ return 1
107
+ else:
108
+ return n * "
109
+
110
+ # Apply chat template if using a chat-tuned base model (Llama-3 is chat-tuned)
111
+ # Or directly tokenize if the base model is not primarily chat-tuned
112
+ messages = [{"role": "user", "content": prompt}]
113
+ input_ids = tokenizer.apply_chat_template(
114
+ messages,
115
+ tokenize=True,
116
+ add_generation_prompt=True,
117
+ return_tensors="pt"
118
+ ).to(model.device)
119
+
120
+ # Generate text
121
+ outputs = model.generate(
122
+ input_ids,
123
+ max_new_tokens=50,
124
+ do_sample=True,
125
+ temperature=0.7,
126
+ top_p=0.9
127
+ )
128
+
129
+ # Decode and print the generated response (excluding the prompt for cleaner output)
130
+ response = tokenizer.decode(outputs[0][len(input_ids[0]):], skip_special_tokens=True)
131
+ print(response)
132
+ ```
133
 
134
  ## Training Details
135
 
136
+ LoRI is implemented using Fully Sharded Data Parallel (FSDP) and can be executed in a multi-GPU environment. Training scripts are provided for various tasks covering Natural Language Understanding (NLU), Code Generation, Mathematical Reasoning, and Safety Alignment.
137
+
138
  ### Training Data
139
 
140
+ LoRI adapters were trained on datasets corresponding to various tasks:
141
+ - **Code generation tasks:** CodeAlpaca
142
+ - **Mathematical reasoning tasks:** GSM8K
143
+ - **Safety alignment tasks:** Saferpaca
144
+ - **Natural Language Understanding (NLU) tasks:** Specific NLU datasets (refer to the paper for a full list).
145
 
146
+ More details on these datasets can be found in the [LoRI GitHub repository](https://github.com/juzhengz/LoRI/).
147
 
148
  ### Training Procedure
149
 
150
+ LoRI training typically involves two main stages:
151
+ 1. **LoRI-D (Decomposition):** Initial training where projection matrices `A` are frozen as random projections, and matrices `B` are trained. This stage is used to extract sparse masks.
152
+ 2. **LoRI-S (Sparsification):** Continues training from LoRI-D, where matrices `B` are sparsified using task-specific masks (e.g., 90% sparsity for `LoRI-S`).
 
 
 
153
 
154
  #### Training Hyperparameters
155
 
156
+ - **PEFT Type:** LORA
157
+ - **LoRA Alpha (`lora_alpha`):** 64
158
+ - **LoRA Rank (`r`):** 32 (for this specific model `LoRI-D_code_llama3_rank_32`)
159
+ - **LoRA Dropout (`lora_dropout`):** 0.05
160
+ - **Target Modules:** `q_proj`, `o_proj`, `k_proj`, `v_proj`, `down_proj`, `gate_proj`, `up_proj`
161
+ - **Training Regime:** Mixed precision (e.g., bfloat16 commonly used with Llama-3).
162
+ - **Optimization:** Fully Sharded Data Parallel (FSDP)
163
 
164
  ## Evaluation
165
 
166
+ Extensive experiments were conducted across natural language understanding, mathematical reasoning, code generation, and safety alignment tasks. The paper demonstrates that LoRI outperforms full fine-tuning and existing PEFT methods, while using up to 95% fewer trainable parameters than standard LoRA. In multi-task experiments, LoRI enables effective adapter merging and continual learning with reduced cross-task interference. Code generation performance on HumanEval is evaluated using the `bigcode-evaluation-harness`. For detailed quantitative results, please refer to the [paper](https://huggingface.co/papers/2504.07448).
 
 
 
 
 
 
 
 
 
 
 
 
 
 
167
 
168
+ ## Technical Specifications
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
169
 
170
  ### Model Architecture and Objective
171
 
172
+ LoRI introduces a novel architecture built upon existing Transformer-based LLMs, adapting the standard LoRA approach. It achieves efficiency and interference reduction by:
173
+ - Freezing the low-rank projection matrix `A` as random projections.
174
+ - Sparsifying the low-rank projection matrix `B` using task-specific masks.
175
+ The primary objective is to minimize cross-task interference in multi-task low-rank adaptation, while significantly reducing the trainable parameter count and maintaining strong performance.
176
 
177
  ### Compute Infrastructure
178
 
179
+ The training and evaluation were performed on multi-GPU environments, leveraging technologies like FSDP. Experiments were conducted with LLaMA-3-8B and Mistral-7B base models.
 
 
 
 
180
 
181
  #### Software
182
 
183
+ The implementation relies on `PyTorch`, `transformers`, and `peft` libraries. It builds on the codebase of [dpo-rlaif](https://github.com/architsharma97/dpo-rlaif) and incorporates code from [lottery-ticket-adaptation](https://github.com/kiddyboots216/lottery-ticket-adaptation). Evaluation for code generation uses the [bigcode-evaluation-harness](https://github.com/bigcode-project/bigcode-evaluation-harness).
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
184
 
185
+ ## Citation
186
 
187
+ If you use LoRI in your work, please cite:
188
 
189
+ ```bibtex
190
+ @article{zhang2025lori,
191
+ title={LoRI: Reducing Cross-Task Interference in Multi-Task Low-Rank Adaptation},
192
+ author={Zhang, Juzheng and You, Jiacheng and Panda, Ashwinee and Goldstein, Tom},
193
+ journal={arXiv preprint arXiv:2504.07448},
194
+ year={2025}
195
+ }
196
+ ```
197
 
198
+ ## More Information
199
 
200
+ For further details on installation, training from scratch, adapter merging, continual learning, and customizing base models/losses, please refer to the [official GitHub repository](https://github.com/juzhengz/LoRI/).
201
 
 
202
  ### Framework versions
203
 
204
  - PEFT 0.12.0