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-2.0
|
| 3 |
+
language:
|
| 4 |
+
- en
|
| 5 |
+
base_model:
|
| 6 |
+
- meta-llama/Llama-3.3-70B-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/llama317
|
| 24 |
+
- https://huggingface.co/kevin009/llama318
|
| 25 |
+
- https://huggingface.co/kevin009/llama319
|
| 26 |
+
- https://huggingface.co/kevin009/llama320
|
| 27 |
+
- https://huggingface.co/kevin009/llamabase-r-16
|
| 28 |
+
|
| 29 |
+
## Merger Configuration
|
| 30 |
+
|
| 31 |
+
### Source Adapters
|
| 32 |
+
|
| 33 |
+
All source adapters share the following configuration:
|
| 34 |
+
- Rank (r): 16
|
| 35 |
+
- Alpha: 16
|
| 36 |
+
- Target Modules:
|
| 37 |
+
- q_proj (Query projection)
|
| 38 |
+
- k_proj (Key projection)
|
| 39 |
+
- v_proj (Value projection)
|
| 40 |
+
- o_proj (Output projection)
|
| 41 |
+
- up_proj (Upsampling projection)
|
| 42 |
+
- down_proj (Downsampling projection)
|
| 43 |
+
- gate_proj (Gate projection)
|
| 44 |
+
|
| 45 |
+
### Merger Details
|
| 46 |
+
|
| 47 |
+
- Merger Method: Linear interpolation
|
| 48 |
+
- Merger Weights: Equal weights (0.25) for each adapter
|
| 49 |
+
- Combined Rank: 16 (maintained from source adapters)
|
| 50 |
+
|
| 51 |
+
## Usage
|
| 52 |
+
|
| 53 |
+
This merged adapter must be used with the base Llama-3.1-8B-instruct model.
|
| 54 |
+
|
| 55 |
+
### Loading the Model
|
| 56 |
+
|
| 57 |
+
```python
|
| 58 |
+
from peft import PeftModel, PeftConfig
|
| 59 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 60 |
+
|
| 61 |
+
# Load base model
|
| 62 |
+
base_model = AutoModelForCausalLM.from_pretrained("meta-llama/Llama-3.1-8B-instruct")
|
| 63 |
+
tokenizer = AutoTokenizer.from_pretrained("meta-llama/Llama-3.1-8B-instruct")
|
| 64 |
+
|
| 65 |
+
# Load merged LoRA adapter
|
| 66 |
+
model = PeftModel.from_pretrained(base_model, "path_to_merged_adapter")
|
| 67 |
+
```
|
| 68 |
+
|
| 69 |
+
## Limitations and Biases
|
| 70 |
+
|
| 71 |
+
- This merged adapter inherits limitations and biases from:
|
| 72 |
+
- The base Llama-3.1-8B-instruct model
|
| 73 |
+
- All four source adapters
|
| 74 |
+
- The merging process may result in:
|
| 75 |
+
- Potential loss of specialized capabilities from individual adapters
|
| 76 |
+
- Averaged behavior across different adapter specializations
|
| 77 |
+
- Possible interference between adapter weights
|
| 78 |
+
|
| 79 |
+
## Merging Process
|
| 80 |
+
|
| 81 |
+
The adapters were merged using the following approach:
|
| 82 |
+
1. Linear interpolation of adapter weights
|
| 83 |
+
2. Equal weighting (0.25) applied to each source adapter
|
| 84 |
+
3. Preservation of original LoRA rank and architecture
|
| 85 |
+
|
| 86 |
+
### Method Used
|
| 87 |
+
|
| 88 |
+
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.
|
| 89 |
+
|
| 90 |
+
### Step-by-Step Merging Process
|
| 91 |
+
|
| 92 |
+
1. Load the base model and initial adapter:
|
| 93 |
+
```python
|
| 94 |
+
from peft import PeftModel, PeftConfig
|
| 95 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 96 |
+
|
| 97 |
+
MODEL_NAME = "meta-llama/Meta-Llama-3.1-8B-Instruct"
|
| 98 |
+
model = AutoModelForCausalLM.from_pretrained(MODEL_NAME)
|
| 99 |
+
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
|
| 100 |
+
|
| 101 |
+
# Load first adapter as base
|
| 102 |
+
peft_model = PeftModel.from_pretrained(model, "llama319", adapter_name="llama319")
|
| 103 |
+
```
|
| 104 |
+
|
| 105 |
+
2. Load additional adapters:
|
| 106 |
+
```python
|
| 107 |
+
# Load remaining adapters
|
| 108 |
+
peft_model.load_adapter("llama320", adapter_name="llama320")
|
| 109 |
+
peft_model.load_adapter("llama318", adapter_name="llama318")
|
| 110 |
+
peft_model.load_adapter("llama317", adapter_name="llama317")
|
| 111 |
+
peft_model.load_adapter("kevin009/llamabase-r-16", adapter_name="kevin009/llamabase-r-16") # base model with alpha 1
|
| 112 |
+
```
|
| 113 |
+
|
| 114 |
+
3. Configure and execute the merger:
|
| 115 |
+
```python
|
| 116 |
+
# Define adapters and their weights
|
| 117 |
+
adapters = ["llama319", "llama320", "llama318", "llama317"]
|
| 118 |
+
weights = [1.0, 1.0, 1.0, 1.0] # Equal weights for all adapters
|
| 119 |
+
|
| 120 |
+
# Merge adapters
|
| 121 |
+
peft_model.add_weighted_adapter(
|
| 122 |
+
adapters,
|
| 123 |
+
weights,
|
| 124 |
+
"merge",
|
| 125 |
+
combination_type="ties", # Using ties combination method
|
| 126 |
+
density=0.2 # Density parameter for merger
|
| 127 |
+
)
|
| 128 |
+
|
| 129 |
+
# Set active adapter to merged version
|
| 130 |
+
peft_model.set_adapter("merge")
|
| 131 |
+
|
| 132 |
+
# Save the merged adapter
|
| 133 |
+
peft_model.save_pretrained("merged")
|
| 134 |
+
```
|
| 135 |
+
|
| 136 |
+
### Key Parameters
|
| 137 |
+
|
| 138 |
+
- `combination_type="ties"`: Uses the TIES (Task Interference Edge Selection) method for combining adapters
|
| 139 |
+
- `density=0.2`: Controls the sparsity of the merged weights
|
| 140 |
+
- `weights=[1.0, 1.0, 1.0, 1.0]`: Equal weighting for all adapters (0.25 each after normalization)
|
| 141 |
+
|
| 142 |
+
### Notes
|
| 143 |
+
|
| 144 |
+
- The order of loading adapters may affect the final result
|
| 145 |
+
- Equal weights were chosen to maintain balanced influence from each adapter
|
| 146 |
+
- The merged adapter maintains the same architecture and rank as the original adapters
|
| 147 |
+
- 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.
|
| 148 |
+
|
| 149 |
+
## License
|
| 150 |
+
|
| 151 |
+
Licensed under Apache 2.0 License.
|
| 152 |
+
|
| 153 |
+
This merged adapter is part of independent individual research work. While the code is open-source under the Apache 2.0 license, please note:
|
| 154 |
+
|
| 155 |
+
- You are free to use, modify, and distribute this adapter following the Apache 2.0 license terms
|
| 156 |
+
- This work is provided "as is" without warranties or conditions of any kind
|
| 157 |
+
- This is an independent research project and not affiliated with any organization
|
| 158 |
+
- Attribution is appreciated but not required
|
| 159 |
+
- For full license details, see: https://www.apache.org/licenses/LICENSE-2.0
|