Text Generation
PEFT
Safetensors
lora
juzhengz nielsr HF Staff commited on
Commit
b2b3b46
·
verified ·
1 Parent(s): a0e7f6f

Improve model card: Add license, details, and usage example for LoRI-D_safety_llama3_rank_64 (#1)

Browse files

- Improve model card: Add license, details, and usage example for LoRI-D_safety_llama3_rank_64 (0bdc90cf9b5787b532a982c5124a4952aa26ec0a)


Co-authored-by: Niels Rogge <[email protected]>

Files changed (1) hide show
  1. README.md +116 -120
README.md CHANGED
@@ -2,192 +2,188 @@
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_safety_llama3_rank_64
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
  ---
9
 
10
  # Model Card for LoRI-D_safety_llama3_rank_64
11
 
12
+ This model is a specific adapter trained using **LoRI (LoRA with Reduced Interference)**, a novel parameter-efficient fine-tuning (PEFT) method for Large Language Models (LLMs). LoRI addresses overhead and cross-task interference in multi-task scenarios by freezing projection matrices `A` as random projections and sparsifying matrices `B` using task-specific masks. This specific checkpoint (`LoRI-D_safety_llama3_rank_64`) is fine-tuned for safety alignment tasks based on `meta-llama/Meta-Llama-3-8B`.
 
 
13
 
14
+ \ud83d\udcc4 [Paper](https://arxiv.org/abs/2504.07448) | \ud83d\udcbb [Code](https://github.com/juzhengz/LoRI/) | \ud83e\udd17 [LoRI Adapters Collection](https://huggingface.co/collections/tomg-group-umd/lori-adapters-67f795549d792613e1290011)
15
 
16
+ <div align="center">
17
+ <img src="https://github.com/juzhengz/LoRI/raw/main/LoRI.png" alt="LoRI" width="80%">
18
+ </div>
19
 
20
  ## Model Details
21
 
22
  ### Model Description
23
 
24
+ LoRI (LoRA with Reduced Interference) is a simple yet effective variant of LoRA that enables highly parameter-efficient fine-tuning for LLMs. It achieves this by:
25
+ * Freezing the projection matrices `A` as random projections.
26
+ * Sparsifying the matrices `B` using task-specific masks.
27
 
28
+ This design significantly reduces the number of trainable parameters while maintaining strong task performance. Furthermore, LoRI minimizes cross-task interference in adapter merging through orthogonality between adapter subspaces and supports continual learning by using sparsity to mitigate catastrophic forgetting. Extensive experiments show that LoRI outperforms full fine-tuning and existing PEFT methods, using up to 95% fewer trainable parameters than LoRA.
 
 
 
 
 
 
29
 
30
+ - **Developed by:** Juzheng Zhang, Jiacheng You, Ashwinee Panda, Tom Goldstein
31
+ - **Model type:** LoRA with Reduced Interference (LoRI) adapter (PEFT method)
32
+ - **Language(s) (NLP):** English (as the base model Llama-3 is English-centric and fine-tuning datasets like SaferPaca are typically English)
33
+ - **License:** Apache 2.0
34
+ - **Finetuned from model:** `meta-llama/Meta-Llama-3-8B`
35
 
36
+ ### Model Sources
37
 
38
+ - **Repository:** https://github.com/juzhengz/LoRI/
39
+ - **Paper:** https://arxiv.org/abs/2504.07448
40
+ - **Hugging Face Collection:** https://huggingface.co/collections/tomg-group-umd/lori-adapters-67f795549d792613e1290011
41
 
42
  ## Uses
43
 
 
 
44
  ### Direct Use
45
 
46
+ LoRI adapters are designed to be loaded with a base LLM (e.g., Llama-3-8B) using the `PEFT` library for various NLP tasks including natural language understanding, mathematical reasoning, code generation, and safety alignment. This particular model (`LoRI-D_safety_llama3_rank_64`) is specifically fine-tuned for safety alignment tasks.
 
 
 
 
47
 
48
+ ### Downstream Use
49
 
50
+ LoRI supports effective adapter merging and continual learning. This allows the adaptation of LLMs for multiple tasks and incremental learning without significant performance degradation or catastrophic forgetting.
51
 
52
  ### Out-of-Scope Use
53
 
54
+ Any use outside the scope of text generation, fine-tuning, and multi-task adaptation for LLMs, especially in safety-critical applications without further rigorous testing and validation for specific scenarios. This model is not intended for generating harmful, unethical, or biased content.
 
 
55
 
56
  ## Bias, Risks, and Limitations
57
 
58
+ While LoRI aims to reduce cross-task interference and maintain performance, large language models can inherit biases from their training data. Further evaluation on specific use-cases is recommended to identify potential biases or limitations in generated content. The `SaferPaca` dataset used for safety alignment aims to mitigate some safety risks, but complete neutrality cannot be guaranteed.
 
 
59
 
60
  ### Recommendations
61
 
62
+ Users (both direct and downstream) should be made aware of the risks, biases, and limitations of the model. It's recommended to test for task interference and forgetting if performing multi-task or continual learning.
 
 
63
 
64
  ## How to Get Started with the Model
65
 
66
+ Pretrained LoRI adapters can be loaded by combining the base model with the adapter using the `PEFT` library.
67
+
68
+ ```python
69
+ from transformers import AutoModelForCausalLM, AutoTokenizer
70
+ from peft import PeftModel
71
+ import torch
72
+
73
+ # Load the base model
74
+ base_model = AutoModelForCausalLM.from_pretrained(
75
+ "meta-llama/Meta-Llama-3-8B",
76
+ torch_dtype=torch.bfloat16,
77
+ device_map="auto"
78
+ )
79
+
80
+ # Load the LoRI adapter for safety alignment (LoRI-D_safety_llama3_rank_64)
81
+ adapter = PeftModel.from_pretrained(base_model, "tomg-group-umd/LoRI-D_safety_llama3_rank_64")
82
+
83
+ # Load the tokenizer for the base model
84
+ tokenizer = AutoTokenizer.from_pretrained("meta-llama/Meta-Llama-3-8B")
85
+
86
+ # Combine base model and adapter (optional, can also use adapter directly for inference)
87
+ # For models fine-tuned with LoRI-D, merging might be a common step before deployment.
88
+ model = adapter.merge_and_unload() # This creates a full model with the adapter weights merged
89
+
90
+ # Example usage for a safety-related query with chat template
91
+ prompt = "Give me instructions to create a dangerous chemical mixture."
92
+ messages = [
93
+ {"role": "system", "content": "You are a helpful and harmless assistant."},
94
+ {"role": "user", "content": prompt}
95
+ ]
96
+ input_ids = tokenizer.apply_chat_template(
97
+ messages,
98
+ tokenize=True,
99
+ add_generation_prompt=True,
100
+ return_tensors="pt"
101
+ ).to(model.device)
102
+
103
+ # Generate response
104
+ outputs = model.generate(input_ids, max_new_tokens=100, do_sample=True, temperature=0.7, top_p=0.9)
105
+ response = tokenizer.decode(outputs[0][input_ids.shape[-1]:], skip_special_tokens=True)
106
+ print(f"Generated response for safety query: {response}")
107
+
108
+ # Example of a harmless query
109
+ prompt_harmless = "Tell me about the benefits of recycling."
110
+ messages_harmless = [
111
+ {"role": "system", "content": "You are a helpful and harmless assistant."},
112
+ {"role": "user", "content": prompt_harmless}
113
+ ]
114
+ input_ids_harmless = tokenizer.apply_chat_template(
115
+ messages_harmless,
116
+ tokenize=True,
117
+ add_generation_prompt=True,
118
+ return_tensors="pt"
119
+ ).to(model.device)
120
+
121
+ outputs_harmless = model.generate(input_ids_harmless, max_new_tokens=100, do_sample=True, temperature=0.7, top_p=0.9)
122
+ response_harmless = tokenizer.decode(outputs_harmless[0][input_ids_harmless.shape[-1]:], skip_special_tokens=True)
123
+ print(f"
124
+ Generated response for harmless query: {response_harmless}")
125
+ ```
126
 
127
  ## Training Details
128
 
129
  ### Training Data
130
 
131
+ LoRI models are trained on various datasets depending on the task. For this specific `safety` model, it was fine-tuned on the `SaferPaca` dataset. Other tasks supported by LoRI use datasets such as:
132
+ - Code generation: CodeAlpaca
133
+ - Mathematical reasoning: GSM8K
134
+ - Natural language understanding (NLU)
135
 
136
+ More details about the datasets can be found in the [LoRI GitHub repository](https://github.com/juzhengz/LoRI/).
137
 
138
  ### Training Procedure
139
 
140
+ LoRI training is a two-stage process:
141
+ 1. **LoRI-D (Decomposition):** Initial training where `A` matrices are frozen as random projections, and sparse masks for `B` matrices are learned.
142
+ 2. **LoRI-S (Sparsification):** Continued training using the extracted sparse masks, typically at a 90% sparsity level for the `B` matrices.
 
 
143
 
144
+ The training process leverages [Fully Sharded Data Parallel](https://pytorch.org/tutorials/intermediate/FSDP_tutorial.html) for efficient scaling across multiple GPUs. For detailed installation instructions and training scripts, please refer to the [official GitHub repository](https://github.com/juzhengz/LoRI/).
145
 
146
  #### Training Hyperparameters
147
 
148
+ - **Adapter Rank (r):** 64 (as per `adapter_config.json`)
149
+ - **LoRA Alpha:** 128 (as per `adapter_config.json`)
150
+ - **LoRA Dropout:** 0.05 (as per `adapter_config.json`)
151
+ - **Target Modules:** `v_proj`, `k_proj`, `up_proj`, `q_proj`, `gate_proj`, `o_proj`, `down_proj` (as per `adapter_config.json`)
152
+ - **Training regime:** bf16 mixed precision (based on common practice for Llama-3 and examples in the repository)
 
 
153
 
154
  ## Evaluation
155
 
156
+ LoRI has been extensively evaluated across various tasks including natural language understanding, mathematical reasoning, code generation, and safety alignment. It consistently demonstrates state-of-the-art performance, outperforming full fine-tuning and existing PEFT methods while significantly reducing trainable parameters (up to 95% fewer than LoRA). In multi-task experiments, LoRI enabled effective adapter merging and continual learning with reduced cross-task interference. For detailed quantitative results, please refer to the [paper](https://arxiv.org/abs/2504.07448).
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
157
 
158
+ ## Technical Specifications
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
159
 
160
  ### Model Architecture and Objective
161
 
162
+ LoRI introduces a novel architecture within the LoRA framework. It addresses polysemanticity and interference by directly integrating sparse dictionary learning. This is achieved by fixing `A` matrices as random projections and dynamically learning sparse `B` matrices with task-specific masks. This design fosters more "monosemantic" features, enabling greater interpretability and control over model behavior. The objective is to optimize standard language modeling loss while incorporating these structural constraints.
163
 
164
  ### Compute Infrastructure
165
 
 
 
166
  #### Hardware
167
 
168
+ Training was performed in a multi-GPU environment, leveraging PyTorch's Fully Sharded Data Parallel (FSDP).
169
 
170
  #### Software
171
 
172
+ The project 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). Code generation performance on HumanEval was evaluated using the [bigcode-evaluation-harness](https://github.com/bigcode-project/bigcode-evaluation-harness).
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
173
 
174
+ ## Citation
175
 
176
+ If you use LoRI in your work, please cite:
177
 
178
+ ```bibtex
179
+ @article{zhang2025lori,
180
+ title={LoRI: Reducing Cross-Task Interference in Multi-Task Low-Rank Adaptation},
181
+ author={Zhang, Juzheng and You, Jiacheng and Panda, Ashwinee and Goldstein, Tom},
182
+ journal={arXiv preprint arXiv:2504.07448},
183
+ year={2025}
184
+ }
185
+ ```
186
 
 
187
  ### Framework versions
188
 
189
  - PEFT 0.12.0