Update README.md
Browse files
README.md
CHANGED
|
@@ -1,199 +1,137 @@
|
|
| 1 |
---
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
---
|
| 5 |
|
| 6 |
-
#
|
| 7 |
|
| 8 |
-
|
| 9 |
|
|
|
|
| 10 |
|
|
|
|
| 11 |
|
| 12 |
## Model Details
|
| 13 |
|
| 14 |
### Model Description
|
| 15 |
|
| 16 |
-
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
- **
|
| 21 |
-
- **
|
| 22 |
-
- **
|
| 23 |
-
- **Model type:** [More Information Needed]
|
| 24 |
-
- **Language(s) (NLP):** [More Information Needed]
|
| 25 |
-
- **License:** [More Information Needed]
|
| 26 |
-
- **Finetuned from model [optional]:** [More Information Needed]
|
| 27 |
-
|
| 28 |
-
### Model Sources [optional]
|
| 29 |
-
|
| 30 |
-
<!-- Provide the basic links for the model. -->
|
| 31 |
-
|
| 32 |
-
- **Repository:** [More Information Needed]
|
| 33 |
-
- **Paper [optional]:** [More Information Needed]
|
| 34 |
-
- **Demo [optional]:** [More Information Needed]
|
| 35 |
-
|
| 36 |
-
## Uses
|
| 37 |
-
|
| 38 |
-
<!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
|
| 39 |
-
|
| 40 |
-
### Direct Use
|
| 41 |
-
|
| 42 |
-
<!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
|
| 43 |
-
|
| 44 |
-
[More Information Needed]
|
| 45 |
-
|
| 46 |
-
### Downstream Use [optional]
|
| 47 |
-
|
| 48 |
-
<!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
|
| 49 |
-
|
| 50 |
-
[More Information Needed]
|
| 51 |
-
|
| 52 |
-
### Out-of-Scope Use
|
| 53 |
-
|
| 54 |
-
<!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
|
| 55 |
-
|
| 56 |
-
[More Information Needed]
|
| 57 |
-
|
| 58 |
-
## Bias, Risks, and Limitations
|
| 59 |
-
|
| 60 |
-
<!-- This section is meant to convey both technical and sociotechnical limitations. -->
|
| 61 |
-
|
| 62 |
-
[More Information Needed]
|
| 63 |
-
|
| 64 |
-
### Recommendations
|
| 65 |
-
|
| 66 |
-
<!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
|
| 67 |
-
|
| 68 |
-
Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
|
| 69 |
|
| 70 |
## How to Get Started with the Model
|
| 71 |
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
## Training Details
|
| 77 |
|
| 78 |
### Training Data
|
| 79 |
|
| 80 |
-
|
| 81 |
|
| 82 |
-
|
|
|
|
|
|
|
|
|
|
| 83 |
|
| 84 |
### Training Procedure
|
| 85 |
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
#### Preprocessing [optional]
|
| 89 |
-
|
| 90 |
-
[More Information Needed]
|
| 91 |
-
|
| 92 |
|
| 93 |
#### Training Hyperparameters
|
| 94 |
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
<!-- This section describes the evaluation protocols and provides the results. -->
|
| 106 |
-
|
| 107 |
-
### Testing Data, Factors & Metrics
|
| 108 |
-
|
| 109 |
-
#### Testing Data
|
| 110 |
-
|
| 111 |
-
<!-- This should link to a Dataset Card if possible. -->
|
| 112 |
-
|
| 113 |
-
[More Information Needed]
|
| 114 |
|
| 115 |
-
####
|
| 116 |
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
#### Metrics
|
| 122 |
-
|
| 123 |
-
<!-- These are the evaluation metrics being used, ideally with a description of why. -->
|
| 124 |
-
|
| 125 |
-
[More Information Needed]
|
| 126 |
-
|
| 127 |
-
### Results
|
| 128 |
-
|
| 129 |
-
[More Information Needed]
|
| 130 |
-
|
| 131 |
-
#### Summary
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
## Model Examination [optional]
|
| 136 |
-
|
| 137 |
-
<!-- Relevant interpretability work for the model goes here -->
|
| 138 |
-
|
| 139 |
-
[More Information Needed]
|
| 140 |
-
|
| 141 |
-
## Environmental Impact
|
| 142 |
-
|
| 143 |
-
<!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
|
| 144 |
-
|
| 145 |
-
Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
|
| 146 |
-
|
| 147 |
-
- **Hardware Type:** [More Information Needed]
|
| 148 |
-
- **Hours used:** [More Information Needed]
|
| 149 |
-
- **Cloud Provider:** [More Information Needed]
|
| 150 |
-
- **Compute Region:** [More Information Needed]
|
| 151 |
-
- **Carbon Emitted:** [More Information Needed]
|
| 152 |
-
|
| 153 |
-
## Technical Specifications [optional]
|
| 154 |
-
|
| 155 |
-
### Model Architecture and Objective
|
| 156 |
-
|
| 157 |
-
[More Information Needed]
|
| 158 |
|
| 159 |
### Compute Infrastructure
|
| 160 |
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
[More Information Needed]
|
| 166 |
-
|
| 167 |
-
#### Software
|
| 168 |
-
|
| 169 |
-
[More Information Needed]
|
| 170 |
-
|
| 171 |
-
## Citation [optional]
|
| 172 |
-
|
| 173 |
-
<!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
|
| 174 |
-
|
| 175 |
-
**BibTeX:**
|
| 176 |
-
|
| 177 |
-
[More Information Needed]
|
| 178 |
-
|
| 179 |
-
**APA:**
|
| 180 |
-
|
| 181 |
-
[More Information Needed]
|
| 182 |
-
|
| 183 |
-
## Glossary [optional]
|
| 184 |
-
|
| 185 |
-
<!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
|
| 186 |
-
|
| 187 |
-
[More Information Needed]
|
| 188 |
-
|
| 189 |
-
## More Information [optional]
|
| 190 |
-
|
| 191 |
-
[More Information Needed]
|
| 192 |
-
|
| 193 |
-
## Model Card Authors [optional]
|
| 194 |
|
| 195 |
-
|
| 196 |
|
| 197 |
-
## Model Card Contact
|
| 198 |
|
| 199 |
-
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
base_model: meta-llama/Llama-3.2-1B-Instruct
|
| 4 |
+
tags:
|
| 5 |
+
- dpo
|
| 6 |
+
- lora
|
| 7 |
+
- peft
|
| 8 |
+
- llama-3.2
|
| 9 |
+
- pairrm
|
| 10 |
+
library_name: peft
|
| 11 |
---
|
| 12 |
|
| 13 |
+
# DPO Fine-Tune of Llama-3.2-1B using PairRM Preferences
|
| 14 |
|
| 15 |
+
This repository contains the LoRA adapters for a `meta-llama/Llama-3.2-1B-Instruct` model that has been fine-tuned using Direct Preference Optimization (DPO).
|
| 16 |
|
| 17 |
+
The preference dataset for this training was generated using the `llm-blender/PairRM` reward model, which is designed to rank LLM responses based on quality. This model represents an efficient approach to preference alignment without the need for a separate LLM Judge or human annotation.
|
| 18 |
|
| 19 |
+
- **Preference Dataset:** [NilayR/pairrm-preferences-llama32](https://huggingface.co/datasets/NilayR/pairrm-preferences-llama32)
|
| 20 |
|
| 21 |
## Model Details
|
| 22 |
|
| 23 |
### Model Description
|
| 24 |
|
| 25 |
+
This model is a fine-tuned version of `meta-llama/Llama-3.2-1B-Instruct`. It was trained using DPO on a preference dataset where the 'chosen' and 'rejected' labels were determined by the `llm-blender/PairRM` model. The goal was to align the base model's outputs with PairRM's learned preferences for high-quality, factual, and concise responses.
|
| 26 |
|
| 27 |
+
- **Developed by:** NilayR
|
| 28 |
+
- **Model type:** Causal Language Model
|
| 29 |
+
- **Language(s):** English
|
| 30 |
+
- **License:** apache-2.0
|
| 31 |
+
- **Finetuned from model:** `meta-llama/Llama-3.2-1B-Instruct`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
## How to Get Started with the Model
|
| 34 |
|
| 35 |
+
To use these LoRA adapters, load the base model (`meta-llama/Llama-3.2-1B-Instruct`) and then apply the adapters from this repository.
|
| 36 |
+
|
| 37 |
+
```python
|
| 38 |
+
import torch
|
| 39 |
+
from peft import PeftModel
|
| 40 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
|
| 41 |
+
|
| 42 |
+
# Set base model ID and adapter path
|
| 43 |
+
base_model_id = "meta-llama/Llama-3.2-1B-Instruct"
|
| 44 |
+
adapter_id = "NilayR/llama32-dpo-pairrm"
|
| 45 |
+
|
| 46 |
+
# Configure BitsAndBytes for 4-bit quantization
|
| 47 |
+
bnb_config = BitsAndBytesConfig(
|
| 48 |
+
load_in_4bit=True,
|
| 49 |
+
bnb_4bit_quant_type="nf4",
|
| 50 |
+
bnb_4bit_compute_dtype=torch.bfloat16
|
| 51 |
+
)
|
| 52 |
+
|
| 53 |
+
# Load the base model with quantization
|
| 54 |
+
base_model = AutoModelForCausalLM.from_pretrained(
|
| 55 |
+
base_model_id,
|
| 56 |
+
quantization_config=bnb_config,
|
| 57 |
+
device_map="auto",
|
| 58 |
+
trust_remote_code=True,
|
| 59 |
+
)
|
| 60 |
+
|
| 61 |
+
# Load the tokenizer
|
| 62 |
+
tokenizer = AutoTokenizer.from_pretrained(base_model_id)
|
| 63 |
+
tokenizer.pad_token = tokenizer.eos_token
|
| 64 |
+
|
| 65 |
+
# Load and apply the PEFT adapters
|
| 66 |
+
model = PeftModel.from_pretrained(base_model, adapter_id)
|
| 67 |
+
|
| 68 |
+
# --- Generate a response ---
|
| 69 |
+
prompt = "What are the main differences between renewable and non-renewable energy?"
|
| 70 |
+
messages = [
|
| 71 |
+
{"role": "system", "content": "You are a helpful assistant."},
|
| 72 |
+
{"role": "user", "content": prompt}
|
| 73 |
+
]
|
| 74 |
+
|
| 75 |
+
input_ids = tokenizer.apply_chat_template(
|
| 76 |
+
messages,
|
| 77 |
+
add_generation_prompt=True,
|
| 78 |
+
return_tensors="pt"
|
| 79 |
+
).to(model.device)
|
| 80 |
+
|
| 81 |
+
outputs = model.generate(
|
| 82 |
+
input_ids,
|
| 83 |
+
max_new_tokens=200,
|
| 84 |
+
do_sample=True,
|
| 85 |
+
temperature=0.7,
|
| 86 |
+
top_p=0.95
|
| 87 |
+
)
|
| 88 |
+
|
| 89 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 90 |
+
print(response.split("assistant")[-1].strip())
|
| 91 |
+
|
| 92 |
+
```
|
| 93 |
## Training Details
|
| 94 |
|
| 95 |
### Training Data
|
| 96 |
|
| 97 |
+
The model was trained on a preference dataset generated using the `llm-blender/PairRM` model.
|
| 98 |
|
| 99 |
+
* **Data Generation Process:**
|
| 100 |
+
1. **Instructions:** 50 instructions were extracted from the LIMA dataset.
|
| 101 |
+
2. **Response Generation:** The base `Llama-3.2-1B` model generated 5 diverse responses for each instruction.
|
| 102 |
+
3. **Preference Labeling:** The `llm-blender/PairRM` ranker scored all 5 responses for each instruction. The highest-ranked response was selected as 'chosen' and the lowest-ranked as 'rejected', resulting in **50 preference pairs**.
|
| 103 |
|
| 104 |
### Training Procedure
|
| 105 |
|
| 106 |
+
The model was trained for one epoch using the TRL library's `DPOTrainer`.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
|
| 108 |
#### Training Hyperparameters
|
| 109 |
|
| 110 |
+
* **Framework:** `trl.DPOTrainer`
|
| 111 |
+
* **Epochs:** 1
|
| 112 |
+
* **Batch Size:** 1
|
| 113 |
+
* **Gradient Accumulation Steps:** 4 (Effective Batch Size: 4)
|
| 114 |
+
* **Optimizer:** `paged_adamw_8bit`
|
| 115 |
+
* **Learning Rate:** 5e-5
|
| 116 |
+
* **LR Scheduler:** `cosine` with a warmup ratio of 0.1
|
| 117 |
+
* **DPO Beta (β):** 0.1
|
| 118 |
+
* **Final Training Loss:** `0.6872`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
|
| 120 |
+
#### LoRA Configuration
|
| 121 |
|
| 122 |
+
* **Rank (`r`):** 16
|
| 123 |
+
* **Alpha (`lora_alpha`):** 32
|
| 124 |
+
* **Target Modules:** `q_proj`, `k_proj`, `v_proj`, `o_proj`, `gate_proj`, `up_proj`, `down_proj`
|
| 125 |
+
* **Dropout:** 0.05
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
|
| 127 |
### Compute Infrastructure
|
| 128 |
|
| 129 |
+
* **Hardware:** 1x NVIDIA A100 40GB GPU
|
| 130 |
+
* **Cloud Provider:** Google Colab
|
| 131 |
+
* **Software:** `transformers`, `peft`, `trl`, `bitsandbytes`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 132 |
|
| 133 |
+
-----
|
| 134 |
|
|
|
|
| 135 |
|
| 136 |
+
```
|
| 137 |
+
```
|