john6ygu88 GGLS commited on
Commit
63e4a56
·
0 Parent(s):

Duplicate from FuseAI/FuseChat-7B-VaRM

Browse files

Co-authored-by: Longguang Zhong <GGLS@users.noreply.huggingface.co>

.gitattributes ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tar filter=lfs diff=lfs merge=lfs -text
29
+ *.tflite filter=lfs diff=lfs merge=lfs -text
30
+ *.tgz filter=lfs diff=lfs merge=lfs -text
31
+ *.wasm filter=lfs diff=lfs merge=lfs -text
32
+ *.xz filter=lfs diff=lfs merge=lfs -text
33
+ *.zip filter=lfs diff=lfs merge=lfs -text
34
+ *.zst filter=lfs diff=lfs merge=lfs -text
35
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ assets/tab_1.png filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,545 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ language:
4
+ - en
5
+ base_model: openchat/openchat_3.5
6
+ datasets:
7
+ - FuseAI/FuseChat-Mixture
8
+ pipeline_tag: text-generation
9
+ tags:
10
+ - mistral
11
+ - mixtral
12
+ - solar
13
+ - model-fusion
14
+ - fusechat
15
+ library_name: transformers
16
+ model-index:
17
+ - name: FuseChat-7B-VaRM
18
+ results:
19
+ - task:
20
+ type: text-generation
21
+ name: Text Generation
22
+ dataset:
23
+ name: MT-Bench
24
+ type: unknown
25
+ metrics:
26
+ - type: unknown
27
+ value: 8.22
28
+ name: score
29
+ source:
30
+ url: https://huggingface.co/spaces/lmsys/mt-bench
31
+ - task:
32
+ type: text-generation
33
+ name: Text Generation
34
+ dataset:
35
+ name: AI2 Reasoning Challenge (25-Shot)
36
+ type: ai2_arc
37
+ config: ARC-Challenge
38
+ split: test
39
+ args:
40
+ num_few_shot: 25
41
+ metrics:
42
+ - type: acc_norm
43
+ value: 62.88
44
+ name: normalized accuracy
45
+ source:
46
+ url: https://huggingface.co/spaces/HuggingFaceH4/open_llm_leaderboard?query=FuseAI/FuseChat-7B-VaRM
47
+ name: Open LLM Leaderboard
48
+ - task:
49
+ type: text-generation
50
+ name: Text Generation
51
+ dataset:
52
+ name: HellaSwag (10-Shot)
53
+ type: hellaswag
54
+ split: validation
55
+ args:
56
+ num_few_shot: 10
57
+ metrics:
58
+ - type: acc_norm
59
+ value: 84.25
60
+ name: normalized accuracy
61
+ source:
62
+ url: https://huggingface.co/spaces/HuggingFaceH4/open_llm_leaderboard?query=FuseAI/FuseChat-7B-VaRM
63
+ name: Open LLM Leaderboard
64
+ - task:
65
+ type: text-generation
66
+ name: Text Generation
67
+ dataset:
68
+ name: MMLU (5-Shot)
69
+ type: cais/mmlu
70
+ config: all
71
+ split: test
72
+ args:
73
+ num_few_shot: 5
74
+ metrics:
75
+ - type: acc
76
+ value: 63.71
77
+ name: accuracy
78
+ source:
79
+ url: https://huggingface.co/spaces/HuggingFaceH4/open_llm_leaderboard?query=FuseAI/FuseChat-7B-VaRM
80
+ name: Open LLM Leaderboard
81
+ - task:
82
+ type: text-generation
83
+ name: Text Generation
84
+ dataset:
85
+ name: TruthfulQA (0-shot)
86
+ type: truthful_qa
87
+ config: multiple_choice
88
+ split: validation
89
+ args:
90
+ num_few_shot: 0
91
+ metrics:
92
+ - type: mc2
93
+ value: 45.67
94
+ source:
95
+ url: https://huggingface.co/spaces/HuggingFaceH4/open_llm_leaderboard?query=FuseAI/FuseChat-7B-VaRM
96
+ name: Open LLM Leaderboard
97
+ - task:
98
+ type: text-generation
99
+ name: Text Generation
100
+ dataset:
101
+ name: Winogrande (5-shot)
102
+ type: winogrande
103
+ config: winogrande_xl
104
+ split: validation
105
+ args:
106
+ num_few_shot: 5
107
+ metrics:
108
+ - type: acc
109
+ value: 79.16
110
+ name: accuracy
111
+ source:
112
+ url: https://huggingface.co/spaces/HuggingFaceH4/open_llm_leaderboard?query=FuseAI/FuseChat-7B-VaRM
113
+ name: Open LLM Leaderboard
114
+ - task:
115
+ type: text-generation
116
+ name: Text Generation
117
+ dataset:
118
+ name: GSM8k (5-shot)
119
+ type: gsm8k
120
+ config: main
121
+ split: test
122
+ args:
123
+ num_few_shot: 5
124
+ metrics:
125
+ - type: acc
126
+ value: 63.46
127
+ name: accuracy
128
+ source:
129
+ url: https://huggingface.co/spaces/HuggingFaceH4/open_llm_leaderboard?query=FuseAI/FuseChat-7B-VaRM
130
+ name: Open LLM Leaderboard
131
+ ---
132
+ <p align="center" width="100%">
133
+ </p>
134
+
135
+ <div id="top" align="center">
136
+
137
+ <p style="font-size: 30px; font-weight: bold;">FuseChat: Knowledge Fusion of Chat Models</p>
138
+
139
+ <p style="font-size: 24px; font-weight: bold;">[SOTA 7B LLM on MT-Bench]</p>
140
+
141
+ <h4> |<a href="https://arxiv.org/abs/2402.16107"> 📑 Paper </a> |
142
+ <a href="https://huggingface.co/FuseAI"> 🤗 HuggingFace Repo </a> |
143
+ <a href="https://github.com/fanqiwan/FuseLLM"> 🐱 GitHub Repo </a> |
144
+ </h4>
145
+
146
+ <!-- **Authors:** -->
147
+
148
+ _**Fanqi Wan, Ziyi Yang, Longguang Zhong, Xiaojun Quan, Xinting Huang, Wei Bi**_
149
+
150
+
151
+ <!-- **Affiliations:** -->
152
+
153
+
154
+ _Sun Yat-sen University_
155
+
156
+ <p align="center">
157
+ <img src="./assets/fig_0.png" width="70%"> <br>
158
+ </p>
159
+
160
+ | Proprietary Models | #Params | MT-Bench | Open Source Models | #Params | MT-Bench |
161
+ |-----------------------------------------------------------------------|---------|----------|-----------------------------------------------------------------------|---------|----------|
162
+ | GPT-4-1106-preview | - | 9.32 | Qwen1.5-72B-Chat | 72B | 8.61 |
163
+ | GPT-4-0613 | - | 9.18 | Nous-Hermes-2-Mixtral-8x7B-DPO | 8x7B | 8.33 |
164
+ | GPT-4-0314 | - | 8.96 | Mixtral-8x7B-Instruct-v0.1 | 8x7B | 8.30 |
165
+ | Mistral Medium | - | 8.61 | 🤗 [FuseChat-7B-VaRM](https://huggingface.co/FuseAI/FuseChat-7B-VaRM) | 7B | 8.22 |
166
+ | GPT-3.5-Turbo-0613 | - | 8.39 | Starling-LM-7B-alpha | 7B | 8.09 |
167
+ | GPT-3.5-Turbo-1106 | - | 8.32 | Tulu-2-DPO-70B | 70B | 7.89 |
168
+ | 🤗 [FuseChat-7B-VaRM](https://huggingface.co/FuseAI/FuseChat-7B-VaRM) | 7B | 8.22 | OpenChat-3.5 | 7B | 7.81 |
169
+ | Claude-2.1 | - | 8.18 | OpenChat-3.5-0106 | 7B | 7.80 |
170
+ | Claude-2.0 | - | 8.06 | WizardLM-70B-v1.0 | 70B | 7.71 |
171
+ | GPT-3.5-Turbo-0314 | - | 7.94 | Yi-34B-Chat | 34B | 7.67 |
172
+ | Claude-1 | - | 7.90 | Nous-Hermes-2-SOLAR-10.7B | 10.7B | 7.66 |
173
+
174
+
175
+ </div>
176
+
177
+
178
+ ## News
179
+ - **Feb 26, 2024:** 🔥🔥 We release [FuseChat-7B-VaRM](https://huggingface.co/FuseAI/FuseChat-7B-VaRM), which is the fusion of three prominent chat LLMs with diverse architectures and scales, namely [NH2-Mixtral-8x7B](https://huggingface.co/NousResearch/Nous-Hermes-2-Mixtral-8x7B-DPO), [NH2-Solar-10.7B](https://huggingface.co/NousResearch/Nous-Hermes-2-SOLAR-10.7B), and [OpenChat-3.5-7B](https://huggingface.co/openchat/openchat_3.5). FuseChat-7B-VaRM achieves an average performance of **8.22** on MT-Bench, outperforming various powerful chat LLMs at 7B and 34B scales like [Starling-7B](https://huggingface.co/berkeley-nest/Starling-LM-7B-alpha) and [Yi-34B-Chat](https://huggingface.co/01-ai/Yi-34B-Chat), even surpassing [GPT-3.5 (March)](https://platform.openai.com/docs/models/gpt-3-5-turbo), [Claude-2.1](https://www.anthropic.com/news/claude-2-1), and approaching [Mixtral-8x7B-Instruct](https://huggingface.co/mistralai/Mixtral-8x7B-Instruct-v0.1).
180
+
181
+ - **Feb 25, 2024:** 🔥 We release [FuseChat-Mixture](https://huggingface.co/datasets/FuseAI/FuseChat-Mixture), which is a comprehensive training dataset covers different styles and capabilities, featuring both human-written and model-generated, and spanning general instruction-following and specific skills.
182
+
183
+ ## Contents
184
+
185
+ - [Overview](#overview)
186
+ - [Model Release](#model-release)
187
+ - [Quick Start](#quick-start)
188
+ - [Data Construction](#data-construction)
189
+ - [Pairwise Knowledge Fusion](#pairwise-knowledge-fusion)
190
+ - [Model Merging](#model-merging)
191
+ - [Evaluation](#evaluation)
192
+ - [Citation](#citation)
193
+
194
+ ## Overview
195
+
196
+ In this work, we propose an extended framework of FuseLLM to integrate the collective knowledge and individual strengths of multiple structure and scale-varied chat LLMs into a more powerful chat LLM, resulting in FuseChat. FuseChat adopts a fuse-then-merge strategy with two main stages. Firstly, it undertakes pairwise knowledge fusion for source LLMs to derive multiple target LLMs of identical structure and size via lightweight fine-tuning. Then, these target LLMs are merged within the parameter space, wherein we propose a novel method VaRM for determining the merging weights based on the variation ratio of parameter matrices before and after fine-tuning.
197
+
198
+
199
+ Moreover, we argue that the concept of knowledge fusion adopted by both FuseChat and FuseLLM shares a fundamentally similar purpose with other related topics, such as the recently popular topic of mixture of experts (MoEs), because they all aim to leverage the strengths of multiple models (experts). However, while MoEs require loading multiple experts during inference, which has higher memory requirements, knowledge fusion supports the integration of multiple LLMs with diverse architectures into a single LLM without any additional memory requirement, making it more memory-efficient.
200
+
201
+ <p align="center">
202
+ <img src="./assets/fig_1.png" width="95%"> <br>
203
+ </p>
204
+
205
+
206
+ ## Model Release
207
+
208
+ We release [FuseChat-7B-VaRM](https://huggingface.co/FuseAI/FuseChat-7B-VaRM), which is the fusion of three prominent chat LLMs with diverse architectures and scales, namely [NH2-Mixtral-8x7B](https://huggingface.co/NousResearch/Nous-Hermes-2-Mixtral-8x7B-DPO), [NH2-Solar-10.7B](https://huggingface.co/NousResearch/Nous-Hermes-2-SOLAR-10.7B), and [OpenChat-3.5-7B](https://huggingface.co/openchat/openchat_3.5). FuseChat-7B-VaRM achieves an average performance of **8.22** on MT-Bench, outperforming various powerful chat LLMs at 7B and 34B scales like [Starling-7B](https://huggingface.co/berkeley-nest/Starling-LM-7B-alpha) and [Yi-34B-Chat](https://huggingface.co/01-ai/Yi-34B-Chat), even surpassing [GPT-3.5 (March)](https://platform.openai.com/docs/models/gpt-3-5-turbo), [Claude-2.1](https://www.anthropic.com/news/claude-2-1), and approaching [Mixtral-8x7B-Instruct](https://huggingface.co/mistralai/Mixtral-8x7B-Instruct-v0.1).
209
+
210
+ To support a plug-and-play fusion of new source LLM, we release our target LLMs: [OpenChat-3.5-7B-Solar](https://huggingface.co/FuseAI/OpenChat-3.5-7B-Solar) and [OpenChat-3.5-7B-Mixtral](https://huggingface.co/FuseAI/OpenChat-3.5-7B-Mixtral), which are obtained from pair-wise knowledge fusion. Integrating a new source LLM at any scale requires only obtaining a target LLM from the new source LLM and merging it with the existing target LLMs.
211
+
212
+ We also release FuseChat with other merging methods: [FuseChat-7B-SLERP](https://huggingface.co/FuseAI/FuseChat-7B-SLERP) and [FuseChat-7B-TA](https://huggingface.co/FuseAI/FuseChat-7B-TA), which achieves an average performance of **8.19** and **8.20** on MT-Bench respectively.
213
+
214
+ Here are the evaluation results.
215
+
216
+ <p align="center">
217
+ <img src="./assets/tab_1.png" width="95%"> <br>
218
+ </p>
219
+
220
+ ## Quick Start
221
+
222
+ ### Setup
223
+
224
+ We use `python 3.11` in this project.
225
+
226
+ Then, we have to install all the libraries listed in `requirements.txt`.
227
+
228
+ ```bash
229
+ pip install -r requirements.txt
230
+ ```
231
+
232
+ ### Usage
233
+
234
+ Here's how you can run the model using the 🤗 Transformers:
235
+
236
+ ```python
237
+ import transformers
238
+ tokenizer = transformers.AutoTokenizer.from_pretrained("FuseAI/FuseChat-7B-VaRM")
239
+ # Single-turn
240
+ tokens = tokenizer("GPT4 Correct User: Hello<|end_of_turn|>GPT4 Correct Assistant:").input_ids
241
+ assert tokens == [1, 420, 6316, 28781, 3198, 3123, 1247, 28747, 22557, 32000, 420, 6316, 28781, 3198, 3123, 21631, 28747]
242
+ # Multi-turn
243
+ tokens = tokenizer("GPT4 Correct User: Hello<|end_of_turn|>GPT4 Correct Assistant: Hi<|end_of_turn|>GPT4 Correct User: How are you today?<|end_of_turn|>GPT4 Correct Assistant:").input_ids
244
+ assert tokens == [1, 420, 6316, 28781, 3198, 3123, 1247, 28747, 22557, 32000, 420, 6316, 28781, 3198, 3123, 21631, 28747, 15359, 32000, 420, 6316, 28781, 3198, 3123, 1247, 28747, 1602, 460, 368, 3154, 28804, 32000, 420, 6316, 28781, 3198, 3123, 21631, 28747]
245
+ ```
246
+
247
+ The GPT4 template is also available as the integrated `tokenizer.chat_template`, which can be used instead of manually specifying the template:
248
+
249
+ ```python
250
+ messages = [
251
+ {"role": "user", "content": "Hello"},
252
+ {"role": "assistant", "content": "Hi"},
253
+ {"role": "user", "content": "How are you today?"}
254
+ ]
255
+ tokens = tokenizer.apply_chat_template(messages, add_generation_prompt=True)
256
+ assert tokens == [1, 420, 6316, 28781, 3198, 3123, 1247, 28747, 22557, 32000, 420, 6316, 28781, 3198, 3123, 21631, 28747, 15359, 32000, 420, 6316, 28781, 3198, 3123, 1247, 28747, 1602, 460, 368, 3154, 28804, 32000, 420, 6316, 28781, 3198, 3123, 21631, 28747]
257
+ ```
258
+
259
+ ## Data Construction
260
+
261
+ We curated a comprehensive training dataset, [FuseChat-Mixture](https://huggingface.co/datasets/FuseAI/FuseChat-Mixture), from various sources. This dataset covers different styles and capabilities, featuring both human-written and model-generated, and spanning general instruction-following and specific skills.
262
+
263
+ Here we show the scripts to obtain representations from multiple source LLMs for model fusion.
264
+
265
+ 1. Get representations for each source LLM
266
+
267
+ ```bash
268
+ # We split the dataset into 4 splits, then process each split on one or multiple GPU.
269
+
270
+ # OpenChat-3.5-7B
271
+ export CUDA_VISIBLE_DEVICES=0
272
+ for i in {0..3}; do
273
+ python /train/get_data_representation.py \
274
+ --model_name_or_path "openchat/openchat_3.5" \
275
+ --data_path "/data/fusechat_v1_clean_split_2048_filter_wrong.json" \
276
+ --dataset_save_dir "<${i}_4_path_to_openchat_representation>" \
277
+ --tknz_dataset_path "<${i}_4_path_to_openchat_tknz>" \
278
+ --cache_dir "/.cache/huggingface/datasets" \
279
+ --model_max_length 2048 \
280
+ --load_in_half bf16 \
281
+ --batch_size 32 \
282
+ --top_k_logits 10 \
283
+ --save_per_token_metric \
284
+ --no_assert \
285
+ --conv_temp "openchat" \
286
+ --flash_attn_transformers \
287
+ --mask_instruction \
288
+ --dataset_split_num 4 \
289
+ --dataset_index ${i}
290
+ done
291
+
292
+ # NH2-Mixtral-8x7B
293
+ export CUDA_VISIBLE_DEVICES=0,1,2
294
+ for i in {0..3}; do
295
+ python /train/get_data_representation.py \
296
+ --model_name_or_path "NousResearch/Nous-Hermes-2-Mixtral-8x7B-DPO" \
297
+ --data_path "/data/fusechat_v1_clean_split_2048_filter_wrong.json" \
298
+ --dataset_save_dir "<${i}_4_path_to_mixtral_representation>" \
299
+ --tknz_dataset_path "<${i}_4_path_to_mixtral_tknz>" \
300
+ --cache_dir "/.cache/huggingface/datasets" \
301
+ --model_max_length 2048 \
302
+ --load_in_half bf16 \
303
+ --batch_size 4 \
304
+ --top_k_logits 10 \
305
+ --save_per_token_metric \
306
+ --no_assert \
307
+ --conv_temp "openchat" \
308
+ --flash_attn_transformers \
309
+ --mask_instruction \
310
+ --device_map "auto" \
311
+ --dataset_split_num 4 \
312
+ --dataset_index ${i}
313
+ done
314
+
315
+ # NH2-Solar-10.7B
316
+ export CUDA_VISIBLE_DEVICES=0
317
+ for i in {0..3}; do
318
+ python /train/get_data_representation.py \
319
+ --model_name_or_path "NousResearch/Nous-Hermes-2-SOLAR-10.7B" \
320
+ --data_path "/data/fusechat_v1_clean_split_2048_filter_wrong.json" \
321
+ --dataset_save_dir "<${i}_4_path_to_solar_representation>" \
322
+ --tknz_dataset_path "<${i}_4_path_to_solar_tknz>" \
323
+ --cache_dir "/.cache/huggingface/datasets" \
324
+ --model_max_length 2048 \
325
+ --load_in_half bf16 \
326
+ --batch_size 8 \
327
+ --top_k_logits 10 \
328
+ --save_per_token_metric \
329
+ --no_assert \
330
+ --conv_temp "openchat" \
331
+ --flash_attn_transformers \
332
+ --mask_instruction \
333
+ --dataset_split_num 4 \
334
+ --dataset_index ${i}
335
+ done
336
+ ```
337
+
338
+ 2. Align representations from different source LLMs
339
+
340
+ ```bash
341
+ # Since the tokenizers and vocabularies of these source LLMs are identical, we do not align.
342
+
343
+ # OpenChat-3.5-7B <-> NH2-Mixtral-8x7B
344
+ for i in {0..3}; do
345
+ python /train/replace_model.py \
346
+ --dataset_dir "<${i}_4_path_to_openchat_representation>" \
347
+ --replace_dataset_dir "<${i}_4_path_to_mixtral_representation>" \
348
+ --dataset_save_dir "<${i}_4_path_to_openchat_mixtral_representation>" \
349
+ --preprocessing_num_workers 64 \
350
+ --batch_size 1000 \
351
+ --replace_model model_0
352
+ done
353
+
354
+ # OpenChat-3.5-7B <-> NH2-Solar-10.7B
355
+ for i in {0..3}; do
356
+ python /train/replace_model.py \
357
+ --dataset_dir "<${i}_4_path_to_openchat_mixtral_representation>" \
358
+ --replace_dataset_dir "<${i}_4_path_to_solar_representation>" \
359
+ --dataset_save_dir "<${i}_4_path_to_openchat_mixtral_solar_representation>" \
360
+ --preprocessing_num_workers 64 \
361
+ --batch_size 1000 \
362
+ --replace_model model_1
363
+ done
364
+ ```
365
+
366
+ 3. Filter instances with NaN loss in the dataset
367
+
368
+ ```bash
369
+ for i in {0..3}; do
370
+ python /train/filter_nan.py \
371
+ --input_data_dir "<${i}_4_path_to_openchat_mixtral_solar_representation>" \
372
+ --output_data_dir "<${i}_4_path_to_openchat_mixtral_solar_representation_fnan>"
373
+ done
374
+ ```
375
+
376
+ The final processed data is at `<${i}_4_path_to_openchat_mixtral_solar_representation_fnan>`.
377
+
378
+ ## Pairwise Knowledge Fusion
379
+
380
+ We show the scripts for pairwise knowledge fusion.
381
+
382
+ ```bash
383
+ # OpenChat-3.5-7B <-> NH2-Mixtral-8x7B
384
+ export CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7
385
+ torchrun --nproc_per_node=8 --master_port=20001 /train/train.py \
386
+ --model_name_or_path "openchat/openchat_3.5" \
387
+ --data_path "<0_4_path_to_openchat_mixtral_solar_representation_fnan>,<1_4_path_to_openchat_mixtral_solar_representation_fnan>,<2_4_path_to_openchat_mixtral_solar_representation_fnan>,<3_4_path_to_openchat_mixtral_solar_representation_fnan>" \
388
+ --bf16 True \
389
+ --output_dir "<path_to_save_openchat_mixtral_ckpt>" \
390
+ --num_train_epochs 3 \
391
+ --per_device_train_batch_size 4 \
392
+ --per_device_eval_batch_size 4 \
393
+ --gradient_accumulation_steps 4 \
394
+ --evaluation_strategy "no" \
395
+ --save_strategy "epoch" \
396
+ --save_steps 10000 \
397
+ --save_total_limit 5 \
398
+ --learning_rate 5e-6 \
399
+ --weight_decay 0. \
400
+ --warmup_ratio 0.03 \
401
+ --lr_scheduler_type "cosine" \
402
+ --logging_steps 1 \
403
+ --fsdp "full_shard auto_wrap" \
404
+ --fsdp_transformer_layer_cls_to_wrap 'MistralDecoderLayer' \
405
+ --tf32 True \
406
+ --model_max_length 2048 \
407
+ --gradient_checkpointing True \
408
+ --conv_temp "openchat" \
409
+ --lazy_preprocess True \
410
+ --flash_attn_transformers True \
411
+ --do_train \
412
+ --do_distill \
413
+ --distill_with_ref_model True \
414
+ --distill_with_aligned_model_0 True \
415
+ --distill_with_aligned_model_1 False \
416
+ --distill_loss_type "ce" \
417
+ --distill_teacher_temperature 1.0 \
418
+ --lm_loss_weight 0.9 \
419
+ --distill_greater_as_gt True \
420
+ --distill_greater_as_gt_type hard \
421
+ --dataloader_num_workers 8 \
422
+ --remove_unused_columns False
423
+
424
+ # OpenChat-3.5-7B <-> NH2-Solar-10.7B
425
+ export CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7
426
+ torchrun --nproc_per_node=8 --master_port=20001 /train/train.py \
427
+ --model_name_or_path "openchat/openchat_3.5" \
428
+ --data_path "<0_4_path_to_openchat_mixtral_solar_representation_fnan>,<1_4_path_to_openchat_mixtral_solar_representation_fnan>,<2_4_path_to_openchat_mixtral_solar_representation_fnan>,<3_4_path_to_openchat_mixtral_solar_representation_fnan>" \
429
+ --bf16 True \
430
+ --output_dir "<path_to_save_openchat_solar_ckpt>" \
431
+ --num_train_epochs 3 \
432
+ --per_device_train_batch_size 4 \
433
+ --per_device_eval_batch_size 4 \
434
+ --gradient_accumulation_steps 4 \
435
+ --evaluation_strategy "no" \
436
+ --save_strategy "epoch" \
437
+ --save_steps 10000 \
438
+ --save_total_limit 5 \
439
+ --learning_rate 5e-6 \
440
+ --weight_decay 0. \
441
+ --warmup_ratio 0.03 \
442
+ --lr_scheduler_type "cosine" \
443
+ --logging_steps 1 \
444
+ --fsdp "full_shard auto_wrap" \
445
+ --fsdp_transformer_layer_cls_to_wrap 'MistralDecoderLayer' \
446
+ --tf32 True \
447
+ --model_max_length 2048 \
448
+ --gradient_checkpointing True \
449
+ --conv_temp "openchat" \
450
+ --lazy_preprocess True \
451
+ --flash_attn_transformers True \
452
+ --do_train \
453
+ --do_distill \
454
+ --distill_with_ref_model True \
455
+ --distill_with_aligned_model_0 False \
456
+ --distill_with_aligned_model_1 True \
457
+ --distill_loss_type "ce" \
458
+ --distill_teacher_temperature 1.0 \
459
+ --lm_loss_weight 0.9 \
460
+ --distill_greater_as_gt True \
461
+ --distill_greater_as_gt_type hard \
462
+ --dataloader_num_workers 8 \
463
+ --remove_unused_columns False
464
+ ```
465
+
466
+ ## Model Merging
467
+
468
+ We show the scripts to obtain the final FuseChat using different merging methods.
469
+
470
+ ```bash
471
+ # For "slerp", "ta", "ties", and "dare" methods (Please install "mergekit")
472
+ export CUDA_VISIBLE_DEVICES=0
473
+ mergekit-yaml merge/mergekit_configs/fusechat-slerp.yml "<path_to_save_fusechat_7b_slerp>"
474
+ mergekit-yaml merge/mergekit_configs/fusechat-ta.yml "<path_to_save_fusechat_7b_ta>"
475
+ mergekit-yaml merge/mergekit_configs/fusechat-ties.yml "<path_to_save_fusechat_7b_ties>"
476
+ mergekit-yaml merge/mergekit_configs/fusechat-dare.yml "<path_to_save_fusechat_7b_dare>"
477
+
478
+ # For "linear" method
479
+ python merge/VaRM/merge.py \
480
+ --merged_model_names "FuseAI/OpenChat-3.5-7B-Mixtral,FuseAI/OpenChat-3.5-7B-Solar" \
481
+ --merged_model_save_dir "<path_to_save_fusechat_7b_linear>" \
482
+ --merge_method "linear" \
483
+ --linear_weights "1,2"
484
+
485
+ # For our "varm" method
486
+ python merge/VaRM/analysis.py \
487
+ --model1_path "FuseAI/OpenChat-3.5-7B-Mixtral" \
488
+ --model2_path "FuseAI/OpenChat-3.5-7B-Solar" \
489
+ --save_path "<path_to_save_analysis_result>/analysis.json" \
490
+ --merge_type "square"
491
+
492
+ python merge/VaRM/merge.py \
493
+ --merged_model_names "FuseAI/OpenChat-3.5-7B-Mixtral,FuseAI/OpenChat-3.5-7B-Solar" \
494
+ --analysis_result "<path_to_save_analysis_result>/analysis.json" \
495
+ --merged_model_save_dir "<path_to_save_fusechat_7b_varm>" \
496
+ --merge_method "avg_param" \
497
+ --merge_type "square"
498
+ ```
499
+
500
+ ## Evaluation
501
+
502
+ We evaluate FuseChat on MT-Bench, which comprises 80 multi-turn dialogues spanning writing, roleplay, reasoning, math, coding, stem, and humanities domains. Please download the [official code](https://github.com/lm-sys/FastChat/tree/main/fastchat/llm_judge) and follow the guidelines for evaluation. We provide the scripts for our evaluation.
503
+
504
+ ```bash
505
+ # Step 1. Generate model answers to MT-bench questions
506
+ export CUDA_VISIBLE_DEVICES=0,1
507
+ python gen_model_answer.py \
508
+ --model-path "FuseAI/FuseChat-7B-VaRM" \
509
+ --model-id "openchat_3.5_fusechat_7b_varm" \
510
+ --num-gpus-per-model 1 \
511
+ --num-gpus-total 2
512
+
513
+ # Step 2. Generate GPT-4 judgments
514
+ export OPENAI_API_KEY=XXXXXX # set the OpenAI API key
515
+ python gen_judgment.py \
516
+ --parallel 2
517
+
518
+ # Step 3. Show MT-bench scores
519
+ python show_result.py
520
+ ```
521
+
522
+ ## Citation
523
+
524
+ If you find this work is relevant with your research or applications, please feel free to cite our work!
525
+ ```
526
+ @article{wan2024fusechat,
527
+ title={FuseChat: Knowledge Fusion of Chat Models},
528
+ author={Fanqi Wan and Ziyi Yang and Longguang Zhong and Xiaojun Quan and Xinting Huang and Wei Bi},
529
+ journal={arXiv preprint arXiv:2402.16107},
530
+ year={2024}
531
+ }
532
+ ```
533
+
534
+ # [Open LLM Leaderboard Evaluation Results](https://huggingface.co/spaces/HuggingFaceH4/open_llm_leaderboard)
535
+ Detailed results can be found [here](https://huggingface.co/datasets/open-llm-leaderboard/details_FuseAI__FuseChat-7B-VaRM)
536
+
537
+ | Metric |Value|
538
+ |---------------------------------|----:|
539
+ |Avg. |66.52|
540
+ |AI2 Reasoning Challenge (25-Shot)|62.88|
541
+ |HellaSwag (10-Shot) |84.25|
542
+ |MMLU (5-Shot) |63.71|
543
+ |TruthfulQA (0-shot) |45.67|
544
+ |Winogrande (5-shot) |79.16|
545
+ |GSM8k (5-shot) |63.46|
added_tokens.json ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ {
2
+ "<|end_of_turn|>": 32000,
3
+ "<|pad_0|>": 32001
4
+ }
assets/fig_0.png ADDED
assets/fig_1.png ADDED
assets/tab_1.png ADDED

Git LFS Details

  • SHA256: b7a9c47a64cc46af1519dae363aa222f43772d64c2b600354fe30e2e0a384563
  • Pointer size: 132 Bytes
  • Size of remote file: 1.04 MB
config.json ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "/data/wanfq/agno_fusion/fusechat_models/fusechat_v1_nous_hermes_mixtral_teacher_e3",
3
+ "architectures": [
4
+ "MistralForCausalLM"
5
+ ],
6
+ "attention_dropout": 0.0,
7
+ "bos_token_id": 1,
8
+ "eos_token_id": 32000,
9
+ "hidden_act": "silu",
10
+ "hidden_size": 4096,
11
+ "initializer_range": 0.02,
12
+ "intermediate_size": 14336,
13
+ "max_position_embeddings": 8192,
14
+ "model_type": "mistral",
15
+ "num_attention_heads": 32,
16
+ "num_hidden_layers": 32,
17
+ "num_key_value_heads": 8,
18
+ "rms_norm_eps": 1e-05,
19
+ "rope_theta": 10000.0,
20
+ "sliding_window": 4096,
21
+ "tie_word_embeddings": false,
22
+ "torch_dtype": "bfloat16",
23
+ "transformers_version": "4.36.0",
24
+ "use_cache": true,
25
+ "vocab_size": 32002
26
+ }
gpt-4_single_fusechat_7b_varm.jsonl ADDED
The diff for this file is too large to render. See raw diff
 
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:cb1d26ef97eaf6e856b000fd82cdcb9055406a9da8d93fbe1424ab37bf413651
3
+ size 14483530992
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:268dd77ab8200fc40b13c670a80bff51960942f97250ac292fc578beda79a9b0
3
+ size 14483593810
special_tokens_map.json ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "additional_special_tokens": [
3
+ "<|end_of_turn|>",
4
+ "<|pad_0|>"
5
+ ],
6
+ "bos_token": {
7
+ "content": "<s>",
8
+ "lstrip": false,
9
+ "normalized": false,
10
+ "rstrip": false,
11
+ "single_word": false
12
+ },
13
+ "eos_token": {
14
+ "content": "<|end_of_turn|>",
15
+ "lstrip": false,
16
+ "normalized": false,
17
+ "rstrip": false,
18
+ "single_word": false
19
+ },
20
+ "unk_token": {
21
+ "content": "<unk>",
22
+ "lstrip": false,
23
+ "normalized": false,
24
+ "rstrip": false,
25
+ "single_word": false
26
+ }
27
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer.model ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:dadfd56d766715c61d2ef780a525ab43b8e6da4de6865bda3d95fdef5e134055
3
+ size 493443
tokenizer_config.json ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_bos_token": true,
3
+ "add_eos_token": false,
4
+ "added_tokens_decoder": {
5
+ "0": {
6
+ "content": "<unk>",
7
+ "lstrip": false,
8
+ "normalized": false,
9
+ "rstrip": false,
10
+ "single_word": false,
11
+ "special": true
12
+ },
13
+ "1": {
14
+ "content": "<s>",
15
+ "lstrip": false,
16
+ "normalized": false,
17
+ "rstrip": false,
18
+ "single_word": false,
19
+ "special": true
20
+ },
21
+ "2": {
22
+ "content": "</s>",
23
+ "lstrip": false,
24
+ "normalized": false,
25
+ "rstrip": false,
26
+ "single_word": false,
27
+ "special": true
28
+ },
29
+ "32000": {
30
+ "content": "<|end_of_turn|>",
31
+ "lstrip": false,
32
+ "normalized": false,
33
+ "rstrip": false,
34
+ "single_word": false,
35
+ "special": true
36
+ },
37
+ "32001": {
38
+ "content": "<|pad_0|>",
39
+ "lstrip": false,
40
+ "normalized": false,
41
+ "rstrip": false,
42
+ "single_word": false,
43
+ "special": true
44
+ }
45
+ },
46
+ "additional_special_tokens": [
47
+ "<|end_of_turn|>",
48
+ "<|pad_0|>"
49
+ ],
50
+ "bos_token": "<s>",
51
+ "chat_template": "{{ bos_token }}{% for message in messages %}{{ 'GPT4 Correct ' + message['role'].title() + ': ' + message['content'] + '<|end_of_turn|>'}}{% endfor %}{% if add_generation_prompt %}{{ 'GPT4 Correct Assistant:' }}{% endif %}",
52
+ "clean_up_tokenization_spaces": false,
53
+ "eos_token": "<|end_of_turn|>",
54
+ "legacy": true,
55
+ "model_max_length": 1000000000000000019884624838656,
56
+ "pad_token": null,
57
+ "sp_model_kwargs": {},
58
+ "spaces_between_special_tokens": false,
59
+ "tokenizer_class": "LlamaTokenizer",
60
+ "unk_token": "<unk>",
61
+ "use_default_system_prompt": true
62
+ }