kevin009 commited on
Commit
dcfc1a6
·
verified ·
1 Parent(s): dfef675

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +202 -0
README.md ADDED
@@ -0,0 +1,202 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ language:
4
+ - en
5
+ base_model:
6
+ - meta-llama/Llama-3.1-8B-instruct
7
+ pipeline_tag: text-generation
8
+ tags:
9
+ - lora
10
+ - adapter
11
+ - writing
12
+ - CoT
13
+ ---
14
+ # Merged-Llama-Adapters-317-320
15
+
16
+ A merged LoRA adapter combining four fine-tuned adapters (317-320) for the Llama-3.1-8B language model.
17
+
18
+ ## Model Details
19
+
20
+ - Base Model: meta-llama/Llama-3.1-8B-instruct
21
+ - Adaptation Method: Merged LoRA
22
+ - Source Adapters:
23
+ - https://huggingface.co/kevin009/llama313
24
+ - https://huggingface.co/kevin009/llama314
25
+ - https://huggingface.co/kevin009/llama315
26
+ - https://huggingface.co/kevin009/llama316
27
+ - https://huggingface.co/kevin009/llama317
28
+ - https://huggingface.co/kevin009/llama318
29
+ - https://huggingface.co/kevin009/llama319
30
+ - https://huggingface.co/kevin009/llama320
31
+ - https://huggingface.co/kevin009/llama326
32
+ - https://huggingface.co/kevin009/llama324
33
+
34
+ ## Merger Configuration
35
+
36
+ ### Source Adapters
37
+
38
+ All source adapters share the following configuration:
39
+ - Rank (r): 16
40
+ - Alpha: 16
41
+ - Target Modules:
42
+ - q_proj (Query projection)
43
+ - k_proj (Key projection)
44
+ - v_proj (Value projection)
45
+ - o_proj (Output projection)
46
+ - up_proj (Upsampling projection)
47
+ - down_proj (Downsampling projection)
48
+ - gate_proj (Gate projection)
49
+
50
+ ### Merger Details
51
+
52
+ - Merger Method: Linear interpolation
53
+ - Merger Weights: Equal weights (0.25) for each adapter
54
+ - Combined Rank: 16 (maintained from source adapters)
55
+
56
+ ## Usage
57
+
58
+ This merged adapter must be used with the base Llama-3.1-8B-instruct model.
59
+
60
+ ### Loading the Model
61
+
62
+ ```python
63
+ from peft import PeftModel, PeftConfig
64
+ from transformers import AutoModelForCausalLM, AutoTokenizer
65
+
66
+ # Load base model
67
+ base_model = AutoModelForCausalLM.from_pretrained("meta-llama/Llama-3.1-8B-instruct")
68
+ tokenizer = AutoTokenizer.from_pretrained("meta-llama/Llama-3.1-8B-instruct")
69
+
70
+ # Load merged LoRA adapter
71
+ model = PeftModel.from_pretrained(base_model, "path_to_merged_adapter")
72
+ ```
73
+
74
+ ## Limitations and Biases
75
+
76
+ - This merged adapter inherits limitations and biases from:
77
+ - The base Llama-3.1-8B-instruct model
78
+ - All four source adapters
79
+ - The merging process may result in:
80
+ - Potential loss of specialized capabilities from individual adapters
81
+ - Averaged behavior across different adapter specializations
82
+ - Possible interference between adapter weights
83
+
84
+ ## Merging Process
85
+
86
+ The adapters were merged using the following approach:
87
+ 1. Linear interpolation of adapter weights
88
+ 2. Equal weighting (0.25) applied to each source adapter
89
+ 3. Preservation of original LoRA rank and architecture
90
+
91
+ ### Method Used
92
+
93
+ The adapters were merged using PEFT (Parameter-Efficient Fine-Tuning) library's weighted adapter combination feature. The process combines multiple LoRA adapters using linear interpolation with specified weights.
94
+
95
+ ### Step-by-Step Merging Process
96
+
97
+ 1. Load the base model and initial adapter:
98
+ ```python
99
+ from peft import PeftModel, PeftConfig
100
+ from transformers import AutoModelForCausalLM, AutoTokenizer
101
+
102
+ MODEL_NAME = "meta-llama/Meta-Llama-3.1-8B-Instruct"
103
+ model = AutoModelForCausalLM.from_pretrained(MODEL_NAME)
104
+ tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
105
+
106
+ # Load first adapter as base
107
+ peft_model = PeftModel.from_pretrained(model, "llama319", adapter_name="llama319")
108
+ ```
109
+
110
+ 2. Load additional adapters:
111
+ ```python
112
+ # Load remaining adapters
113
+ peft_model.load_adapter("llama320", adapter_name="llama320")
114
+ peft_model.load_adapter("llama318", adapter_name="llama318")
115
+ peft_model.load_adapter("llama317", adapter_name="llama317")
116
+ peft_model.load_adapter("llama313", adapter_name="llama313")
117
+ peft_model.load_adapter("llama314", adapter_name="llama314")
118
+ peft_model.load_adapter("llama315", adapter_name="llama315")
119
+ peft_model.load_adapter("llama316", adapter_name="llama316")
120
+ ```
121
+
122
+ 3. Configure and execute the merger:
123
+ ```python
124
+ # Load F32 models (higher precision)
125
+ peft_model.load_adapter("llama324", adapter_name="llama324")
126
+ peft_model.load_adapter("llama320", adapter_name="llama320")
127
+ peft_model.load_adapter("llama318", adapter_name="llama318")
128
+ peft_model.load_adapter("llama317", adapter_name="llama317")
129
+
130
+ # Load BF16 models
131
+ peft_model.load_adapter("llama316", adapter_name="llama316")
132
+ peft_model.load_adapter("llama315", adapter_name="llama315")
133
+ peft_model.load_adapter("llama314", adapter_name="llama314")
134
+ peft_model.load_adapter("llama313", adapter_name="llama313")
135
+
136
+ # Define adapters and weights
137
+ # F32 models weighted slightly higher due to higher precision
138
+ f32_adapters = ["llama319", "llama324", "llama320", "llama318", "llama317"]
139
+ bf16_adapters = ["llama316", "llama315", "llama314", "llama313"]
140
+
141
+ adapters = f32_adapters + bf16_adapters
142
+ weights = [1.2] * len(f32_adapters) + [0.8] * len(bf16_adapters) # Adjusted weights based on precision
143
+
144
+ peft_model.add_weighted_adapter(adapters, weights, "merge", combination_type="ties", density=0.2)
145
+ peft_model.set_adapter("merge")
146
+ peft_model.save_pretrained("merged")
147
+
148
+ ```
149
+
150
+ ### Key Parameters
151
+
152
+ - `combination_type="ties"`: Uses the TIES (Task Interference Edge Selection) method for combining adapters
153
+ - `density=0.2`: Controls the sparsity of the merged weights
154
+
155
+
156
+ ### Notes
157
+
158
+ - The order of loading adapters may affect the final result
159
+ - Equal weights were chosen to maintain balanced influence from each adapter
160
+ - The merged adapter maintains the same architecture and rank as the original adapters
161
+ - While this adapter merges multiple fine-tunes, each component was developed as part of independent research efforts to explore and language model capabilities as part of R&D process.
162
+
163
+
164
+ ## Datasets
165
+
166
+ - Not yet released, but should be released after evaluation has completed.
167
+ - Creating dataset alone tooks more than 3 month for creating 30k pairs dataset.
168
+ - Only 1k pairs example considered to be synthetic dataset, the rest half synthetic and human written text.
169
+
170
+ ### Use Cases
171
+
172
+ - This merged adapter can be used for a wide range of tasks, including but not limited to:
173
+ - Accessibility
174
+ - Revision & Editing
175
+ - instruction-following use with xml tags
176
+ - Thinking & reasoning with xml tag of <thinking> and </thinking>, if being asked i the instructions.
177
+
178
+
179
+ These Models not optimized for code, math, or other specialized tasks that need Perefence Optimization.
180
+
181
+ ## Why SFT Instead of RLHF/DPO?
182
+ - RLHF and DPO approaches often lead to vocabulary limitations and overfitting due to their optimization objectives
183
+
184
+
185
+ ## Why Multiple Adapters?
186
+ - Resource Issue: Placing the training into smaller adapters requires less GPU memory and compute time while gives more control over the training process.
187
+ - Iterative Development: Each adapter can be developed and tested independently
188
+ - Training Infrastructure: The complete fine-tuning process was conducted across multiple sessions, totaling over 100 hours on high-end GPUs (H100, H200, or L40s)
189
+ - Flexibility: Multiple adapters allow for different combinations or weightings
190
+
191
+
192
+ ## License
193
+
194
+ Licensed under Apache 2.0 License.
195
+
196
+ This merged adapter is part of independent individual research work. While the code is open-source under the Apache 2.0 license, please note:
197
+
198
+ - You are free to use, modify, and distribute this adapter following the Apache 2.0 license terms
199
+ - This work is provided "as is" without warranties or conditions of any kind
200
+ - This is an independent research project and not affiliated with any organization
201
+ - Attribution is appreciated but not required
202
+ - For full license details, see: https://www.apache.org/licenses/LICENSE-2.0