RichardErkhov commited on
Commit
e8d1553
1 Parent(s): 9effb7f

uploaded readme

Browse files
Files changed (1) hide show
  1. README.md +590 -0
README.md ADDED
@@ -0,0 +1,590 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Quantization made by Richard Erkhov.
2
+
3
+ [Github](https://github.com/RichardErkhov)
4
+
5
+ [Discord](https://discord.gg/pvy7H8DZMG)
6
+
7
+ [Request more models](https://github.com/RichardErkhov/quant_request)
8
+
9
+
10
+ FuseChat-7B-VaRM - GGUF
11
+ - Model creator: https://huggingface.co/FuseAI/
12
+ - Original model: https://huggingface.co/FuseAI/FuseChat-7B-VaRM/
13
+
14
+
15
+ | Name | Quant method | Size |
16
+ | ---- | ---- | ---- |
17
+ | [FuseChat-7B-VaRM.Q2_K.gguf](https://huggingface.co/RichardErkhov/FuseAI_-_FuseChat-7B-VaRM-gguf/blob/main/FuseChat-7B-VaRM.Q2_K.gguf) | Q2_K | 2.53GB |
18
+ | [FuseChat-7B-VaRM.IQ3_XS.gguf](https://huggingface.co/RichardErkhov/FuseAI_-_FuseChat-7B-VaRM-gguf/blob/main/FuseChat-7B-VaRM.IQ3_XS.gguf) | IQ3_XS | 2.81GB |
19
+ | [FuseChat-7B-VaRM.IQ3_S.gguf](https://huggingface.co/RichardErkhov/FuseAI_-_FuseChat-7B-VaRM-gguf/blob/main/FuseChat-7B-VaRM.IQ3_S.gguf) | IQ3_S | 2.96GB |
20
+ | [FuseChat-7B-VaRM.Q3_K_S.gguf](https://huggingface.co/RichardErkhov/FuseAI_-_FuseChat-7B-VaRM-gguf/blob/main/FuseChat-7B-VaRM.Q3_K_S.gguf) | Q3_K_S | 2.95GB |
21
+ | [FuseChat-7B-VaRM.IQ3_M.gguf](https://huggingface.co/RichardErkhov/FuseAI_-_FuseChat-7B-VaRM-gguf/blob/main/FuseChat-7B-VaRM.IQ3_M.gguf) | IQ3_M | 3.06GB |
22
+ | [FuseChat-7B-VaRM.Q3_K.gguf](https://huggingface.co/RichardErkhov/FuseAI_-_FuseChat-7B-VaRM-gguf/blob/main/FuseChat-7B-VaRM.Q3_K.gguf) | Q3_K | 3.28GB |
23
+ | [FuseChat-7B-VaRM.Q3_K_M.gguf](https://huggingface.co/RichardErkhov/FuseAI_-_FuseChat-7B-VaRM-gguf/blob/main/FuseChat-7B-VaRM.Q3_K_M.gguf) | Q3_K_M | 3.28GB |
24
+ | [FuseChat-7B-VaRM.Q3_K_L.gguf](https://huggingface.co/RichardErkhov/FuseAI_-_FuseChat-7B-VaRM-gguf/blob/main/FuseChat-7B-VaRM.Q3_K_L.gguf) | Q3_K_L | 3.56GB |
25
+ | [FuseChat-7B-VaRM.IQ4_XS.gguf](https://huggingface.co/RichardErkhov/FuseAI_-_FuseChat-7B-VaRM-gguf/blob/main/FuseChat-7B-VaRM.IQ4_XS.gguf) | IQ4_XS | 3.67GB |
26
+ | [FuseChat-7B-VaRM.Q4_0.gguf](https://huggingface.co/RichardErkhov/FuseAI_-_FuseChat-7B-VaRM-gguf/blob/main/FuseChat-7B-VaRM.Q4_0.gguf) | Q4_0 | 3.83GB |
27
+ | [FuseChat-7B-VaRM.IQ4_NL.gguf](https://huggingface.co/RichardErkhov/FuseAI_-_FuseChat-7B-VaRM-gguf/blob/main/FuseChat-7B-VaRM.IQ4_NL.gguf) | IQ4_NL | 3.87GB |
28
+ | [FuseChat-7B-VaRM.Q4_K_S.gguf](https://huggingface.co/RichardErkhov/FuseAI_-_FuseChat-7B-VaRM-gguf/blob/main/FuseChat-7B-VaRM.Q4_K_S.gguf) | Q4_K_S | 3.86GB |
29
+ | [FuseChat-7B-VaRM.Q4_K.gguf](https://huggingface.co/RichardErkhov/FuseAI_-_FuseChat-7B-VaRM-gguf/blob/main/FuseChat-7B-VaRM.Q4_K.gguf) | Q4_K | 4.07GB |
30
+ | [FuseChat-7B-VaRM.Q4_K_M.gguf](https://huggingface.co/RichardErkhov/FuseAI_-_FuseChat-7B-VaRM-gguf/blob/main/FuseChat-7B-VaRM.Q4_K_M.gguf) | Q4_K_M | 4.07GB |
31
+ | [FuseChat-7B-VaRM.Q4_1.gguf](https://huggingface.co/RichardErkhov/FuseAI_-_FuseChat-7B-VaRM-gguf/blob/main/FuseChat-7B-VaRM.Q4_1.gguf) | Q4_1 | 4.24GB |
32
+ | [FuseChat-7B-VaRM.Q5_0.gguf](https://huggingface.co/RichardErkhov/FuseAI_-_FuseChat-7B-VaRM-gguf/blob/main/FuseChat-7B-VaRM.Q5_0.gguf) | Q5_0 | 4.65GB |
33
+ | [FuseChat-7B-VaRM.Q5_K_S.gguf](https://huggingface.co/RichardErkhov/FuseAI_-_FuseChat-7B-VaRM-gguf/blob/main/FuseChat-7B-VaRM.Q5_K_S.gguf) | Q5_K_S | 4.65GB |
34
+ | [FuseChat-7B-VaRM.Q5_K.gguf](https://huggingface.co/RichardErkhov/FuseAI_-_FuseChat-7B-VaRM-gguf/blob/main/FuseChat-7B-VaRM.Q5_K.gguf) | Q5_K | 4.78GB |
35
+ | [FuseChat-7B-VaRM.Q5_K_M.gguf](https://huggingface.co/RichardErkhov/FuseAI_-_FuseChat-7B-VaRM-gguf/blob/main/FuseChat-7B-VaRM.Q5_K_M.gguf) | Q5_K_M | 4.78GB |
36
+ | [FuseChat-7B-VaRM.Q5_1.gguf](https://huggingface.co/RichardErkhov/FuseAI_-_FuseChat-7B-VaRM-gguf/blob/main/FuseChat-7B-VaRM.Q5_1.gguf) | Q5_1 | 5.07GB |
37
+ | [FuseChat-7B-VaRM.Q6_K.gguf](https://huggingface.co/RichardErkhov/FuseAI_-_FuseChat-7B-VaRM-gguf/blob/main/FuseChat-7B-VaRM.Q6_K.gguf) | Q6_K | 5.53GB |
38
+ | [FuseChat-7B-VaRM.Q8_0.gguf](https://huggingface.co/RichardErkhov/FuseAI_-_FuseChat-7B-VaRM-gguf/blob/main/FuseChat-7B-VaRM.Q8_0.gguf) | Q8_0 | 7.17GB |
39
+
40
+
41
+
42
+
43
+ Original model description:
44
+ ---
45
+ license: apache-2.0
46
+ language:
47
+ - en
48
+ base_model: openchat/openchat_3.5
49
+ datasets:
50
+ - FuseAI/FuseChat-Mixture
51
+ pipeline_tag: text-generation
52
+ tags:
53
+ - mistral
54
+ - mixtral
55
+ - solar
56
+ - model-fusion
57
+ - fusechat
58
+ library_name: transformers
59
+ model-index:
60
+ - name: FuseChat-7B-VaRM
61
+ results:
62
+ - task:
63
+ type: text-generation
64
+ name: Text Generation
65
+ dataset:
66
+ name: MT-Bench
67
+ type: unknown
68
+ metrics:
69
+ - type: unknown
70
+ value: 8.22
71
+ name: score
72
+ source:
73
+ url: https://huggingface.co/spaces/lmsys/mt-bench
74
+ - task:
75
+ type: text-generation
76
+ name: Text Generation
77
+ dataset:
78
+ name: AI2 Reasoning Challenge (25-Shot)
79
+ type: ai2_arc
80
+ config: ARC-Challenge
81
+ split: test
82
+ args:
83
+ num_few_shot: 25
84
+ metrics:
85
+ - type: acc_norm
86
+ value: 62.88
87
+ name: normalized accuracy
88
+ source:
89
+ url: https://huggingface.co/spaces/HuggingFaceH4/open_llm_leaderboard?query=FuseAI/FuseChat-7B-VaRM
90
+ name: Open LLM Leaderboard
91
+ - task:
92
+ type: text-generation
93
+ name: Text Generation
94
+ dataset:
95
+ name: HellaSwag (10-Shot)
96
+ type: hellaswag
97
+ split: validation
98
+ args:
99
+ num_few_shot: 10
100
+ metrics:
101
+ - type: acc_norm
102
+ value: 84.25
103
+ name: normalized accuracy
104
+ source:
105
+ url: https://huggingface.co/spaces/HuggingFaceH4/open_llm_leaderboard?query=FuseAI/FuseChat-7B-VaRM
106
+ name: Open LLM Leaderboard
107
+ - task:
108
+ type: text-generation
109
+ name: Text Generation
110
+ dataset:
111
+ name: MMLU (5-Shot)
112
+ type: cais/mmlu
113
+ config: all
114
+ split: test
115
+ args:
116
+ num_few_shot: 5
117
+ metrics:
118
+ - type: acc
119
+ value: 63.71
120
+ name: accuracy
121
+ source:
122
+ url: https://huggingface.co/spaces/HuggingFaceH4/open_llm_leaderboard?query=FuseAI/FuseChat-7B-VaRM
123
+ name: Open LLM Leaderboard
124
+ - task:
125
+ type: text-generation
126
+ name: Text Generation
127
+ dataset:
128
+ name: TruthfulQA (0-shot)
129
+ type: truthful_qa
130
+ config: multiple_choice
131
+ split: validation
132
+ args:
133
+ num_few_shot: 0
134
+ metrics:
135
+ - type: mc2
136
+ value: 45.67
137
+ source:
138
+ url: https://huggingface.co/spaces/HuggingFaceH4/open_llm_leaderboard?query=FuseAI/FuseChat-7B-VaRM
139
+ name: Open LLM Leaderboard
140
+ - task:
141
+ type: text-generation
142
+ name: Text Generation
143
+ dataset:
144
+ name: Winogrande (5-shot)
145
+ type: winogrande
146
+ config: winogrande_xl
147
+ split: validation
148
+ args:
149
+ num_few_shot: 5
150
+ metrics:
151
+ - type: acc
152
+ value: 79.16
153
+ name: accuracy
154
+ source:
155
+ url: https://huggingface.co/spaces/HuggingFaceH4/open_llm_leaderboard?query=FuseAI/FuseChat-7B-VaRM
156
+ name: Open LLM Leaderboard
157
+ - task:
158
+ type: text-generation
159
+ name: Text Generation
160
+ dataset:
161
+ name: GSM8k (5-shot)
162
+ type: gsm8k
163
+ config: main
164
+ split: test
165
+ args:
166
+ num_few_shot: 5
167
+ metrics:
168
+ - type: acc
169
+ value: 63.46
170
+ name: accuracy
171
+ source:
172
+ url: https://huggingface.co/spaces/HuggingFaceH4/open_llm_leaderboard?query=FuseAI/FuseChat-7B-VaRM
173
+ name: Open LLM Leaderboard
174
+ ---
175
+ <p align="center" width="100%">
176
+ </p>
177
+
178
+ <div id="top" align="center">
179
+
180
+ <p style="font-size: 30px; font-weight: bold;">FuseChat: Knowledge Fusion of Chat Models</p>
181
+
182
+ <p style="font-size: 24px; font-weight: bold;">[SOTA 7B LLM on MT-Bench]</p>
183
+
184
+ <h4> |<a href="https://arxiv.org/abs/2402.16107"> 📑 Paper </a> |
185
+ <a href="https://huggingface.co/FuseAI"> 🤗 HuggingFace Repo </a> |
186
+ <a href="https://github.com/fanqiwan/FuseLLM"> 🐱 GitHub Repo </a> |
187
+ </h4>
188
+
189
+ <!-- **Authors:** -->
190
+
191
+ _**Fanqi Wan, Ziyi Yang, Longguang Zhong, Xiaojun Quan, Xinting Huang, Wei Bi**_
192
+
193
+
194
+ <!-- **Affiliations:** -->
195
+
196
+
197
+ _Sun Yat-sen University_
198
+
199
+ <p align="center">
200
+ <img src="./assets/fig_0.png" width="70%"> <br>
201
+ </p>
202
+
203
+ | Proprietary Models | #Params | MT-Bench | Open Source Models | #Params | MT-Bench |
204
+ |-----------------------------------------------------------------------|---------|----------|-----------------------------------------------------------------------|---------|----------|
205
+ | GPT-4-1106-preview | - | 9.32 | Qwen1.5-72B-Chat | 72B | 8.61 |
206
+ | GPT-4-0613 | - | 9.18 | Nous-Hermes-2-Mixtral-8x7B-DPO | 8x7B | 8.33 |
207
+ | GPT-4-0314 | - | 8.96 | Mixtral-8x7B-Instruct-v0.1 | 8x7B | 8.30 |
208
+ | Mistral Medium | - | 8.61 | 🤗 [FuseChat-7B-VaRM](https://huggingface.co/FuseAI/FuseChat-7B-VaRM) | 7B | 8.22 |
209
+ | GPT-3.5-Turbo-0613 | - | 8.39 | Starling-LM-7B-alpha | 7B | 8.09 |
210
+ | GPT-3.5-Turbo-1106 | - | 8.32 | Tulu-2-DPO-70B | 70B | 7.89 |
211
+ | 🤗 [FuseChat-7B-VaRM](https://huggingface.co/FuseAI/FuseChat-7B-VaRM) | 7B | 8.22 | OpenChat-3.5 | 7B | 7.81 |
212
+ | Claude-2.1 | - | 8.18 | OpenChat-3.5-0106 | 7B | 7.80 |
213
+ | Claude-2.0 | - | 8.06 | WizardLM-70B-v1.0 | 70B | 7.71 |
214
+ | GPT-3.5-Turbo-0314 | - | 7.94 | Yi-34B-Chat | 34B | 7.67 |
215
+ | Claude-1 | - | 7.90 | Nous-Hermes-2-SOLAR-10.7B | 10.7B | 7.66 |
216
+
217
+
218
+ </div>
219
+
220
+
221
+ ## News
222
+ - **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).
223
+
224
+ - **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.
225
+
226
+ ## Contents
227
+
228
+ - [Overview](#overview)
229
+ - [Model Release](#model-release)
230
+ - [Quick Start](#quick-start)
231
+ - [Data Construction](#data-construction)
232
+ - [Pairwise Knowledge Fusion](#pairwise-knowledge-fusion)
233
+ - [Model Merging](#model-merging)
234
+ - [Evaluation](#evaluation)
235
+ - [Citation](#citation)
236
+
237
+ ## Overview
238
+
239
+ 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.
240
+
241
+
242
+ 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.
243
+
244
+ <p align="center">
245
+ <img src="./assets/fig_1.png" width="95%"> <br>
246
+ </p>
247
+
248
+
249
+ ## Model Release
250
+
251
+ 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).
252
+
253
+ 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.
254
+
255
+ 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.
256
+
257
+ Here are the evaluation results.
258
+
259
+ <p align="center">
260
+ <img src="./assets/tab_1.png" width="95%"> <br>
261
+ </p>
262
+
263
+ ## Quick Start
264
+
265
+ ### Setup
266
+
267
+ We use `python 3.11` in this project.
268
+
269
+ Then, we have to install all the libraries listed in `requirements.txt`.
270
+
271
+ ```bash
272
+ pip install -r requirements.txt
273
+ ```
274
+
275
+ ### Usage
276
+
277
+ Here's how you can run the model using the 🤗 Transformers:
278
+
279
+ ```python
280
+ import transformers
281
+ tokenizer = transformers.AutoTokenizer.from_pretrained("FuseAI/FuseChat-7B-VaRM")
282
+ # Single-turn
283
+ tokens = tokenizer("GPT4 Correct User: Hello<|end_of_turn|>GPT4 Correct Assistant:").input_ids
284
+ assert tokens == [1, 420, 6316, 28781, 3198, 3123, 1247, 28747, 22557, 32000, 420, 6316, 28781, 3198, 3123, 21631, 28747]
285
+ # Multi-turn
286
+ 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
287
+ 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]
288
+ ```
289
+
290
+ The GPT4 template is also available as the integrated `tokenizer.chat_template`, which can be used instead of manually specifying the template:
291
+
292
+ ```python
293
+ messages = [
294
+ {"role": "user", "content": "Hello"},
295
+ {"role": "assistant", "content": "Hi"},
296
+ {"role": "user", "content": "How are you today?"}
297
+ ]
298
+ tokens = tokenizer.apply_chat_template(messages, add_generation_prompt=True)
299
+ 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]
300
+ ```
301
+
302
+ ## Data Construction
303
+
304
+ 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.
305
+
306
+ Here we show the scripts to obtain representations from multiple source LLMs for model fusion.
307
+
308
+ 1. Get representations for each source LLM
309
+
310
+ ```bash
311
+ # We split the dataset into 4 splits, then process each split on one or multiple GPU.
312
+
313
+ # OpenChat-3.5-7B
314
+ export CUDA_VISIBLE_DEVICES=0
315
+ for i in {0..3}; do
316
+ python /train/get_data_representation.py \
317
+ --model_name_or_path "openchat/openchat_3.5" \
318
+ --data_path "/data/fusechat_v1_clean_split_2048_filter_wrong.json" \
319
+ --dataset_save_dir "<${i}_4_path_to_openchat_representation>" \
320
+ --tknz_dataset_path "<${i}_4_path_to_openchat_tknz>" \
321
+ --cache_dir "/.cache/huggingface/datasets" \
322
+ --model_max_length 2048 \
323
+ --load_in_half bf16 \
324
+ --batch_size 32 \
325
+ --top_k_logits 10 \
326
+ --save_per_token_metric \
327
+ --no_assert \
328
+ --conv_temp "openchat" \
329
+ --flash_attn_transformers \
330
+ --mask_instruction \
331
+ --dataset_split_num 4 \
332
+ --dataset_index ${i}
333
+ done
334
+
335
+ # NH2-Mixtral-8x7B
336
+ export CUDA_VISIBLE_DEVICES=0,1,2
337
+ for i in {0..3}; do
338
+ python /train/get_data_representation.py \
339
+ --model_name_or_path "NousResearch/Nous-Hermes-2-Mixtral-8x7B-DPO" \
340
+ --data_path "/data/fusechat_v1_clean_split_2048_filter_wrong.json" \
341
+ --dataset_save_dir "<${i}_4_path_to_mixtral_representation>" \
342
+ --tknz_dataset_path "<${i}_4_path_to_mixtral_tknz>" \
343
+ --cache_dir "/.cache/huggingface/datasets" \
344
+ --model_max_length 2048 \
345
+ --load_in_half bf16 \
346
+ --batch_size 4 \
347
+ --top_k_logits 10 \
348
+ --save_per_token_metric \
349
+ --no_assert \
350
+ --conv_temp "openchat" \
351
+ --flash_attn_transformers \
352
+ --mask_instruction \
353
+ --device_map "auto" \
354
+ --dataset_split_num 4 \
355
+ --dataset_index ${i}
356
+ done
357
+
358
+ # NH2-Solar-10.7B
359
+ export CUDA_VISIBLE_DEVICES=0
360
+ for i in {0..3}; do
361
+ python /train/get_data_representation.py \
362
+ --model_name_or_path "NousResearch/Nous-Hermes-2-SOLAR-10.7B" \
363
+ --data_path "/data/fusechat_v1_clean_split_2048_filter_wrong.json" \
364
+ --dataset_save_dir "<${i}_4_path_to_solar_representation>" \
365
+ --tknz_dataset_path "<${i}_4_path_to_solar_tknz>" \
366
+ --cache_dir "/.cache/huggingface/datasets" \
367
+ --model_max_length 2048 \
368
+ --load_in_half bf16 \
369
+ --batch_size 8 \
370
+ --top_k_logits 10 \
371
+ --save_per_token_metric \
372
+ --no_assert \
373
+ --conv_temp "openchat" \
374
+ --flash_attn_transformers \
375
+ --mask_instruction \
376
+ --dataset_split_num 4 \
377
+ --dataset_index ${i}
378
+ done
379
+ ```
380
+
381
+ 2. Align representations from different source LLMs
382
+
383
+ ```bash
384
+ # Since the tokenizers and vocabularies of these source LLMs are identical, we do not align.
385
+
386
+ # OpenChat-3.5-7B <-> NH2-Mixtral-8x7B
387
+ for i in {0..3}; do
388
+ python /train/replace_model.py \
389
+ --dataset_dir "<${i}_4_path_to_openchat_representation>" \
390
+ --replace_dataset_dir "<${i}_4_path_to_mixtral_representation>" \
391
+ --dataset_save_dir "<${i}_4_path_to_openchat_mixtral_representation>" \
392
+ --preprocessing_num_workers 64 \
393
+ --batch_size 1000 \
394
+ --replace_model model_0
395
+ done
396
+
397
+ # OpenChat-3.5-7B <-> NH2-Solar-10.7B
398
+ for i in {0..3}; do
399
+ python /train/replace_model.py \
400
+ --dataset_dir "<${i}_4_path_to_openchat_mixtral_representation>" \
401
+ --replace_dataset_dir "<${i}_4_path_to_solar_representation>" \
402
+ --dataset_save_dir "<${i}_4_path_to_openchat_mixtral_solar_representation>" \
403
+ --preprocessing_num_workers 64 \
404
+ --batch_size 1000 \
405
+ --replace_model model_1
406
+ done
407
+ ```
408
+
409
+ 3. Filter instances with NaN loss in the dataset
410
+
411
+ ```bash
412
+ for i in {0..3}; do
413
+ python /train/filter_nan.py \
414
+ --input_data_dir "<${i}_4_path_to_openchat_mixtral_solar_representation>" \
415
+ --output_data_dir "<${i}_4_path_to_openchat_mixtral_solar_representation_fnan>"
416
+ done
417
+ ```
418
+
419
+ The final processed data is at `<${i}_4_path_to_openchat_mixtral_solar_representation_fnan>`.
420
+
421
+ ## Pairwise Knowledge Fusion
422
+
423
+ We show the scripts for pairwise knowledge fusion.
424
+
425
+ ```bash
426
+ # OpenChat-3.5-7B <-> NH2-Mixtral-8x7B
427
+ export CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7
428
+ torchrun --nproc_per_node=8 --master_port=20001 /train/train.py \
429
+ --model_name_or_path "openchat/openchat_3.5" \
430
+ --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>" \
431
+ --bf16 True \
432
+ --output_dir "<path_to_save_openchat_mixtral_ckpt>" \
433
+ --num_train_epochs 3 \
434
+ --per_device_train_batch_size 4 \
435
+ --per_device_eval_batch_size 4 \
436
+ --gradient_accumulation_steps 4 \
437
+ --evaluation_strategy "no" \
438
+ --save_strategy "epoch" \
439
+ --save_steps 10000 \
440
+ --save_total_limit 5 \
441
+ --learning_rate 5e-6 \
442
+ --weight_decay 0. \
443
+ --warmup_ratio 0.03 \
444
+ --lr_scheduler_type "cosine" \
445
+ --logging_steps 1 \
446
+ --fsdp "full_shard auto_wrap" \
447
+ --fsdp_transformer_layer_cls_to_wrap 'MistralDecoderLayer' \
448
+ --tf32 True \
449
+ --model_max_length 2048 \
450
+ --gradient_checkpointing True \
451
+ --conv_temp "openchat" \
452
+ --lazy_preprocess True \
453
+ --flash_attn_transformers True \
454
+ --do_train \
455
+ --do_distill \
456
+ --distill_with_ref_model True \
457
+ --distill_with_aligned_model_0 True \
458
+ --distill_with_aligned_model_1 False \
459
+ --distill_loss_type "ce" \
460
+ --distill_teacher_temperature 1.0 \
461
+ --lm_loss_weight 0.9 \
462
+ --distill_greater_as_gt True \
463
+ --distill_greater_as_gt_type hard \
464
+ --dataloader_num_workers 8 \
465
+ --remove_unused_columns False
466
+
467
+ # OpenChat-3.5-7B <-> NH2-Solar-10.7B
468
+ export CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7
469
+ torchrun --nproc_per_node=8 --master_port=20001 /train/train.py \
470
+ --model_name_or_path "openchat/openchat_3.5" \
471
+ --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>" \
472
+ --bf16 True \
473
+ --output_dir "<path_to_save_openchat_solar_ckpt>" \
474
+ --num_train_epochs 3 \
475
+ --per_device_train_batch_size 4 \
476
+ --per_device_eval_batch_size 4 \
477
+ --gradient_accumulation_steps 4 \
478
+ --evaluation_strategy "no" \
479
+ --save_strategy "epoch" \
480
+ --save_steps 10000 \
481
+ --save_total_limit 5 \
482
+ --learning_rate 5e-6 \
483
+ --weight_decay 0. \
484
+ --warmup_ratio 0.03 \
485
+ --lr_scheduler_type "cosine" \
486
+ --logging_steps 1 \
487
+ --fsdp "full_shard auto_wrap" \
488
+ --fsdp_transformer_layer_cls_to_wrap 'MistralDecoderLayer' \
489
+ --tf32 True \
490
+ --model_max_length 2048 \
491
+ --gradient_checkpointing True \
492
+ --conv_temp "openchat" \
493
+ --lazy_preprocess True \
494
+ --flash_attn_transformers True \
495
+ --do_train \
496
+ --do_distill \
497
+ --distill_with_ref_model True \
498
+ --distill_with_aligned_model_0 False \
499
+ --distill_with_aligned_model_1 True \
500
+ --distill_loss_type "ce" \
501
+ --distill_teacher_temperature 1.0 \
502
+ --lm_loss_weight 0.9 \
503
+ --distill_greater_as_gt True \
504
+ --distill_greater_as_gt_type hard \
505
+ --dataloader_num_workers 8 \
506
+ --remove_unused_columns False
507
+ ```
508
+
509
+ ## Model Merging
510
+
511
+ We show the scripts to obtain the final FuseChat using different merging methods.
512
+
513
+ ```bash
514
+ # For "slerp", "ta", "ties", and "dare" methods (Please install "mergekit")
515
+ export CUDA_VISIBLE_DEVICES=0
516
+ mergekit-yaml merge/mergekit_configs/fusechat-slerp.yml "<path_to_save_fusechat_7b_slerp>"
517
+ mergekit-yaml merge/mergekit_configs/fusechat-ta.yml "<path_to_save_fusechat_7b_ta>"
518
+ mergekit-yaml merge/mergekit_configs/fusechat-ties.yml "<path_to_save_fusechat_7b_ties>"
519
+ mergekit-yaml merge/mergekit_configs/fusechat-dare.yml "<path_to_save_fusechat_7b_dare>"
520
+
521
+ # For "linear" method
522
+ python merge/VaRM/merge.py \
523
+ --merged_model_names "FuseAI/OpenChat-3.5-7B-Mixtral,FuseAI/OpenChat-3.5-7B-Solar" \
524
+ --merged_model_save_dir "<path_to_save_fusechat_7b_linear>" \
525
+ --merge_method "linear" \
526
+ --linear_weights "1,2"
527
+
528
+ # For our "varm" method
529
+ python merge/VaRM/analysis.py \
530
+ --model1_path "FuseAI/OpenChat-3.5-7B-Mixtral" \
531
+ --model2_path "FuseAI/OpenChat-3.5-7B-Solar" \
532
+ --save_path "<path_to_save_analysis_result>/analysis.json" \
533
+ --merge_type "square"
534
+
535
+ python merge/VaRM/merge.py \
536
+ --merged_model_names "FuseAI/OpenChat-3.5-7B-Mixtral,FuseAI/OpenChat-3.5-7B-Solar" \
537
+ --analysis_result "<path_to_save_analysis_result>/analysis.json" \
538
+ --merged_model_save_dir "<path_to_save_fusechat_7b_varm>" \
539
+ --merge_method "avg_param" \
540
+ --merge_type "square"
541
+ ```
542
+
543
+ ## Evaluation
544
+
545
+ 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.
546
+
547
+ ```bash
548
+ # Step 1. Generate model answers to MT-bench questions
549
+ export CUDA_VISIBLE_DEVICES=0,1
550
+ python gen_model_answer.py \
551
+ --model-path "FuseAI/FuseChat-7B-VaRM" \
552
+ --model-id "openchat_3.5_fusechat_7b_varm" \
553
+ --num-gpus-per-model 1 \
554
+ --num-gpus-total 2
555
+
556
+ # Step 2. Generate GPT-4 judgments
557
+ export OPENAI_API_KEY=XXXXXX # set the OpenAI API key
558
+ python gen_judgment.py \
559
+ --parallel 2
560
+
561
+ # Step 3. Show MT-bench scores
562
+ python show_result.py
563
+ ```
564
+
565
+ ## Citation
566
+
567
+ If you find this work is relevant with your research or applications, please feel free to cite our work!
568
+ ```
569
+ @article{wan2024fusechat,
570
+ title={FuseChat: Knowledge Fusion of Chat Models},
571
+ author={Fanqi Wan and Ziyi Yang and Longguang Zhong and Xiaojun Quan and Xinting Huang and Wei Bi},
572
+ journal={arXiv preprint arXiv:2402.16107},
573
+ year={2024}
574
+ }
575
+ ```
576
+
577
+ # [Open LLM Leaderboard Evaluation Results](https://huggingface.co/spaces/HuggingFaceH4/open_llm_leaderboard)
578
+ Detailed results can be found [here](https://huggingface.co/datasets/open-llm-leaderboard/details_FuseAI__FuseChat-7B-VaRM)
579
+
580
+ | Metric |Value|
581
+ |---------------------------------|----:|
582
+ |Avg. |66.52|
583
+ |AI2 Reasoning Challenge (25-Shot)|62.88|
584
+ |HellaSwag (10-Shot) |84.25|
585
+ |MMLU (5-Shot) |63.71|
586
+ |TruthfulQA (0-shot) |45.67|
587
+ |Winogrande (5-shot) |79.16|
588
+ |GSM8k (5-shot) |63.46|
589
+
590
+