Update README.md
Browse files
README.md
CHANGED
@@ -1,199 +1,139 @@
|
|
1 |
---
|
2 |
-
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
---
|
5 |
|
6 |
-
#
|
7 |
|
8 |
-
|
9 |
|
|
|
10 |
|
|
|
11 |
|
12 |
## Model Details
|
13 |
|
14 |
### Model Description
|
15 |
|
16 |
-
|
17 |
|
18 |
-
|
19 |
|
20 |
-
- **Developed by:**
|
21 |
-
- **
|
22 |
-
- **
|
23 |
-
- **
|
24 |
-
- **
|
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 |
-
#### Factors
|
116 |
|
117 |
-
|
118 |
|
119 |
-
|
120 |
-
|
121 |
-
|
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 |
+
- iterative-dpo
|
10 |
+
- self-rewarding
|
11 |
+
library_name: peft
|
12 |
---
|
13 |
|
14 |
+
# Iterative DPO Fine-Tune of Llama-3.2-1B (Iteration 2)
|
15 |
|
16 |
+
This repository contains the LoRA adapters from the **second and final iteration** of a Direct Preference Optimization (DPO) fine-tuning process on the `meta-llama/Llama-3.2-1B-Instruct` model.
|
17 |
|
18 |
+
This model represents a further refinement of the Iteration 1 model, demonstrating a self-improvement loop where the model learns from preferences on its own generated outputs. This work was inspired by the "Self-Rewarding Language Models" paper.
|
19 |
|
20 |
+
- **Repository for Iteration 1:** [NilayR/llama32-iterative-dpo-iter1](https://huggingface.co/NilayR/llama32-iterative-dpo-iter1)
|
21 |
|
22 |
## Model Details
|
23 |
|
24 |
### Model Description
|
25 |
|
26 |
+
This model is the result of the second fine-tuning cycle in an iterative DPO pipeline. The process began with the model from Iteration 1 generating a new set of responses. These responses were then evaluated by an LLM Judge (GPT-3.5-Turbo) to create a fresh preference dataset. This new dataset was used to further fine-tune the model, resulting in the adapters contained in this repository.
|
27 |
|
28 |
+
The goal of this iteration was to demonstrate that the model could continue to improve its alignment with desired behaviors (accuracy, helpfulness, clarity) using its own outputs as a foundation for learning.
|
29 |
|
30 |
+
- **Developed by:** NilayR
|
31 |
+
- **Model type:** Causal Language Model
|
32 |
+
- **Language(s):** English
|
33 |
+
- **License:** apache-2.0
|
34 |
+
- **Finetuned from model:** `meta-llama/Llama-3.2-1B-Instruct` (with adapters from Iteration 1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
## How to Get Started with the Model
|
37 |
|
38 |
+
To use these LoRA adapters, load the base model (`meta-llama/Llama-3.2-1B-Instruct`) and then apply the adapters from this repository.
|
39 |
+
|
40 |
+
```python
|
41 |
+
import torch
|
42 |
+
from peft import PeftModel
|
43 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
|
44 |
+
|
45 |
+
# Set base model ID and adapter path
|
46 |
+
base_model_id = "meta-llama/Llama-3.2-1B-Instruct"
|
47 |
+
adapter_id = "NilayR/llama32-iterative-dpo-iter2"
|
48 |
+
|
49 |
+
# Configure BitsAndBytes for 4-bit quantization
|
50 |
+
bnb_config = BitsAndBytesConfig(
|
51 |
+
load_in_4bit=True,
|
52 |
+
bnb_4bit_quant_type="nf4",
|
53 |
+
bnb_4bit_compute_dtype=torch.bfloat16
|
54 |
+
)
|
55 |
+
|
56 |
+
# Load the base model with quantization
|
57 |
+
base_model = AutoModelForCausalLM.from_pretrained(
|
58 |
+
base_model_id,
|
59 |
+
quantization_config=bnb_config,
|
60 |
+
device_map="auto",
|
61 |
+
trust_remote_code=True,
|
62 |
+
)
|
63 |
+
|
64 |
+
# Load the tokenizer
|
65 |
+
tokenizer = AutoTokenizer.from_pretrained(base_model_id)
|
66 |
+
tokenizer.pad_token = tokenizer.eos_token
|
67 |
+
|
68 |
+
# Load and apply the PEFT adapters
|
69 |
+
model = PeftModel.from_pretrained(base_model, adapter_id)
|
70 |
+
|
71 |
+
# --- Generate a response ---
|
72 |
+
prompt = "What are the key benefits of meditation?"
|
73 |
+
messages = [
|
74 |
+
{"role": "system", "content": "You are a helpful assistant."},
|
75 |
+
{"role": "user", "content": prompt}
|
76 |
+
]
|
77 |
+
|
78 |
+
input_ids = tokenizer.apply_chat_template(
|
79 |
+
messages,
|
80 |
+
add_generation_prompt=True,
|
81 |
+
return_tensors="pt"
|
82 |
+
).to(model.device)
|
83 |
+
|
84 |
+
outputs = model.generate(
|
85 |
+
input_ids,
|
86 |
+
max_new_tokens=200,
|
87 |
+
do_sample=True,
|
88 |
+
temperature=0.7,
|
89 |
+
top_p=0.95
|
90 |
+
)
|
91 |
+
|
92 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
93 |
+
print(response.split("assistant")[-1].strip())
|
94 |
+
```
|
95 |
|
96 |
## Training Details
|
97 |
|
98 |
### Training Data
|
99 |
|
100 |
+
The model was trained on a preference dataset generated by the **Iteration 1 model** (`NilayR/llama32-iterative-dpo-iter1`).
|
101 |
|
102 |
+
* **Data Generation Process:**
|
103 |
+
1. **Instructions:** The model from Iteration 1 generated responses to 20 instructions from the LIMA dataset.
|
104 |
+
2. **Preference Labeling:** A custom LLM Judge powered by `GPT-3.5-Turbo` evaluated pairs of the new responses, creating a dataset of **57 chosen/rejected pairs**.
|
105 |
|
106 |
### Training Procedure
|
107 |
|
108 |
+
The model was trained for one epoch using the TRL library's `DPOTrainer`.
|
|
|
|
|
|
|
|
|
|
|
109 |
|
110 |
#### Training Hyperparameters
|
111 |
|
112 |
+
* **Framework:** `trl.DPOTrainer`
|
113 |
+
* **Epochs:** 1
|
114 |
+
* **Batch Size:** 1
|
115 |
+
* **Gradient Accumulation Steps:** 2 (Effective Batch Size: 2)
|
116 |
+
* **Optimizer:** `paged_adamw_8bit`
|
117 |
+
* **Learning Rate:** 2e-5
|
118 |
+
* **DPO Beta (β):** 0.1
|
119 |
+
* **Max Steps:** 50
|
120 |
+
* **Final Training Loss:** `0.6343`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
121 |
|
122 |
+
#### LoRA Configuration
|
123 |
|
124 |
+
* **Rank (`r`):** 16
|
125 |
+
* **Alpha (`lora_alpha`):** 32
|
126 |
+
* **Target Modules:** `q_proj`, `k_proj`, `v_proj`, `o_proj`
|
127 |
+
* **Dropout:** 0.05
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
128 |
|
129 |
### Compute Infrastructure
|
130 |
|
131 |
+
* **Hardware:** 1x NVIDIA A100 40GB GPU
|
132 |
+
* **Cloud Provider:** Google Colab
|
133 |
+
* **Software:** `transformers`, `peft`, `trl`, `bitsandbytes`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
134 |
|
135 |
+
-----
|
136 |
|
|
|
137 |
|
138 |
+
```
|
139 |
+
```
|