Safetensors
English
llama
alignment-handbook
trl
dpo
Generated from Trainer
File size: 8,969 Bytes
d8eec6f
 
88d17cd
d8eec6f
f98f101
d8eec6f
 
 
f98f101
 
 
 
 
d8eec6f
88d17cd
d8eec6f
88d17cd
 
d8eec6f
 
88d17cd
 
d8eec6f
30e6682
d8eec6f
88d17cd
d8eec6f
88d17cd
d8eec6f
88d17cd
d8eec6f
88d17cd
d8eec6f
88d17cd
d8eec6f
88d17cd
d8eec6f
88d17cd
 
 
 
d8eec6f
88d17cd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9ebe5f7
 
 
 
88d17cd
 
 
 
 
 
d8eec6f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88d17cd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
---
license: llama3.1
base_model: Magpie-Align/Llama-3.1-8B-Magpie-Align-SFT-v0.2
tags:
- alignment-handbook
- trl
- dpo
- generated_from_trainer
- trl
- dpo
- generated_from_trainer
datasets:
- Magpie-Align/Llama-3.1-70B-PO-100K-armorm
model-index:
- name: Llama-3.1-8B-Magpie-Align-v0.2
  results: []
language:
- en
---

![Magpie](https://cdn-uploads.huggingface.co/production/uploads/653df1323479e9ebbe3eb6cc/FWWILXrAGNwWr52aghV0S.png)
## πŸ”₯ Chat with Magpie [Here](https://huggingface.co/spaces/flydust/Chat-with-Magpie)!

# 🐦 Llama-3.1-8B-Magpie-Align-v0.2

Project Web: [https://magpie-align.github.io/](https://magpie-align.github.io/)

Online Model Demo: [https://huggingface.co/spaces/flydust/Chat-with-Magpie](https://huggingface.co/spaces/flydust/Chat-with-Magpie)

Arxiv Technical Report: [https://arxiv.org/abs/2406.08464](https://arxiv.org/abs/2406.08464)

Codes: [https://github.com/magpie-align/magpie](https://github.com/magpie-align/magpie)

## 🧐 About This Model

This model is an aligned version of [meta-llama/Meta-Llama-3.1-8B](https://huggingface.co/meta-llama/Meta-Llama-3.1-8B). We apply the following pipeline:

We first perform SFT using:
* [Magpie-Align/Magpie-Llama-3.1-Pro-500K-Filtered](https://huggingface.co/datasets/Magpie-Align/Magpie-Llama-3.1-Pro-500K-Filtered)
* [Magpie-Align/Magpie-Reasoning-150K](https://huggingface.co/datasets/Magpie-Align/Magpie-Reasoning-150K)
* **SFT Model Checkpoint:** [Magpie-Align/Llama-3.1-8B-Magpie-Align-SFT-v0.2](https://huggingface.co/Magpie-Align/Llama-3.1-8B-Magpie-Align-SFT-v0.2)

We then perform DPO on the [Magpie-Align/Llama-3.1-70B-PO-100K-armorm](https://huggingface.co/datasets/Magpie-Align/Llama-3.1-70B-PO-100K-armorm) dataset.

The overall performance is much better than the official Llama-3.1-8B-Instruct Model! 

- **Alpaca Eval 2 (vs GPT-4-Turbo-1106): 46.68 (LC), 53.42 (WR)**
- **Arena Hard: 43.2**


## πŸ‘€ Other Information

**License**: Please follow [Meta Llama 3.1 Community License](https://github.com/meta-llama/llama-models/blob/main/models/llama3_1/LICENSE).

**Conversation Template**: Please use Llama 3 **official chat template** for the best performance.

**How to use it?** Please check the official [Llama 3.1 repository](https://huggingface.co/meta-llama/Meta-Llama-3.1-8B-Instruct#how-to-use) for detailed instructions. Simply replace the original `model_id` with this model id.

---
# Alignment Pipeline

The detailed alignment pipeline is as follows.

## Stage 1: Supervised Fine-tuning

We use [Axolotl](https://github.com/OpenAccess-AI-Collective/axolotl) for SFT. Please refer to the model card of [SFT checkpoint](https://huggingface.co/Magpie-Align/Llama-3.1-8B-Magpie-Align-SFT-v0.2) for detailed configurations.

## Stage 2: Direct Preference Optimization

### Training hyperparameters

The following hyperparameters were used during training:
- learning_rate: 5e-07
- train_batch_size: 2
- eval_batch_size: 4
- seed: 42
- distributed_type: multi-GPU
- num_devices: 4
- gradient_accumulation_steps: 16
- total_train_batch_size: 128
- total_eval_batch_size: 16
- optimizer: Adam with betas=(0.9,0.999) and epsilon=1e-08
- lr_scheduler_type: cosine
- lr_scheduler_warmup_ratio: 0.1
- num_epochs: 1

### Training results

| Training Loss | Epoch  | Step | Validation Loss | Rewards/chosen | Rewards/rejected | Rewards/accuracies | Rewards/margins | Logps/rejected | Logps/chosen | Logits/rejected | Logits/chosen |
|:-------------:|:------:|:----:|:---------------:|:--------------:|:----------------:|:------------------:|:---------------:|:--------------:|:------------:|:---------------:|:-------------:|
| 0.5603        | 0.1306 | 100  | 0.5762          | -1.0828        | -1.5526          | 0.7620             | 0.4698          | -505.3885      | -452.3145    | -0.7241         | -0.7285       |
| 0.5441        | 0.2612 | 200  | 0.4445          | -3.4116        | -5.1002          | 0.8360             | 1.6886          | -860.1481      | -685.1905    | -0.6966         | -0.6964       |
| 0.3586        | 0.3919 | 300  | 0.3949          | -3.4100        | -5.2798          | 0.8720             | 1.8698          | -878.1118      | -685.0309    | -0.7677         | -0.7653       |
| 0.3737        | 0.5225 | 400  | 0.3653          | -4.3580        | -6.6737          | 0.8760             | 2.3157          | -1017.5        | -779.8291    | -0.7777         | -0.7711       |
| 0.2611        | 0.6531 | 500  | 0.3457          | -4.9017        | -7.6712          | 0.8860             | 2.7695          | -1117.2515     | -834.2015    | -0.8137         | -0.8074       |
| 0.3342        | 0.7837 | 600  | 0.3354          | -4.7041        | -7.3342          | 0.8920             | 2.6301          | -1083.5503     | -814.4402    | -0.8081         | -0.7999       |
| 0.3251        | 0.9144 | 700  | 0.3335          | -4.8366        | -7.5394          | 0.8880             | 2.7028          | -1104.0730     | -827.6954    | -0.8119         | -0.8042       |

### Framework versions

- Transformers 4.43.3
- Pytorch 2.4.0+cu121
- Datasets 2.20.0
- Tokenizers 0.19.1

<details><summary>See alignment handbook config</summary>

```yaml
# Customized Configs
model_name_or_path: Magpie-Align/Llama-3.1-8B-Magpie-Align-SFT-v0.2
hub_model_id: Magpie-Align/Llama-3.1-8B-Magpie-Align-v0.2
output_dir: /data/zhangchen_xu/alignment_handbook_out/Llama-3.1-8B-Magpie-Align-v0.2
run_name: Llama-3.1-8B-Magpie-Align-v0.2

dataset_mixer:
  Magpie-Align/Llama-3.1-70B-PO-100K-armorm: 1.0
dataset_splits:
- train
- test
preprocessing_num_workers: 64

# DPOTrainer arguments
bf16: true
beta: 0.01
learning_rate: 0.5e-6
gradient_accumulation_steps: 16
per_device_train_batch_size: 2
per_device_eval_batch_size: 4
num_train_epochs: 1
max_length: 2048
max_prompt_length: 1800
warmup_ratio: 0.1
logging_steps: 1
lr_scheduler_type: cosine
optim: adamw_torch

torch_dtype: null
use_flash_attention_2: true
do_eval: true
evaluation_strategy: steps
eval_steps: 100
gradient_checkpointing: true
gradient_checkpointing_kwargs:
  use_reentrant: False
log_level: info
push_to_hub: true
save_strategy: "steps"
save_steps: 100
save_total_limit: 1
seed: 42
report_to:
- wandb
```
</details><be>

## Paper Abstract

<details><summary>Click Here</summary>
High-quality instruction data is critical for aligning large language models (LLMs). Although some models, such as Llama-3-Instruct, have open weights, their alignment data remain private, which hinders the democratization of AI. High human labor costs and a limited, predefined scope for prompting prevent existing open-source data creation methods from scaling effectively, potentially limiting the diversity and quality of public alignment datasets. Is it possible to synthesize high-quality instruction data at scale by extracting it directly from an aligned LLM? We present a self-synthesis method for generating large-scale alignment data named Magpie. Our key observation is that aligned LLMs like Llama-3-Instruct can generate a user query when we input only the left-side templates up to the position reserved for user messages, thanks to their auto-regressive nature. We use this method to prompt Llama-3-Instruct and generate 4 million instructions along with their corresponding responses. We perform a comprehensive analysis of the extracted data and select 300K high-quality instances. To compare Magpie data with other public instruction datasets, we fine-tune Llama-3-8B-Base with each dataset and evaluate the performance of the fine-tuned models. Our results indicate that in some tasks, models fine-tuned with Magpie perform comparably to the official Llama-3-8B-Instruct, despite the latter being enhanced with 10 million data points through supervised fine-tuning (SFT) and subsequent feedback learning. We also show that using Magpie solely for SFT can surpass the performance of previous public datasets utilized for both SFT and preference optimization, such as direct preference optimization with UltraFeedback. This advantage is evident on alignment benchmarks such as AlpacaEval, ArenaHard, and WildBench.
</details><be>

## πŸ“š Citation

If you find the model, data, or code useful, please cite our paper:
```
@article{xu2024magpie,
	title={Magpie: Alignment Data Synthesis from Scratch by Prompting Aligned LLMs with Nothing}, 
	author={Zhangchen Xu and Fengqing Jiang and Luyao Niu and Yuntian Deng and Radha Poovendran and Yejin Choi and Bill Yuchen Lin},
	year={2024},
	eprint={2406.08464},
	archivePrefix={arXiv},
	primaryClass={cs.CL}
}
```

Please also cite the reward model for creating preference datasets:

ArmoRM paper:
```
@article{wang2024interpretable,
  title={Interpretable Preferences via Multi-Objective Reward Modeling and Mixture-of-Experts},
  author={Wang, Haoxiang and Xiong, Wei and Xie, Tengyang and Zhao, Han and Zhang, Tong},
  journal={arXiv preprint arXiv:2406.12845},
  year={2024}
}
```

**Questions?** Please contact [Zhangchen](https://zhangchenxu.com/) by email.