koesn commited on
Commit
f2f302c
1 Parent(s): 3d4d706

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +441 -0
README.md CHANGED
@@ -1,3 +1,444 @@
1
  ---
2
  license: apache-2.0
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: apache-2.0
3
  ---
4
+ # FuseChat-7B-VaRM
5
+
6
+ ## Description
7
+ This repo contains GGUF format model files for FuseChat-7B-VaRM.
8
+
9
+ ## Files Provided
10
+ | Name | Quant | Bits | File Size | Remark |
11
+ | ----------------------------- | ------- | ---- | --------- | -------------------------------- |
12
+ | fusechat-7b-varm.IQ3_XXS.gguf | IQ3_XXS | 3 | 3.02 GB | 3.06 bpw quantization |
13
+ | fusechat-7b-varm.IQ3_S.gguf | IQ3_S | 3 | 3.18 GB | 3.44 bpw quantization |
14
+ | fusechat-7b-varm.IQ3_M.gguf | IQ3_M | 3 | 3.28 GB | 3.66 bpw quantization mix |
15
+ | fusechat-7b-varm.Q4_0.gguf | Q4_0 | 4 | 4.11 GB | 3.56G, +0.2166 ppl |
16
+ | fusechat-7b-varm.IQ4_NL.gguf | IQ4_NL | 4 | 4.16 GB | 4.25 bpw non-linear quantization |
17
+ | fusechat-7b-varm.Q4_K_M.gguf | Q4_K_M | 4 | 4.37 GB | 3.80G, +0.0532 ppl |
18
+ | fusechat-7b-varm.Q5_K_M.gguf | Q5_K_M | 5 | 5.13 GB | 4.45G, +0.0122 ppl |
19
+ | fusechat-7b-varm.Q6_K.gguf | Q6_K | 6 | 5.94 GB | 5.15G, +0.0008 ppl |
20
+ | fusechat-7b-varm.Q8_0.gguf | Q8_0 | 8 | 7.70 GB | 6.70G, +0.0004 ppl |
21
+
22
+ ## Parameters
23
+ | path | type | architecture | rope_theta | sliding_win | max_pos_embed |
24
+ | ----------------------- | ------- | ------------------ | ---------- | ----------- | ------------- |
25
+ | FuseAI/FuseChat-7B-VaRM | mistral | MistralForCausalLM | 10000.0 | 4096 | 8192 |
26
+
27
+ ## Benchmarks
28
+ ![](<----enter picture url here---->)
29
+
30
+ ## Specific Purpose Notes
31
+ # Original Model Card
32
+
33
+ ---
34
+ license: apache-2.0
35
+ language:
36
+ - en
37
+ pipeline_tag: text-generation
38
+ tags:
39
+ - mistral
40
+ - mixtral
41
+ - solar
42
+ - model-fusion
43
+ - fusechat
44
+ library_name: transformers
45
+ ---
46
+ <p align="center" width="100%">
47
+ </p>
48
+
49
+ <div id="top" align="center">
50
+
51
+ <p style="font-size: 32px; font-weight: bold;">FuseChat: Knowledge Fusion of Chat Models</p>
52
+
53
+
54
+ <h4> |<a href="https://arxiv.org/abs/2402.16107"> 📑 Paper </a> |
55
+ <a href="https://huggingface.co/FuseAI"> 🤗 Huggingface Repo </a> |
56
+ <a href="https://github.com/fanqiwan/FuseLLM"> 🐱 Github Repo </a> |
57
+ </h4>
58
+
59
+ <!-- **Authors:** -->
60
+
61
+ _**Fanqi Wan, Ziyi Yang, Longguang Zhong, Xiaojun Quan, Xinting Huang, Wei Bi**_
62
+
63
+
64
+ <!-- **Affiliations:** -->
65
+
66
+
67
+ _Sun Yat-sen University_
68
+
69
+ <p align="center">
70
+ <img src="./assets/fig_0.png" width="70%"> <br>
71
+ </p>
72
+
73
+ | Proprietary Models | #Params | MT-Bench | Open Source Models | #Params | MT-Bench |
74
+ |-----------------------------------------------------------------------|---------|----------|-----------------------------------------------------------------------|---------|----------|
75
+ | GPT-4-1106-preview | - | 9.32 | Qwen1.5-72B-Chat | 72B | 8.61 |
76
+ | GPT-4-0613 | - | 9.18 | Nous-Hermes-2-Mixtral-8x7B-DPO | 8x7B | 8.33 |
77
+ | GPT-4-0314 | - | 8.96 | Mixtral-8x7B-Instruct-v0.1 | 8x7B | 8.30 |
78
+ | Mistral Medium | - | 8.61 | 🤗 [FuseChat-7B-VaRM](https://huggingface.co/FuseAI/FuseChat-7B-VaRM) | 7B | 8.22 |
79
+ | GPT-3.5-Turbo-0613 | - | 8.39 | Starling-LM-7B-alpha | 7B | 8.09 |
80
+ | GPT-3.5-Turbo-1106 | - | 8.32 | Tulu-2-DPO-70B | 70B | 7.89 |
81
+ | 🤗 [FuseChat-7B-VaRM](https://huggingface.co/FuseAI/FuseChat-7B-VaRM) | 7B | 8.22 | OpenChat-3.5 | 7B | 7.81 |
82
+ | Claude-2.1 | - | 8.18 | OpenChat-3.5-0106 | 7B | 7.80 |
83
+ | Claude-2.0 | - | 8.06 | WizardLM-70B-v1.0 | 70B | 7.71 |
84
+ | GPT-3.5-Turbo-0314 | - | 7.94 | Yi-34B-Chat | 34B | 7.67 |
85
+ | Claude-1 | - | 7.90 | Nous-Hermes-2-SOLAR-10.7B | 10.7B | 7.66 |
86
+
87
+
88
+ </div>
89
+
90
+
91
+ ## News
92
+ - **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).
93
+
94
+
95
+ ## Contents
96
+
97
+ - [Overview](#overview)
98
+ - [Model Release](#model-release)
99
+ - [Quick Start](#quick-start)
100
+ - [Data Construction](#data-construction)
101
+ - [Pairwise Knowledge Fusion](#pairwise-knowledge-fusion)
102
+ - [Model Merging](#model-merging)
103
+ - [Evaluation](#evaluation)
104
+ - [Citation](#citation)
105
+
106
+ ## Overview
107
+
108
+ 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.
109
+
110
+
111
+ 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.
112
+
113
+ <p align="center">
114
+ <img src="./assets/fig_1.png" width="95%"> <br>
115
+ </p>
116
+
117
+
118
+ ## Model Release
119
+
120
+ 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).
121
+
122
+ 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.
123
+
124
+ 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.
125
+
126
+ Here are the evaluation results.
127
+
128
+ <p align="center">
129
+ <img src="./assets/tab_1.png" width="95%"> <br>
130
+ </p>
131
+
132
+ ## Quick Start
133
+
134
+ ### Setup
135
+
136
+ We use `python 3.11` in this project.
137
+
138
+ Then, we have to install all the libraries listed in `requirements.txt`.
139
+
140
+ ```bash
141
+ pip install -r requirements.txt
142
+ ```
143
+
144
+ ### Usage
145
+
146
+ Here's how you can run the model using the 🤗 Transformers:
147
+
148
+ ```python
149
+ import transformers
150
+ tokenizer = transformers.AutoTokenizer.from_pretrained("FuseAI/FuseChat-7B-VaRM")
151
+ # Single-turn
152
+ tokens = tokenizer("GPT4 Correct User: Hello<|end_of_turn|>GPT4 Correct Assistant:").input_ids
153
+ assert tokens == [1, 420, 6316, 28781, 3198, 3123, 1247, 28747, 22557, 32000, 420, 6316, 28781, 3198, 3123, 21631, 28747]
154
+ # Multi-turn
155
+ 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
156
+ 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]
157
+ ```
158
+
159
+ The GPT4 template is also available as the integrated `tokenizer.chat_template`, which can be used instead of manually specifying the template:
160
+
161
+ ```python
162
+ messages = [
163
+ {"role": "user", "content": "Hello"},
164
+ {"role": "assistant", "content": "Hi"},
165
+ {"role": "user", "content": "How are you today?"}
166
+ ]
167
+ tokens = tokenizer.apply_chat_template(messages, add_generation_prompt=True)
168
+ 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]
169
+ ```
170
+
171
+ ## Data Construction
172
+
173
+ 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.
174
+
175
+ Here we show the scripts to obtain representations from multiple source LLMs for model fusion.
176
+
177
+ 1. Get representations for each source LLM
178
+
179
+ ```bash
180
+ # We split the dataset into 4 splits, then process each split on one or multiple GPU.
181
+
182
+ # OpenChat-3.5-7B
183
+ export CUDA_VISIBLE_DEVICES=0
184
+ for i in {0..3}; do
185
+ python /train/get_data_representation.py \
186
+ --model_name_or_path "openchat/openchat_3.5" \
187
+ --data_path "/data/fusechat_v1_clean_split_2048_filter_wrong.json" \
188
+ --dataset_save_dir "<${i}_4_path_to_openchat_representation>" \
189
+ --tknz_dataset_path "<${i}_4_path_to_openchat_tknz>" \
190
+ --cache_dir "/.cache/huggingface/datasets" \
191
+ --model_max_length 2048 \
192
+ --load_in_half bf16 \
193
+ --batch_size 32 \
194
+ --top_k_logits 10 \
195
+ --save_per_token_metric \
196
+ --no_assert \
197
+ --conv_temp "openchat" \
198
+ --flash_attn_transformers \
199
+ --mask_instruction \
200
+ --dataset_split_num 4 \
201
+ --dataset_index ${i}
202
+ done
203
+
204
+ # NH2-Mixtral-8x7B
205
+ export CUDA_VISIBLE_DEVICES=0,1,2
206
+ for i in {0..3}; do
207
+ python /train/get_data_representation.py \
208
+ --model_name_or_path "NousResearch/Nous-Hermes-2-Mixtral-8x7B-DPO" \
209
+ --data_path "/data/fusechat_v1_clean_split_2048_filter_wrong.json" \
210
+ --dataset_save_dir "<${i}_4_path_to_mixtral_representation>" \
211
+ --tknz_dataset_path "<${i}_4_path_to_mixtral_tknz>" \
212
+ --cache_dir "/.cache/huggingface/datasets" \
213
+ --model_max_length 2048 \
214
+ --load_in_half bf16 \
215
+ --batch_size 4 \
216
+ --top_k_logits 10 \
217
+ --save_per_token_metric \
218
+ --no_assert \
219
+ --conv_temp "openchat" \
220
+ --flash_attn_transformers \
221
+ --mask_instruction \
222
+ --device_map "auto" \
223
+ --dataset_split_num 4 \
224
+ --dataset_index ${i}
225
+ done
226
+
227
+ # NH2-Solar-10.7B
228
+ export CUDA_VISIBLE_DEVICES=0
229
+ for i in {0..3}; do
230
+ python /train/get_data_representation.py \
231
+ --model_name_or_path "NousResearch/Nous-Hermes-2-SOLAR-10.7B" \
232
+ --data_path "/data/fusechat_v1_clean_split_2048_filter_wrong.json" \
233
+ --dataset_save_dir "<${i}_4_path_to_solar_representation>" \
234
+ --tknz_dataset_path "<${i}_4_path_to_solar_tknz>" \
235
+ --cache_dir "/.cache/huggingface/datasets" \
236
+ --model_max_length 2048 \
237
+ --load_in_half bf16 \
238
+ --batch_size 8 \
239
+ --top_k_logits 10 \
240
+ --save_per_token_metric \
241
+ --no_assert \
242
+ --conv_temp "openchat" \
243
+ --flash_attn_transformers \
244
+ --mask_instruction \
245
+ --dataset_split_num 4 \
246
+ --dataset_index ${i}
247
+ done
248
+ ```
249
+
250
+ 2. Align representations from different source LLMs
251
+
252
+ ```bash
253
+ # Since the tokenizers and vocabularies of these source LLMs are identical, we do not align.
254
+
255
+ # OpenChat-3.5-7B <-> NH2-Mixtral-8x7B
256
+ for i in {0..3}; do
257
+ python /train/replace_model.py \
258
+ --dataset_dir "<${i}_4_path_to_openchat_representation>" \
259
+ --replace_dataset_dir "<${i}_4_path_to_mixtral_representation>" \
260
+ --dataset_save_dir "<${i}_4_path_to_openchat_mixtral_representation>" \
261
+ --preprocessing_num_workers 64 \
262
+ --batch_size 1000 \
263
+ --replace_model model_0
264
+ done
265
+
266
+ # OpenChat-3.5-7B <-> NH2-Solar-10.7B
267
+ for i in {0..3}; do
268
+ python /train/replace_model.py \
269
+ --dataset_dir "<${i}_4_path_to_openchat_mixtral_representation>" \
270
+ --replace_dataset_dir "<${i}_4_path_to_solar_representation>" \
271
+ --dataset_save_dir "<${i}_4_path_to_openchat_mixtral_solar_representation>" \
272
+ --preprocessing_num_workers 64 \
273
+ --batch_size 1000 \
274
+ --replace_model model_1
275
+ done
276
+ ```
277
+
278
+ 3. Filter instances with NaN loss in the dataset
279
+
280
+ ```bash
281
+ for i in {0..3}; do
282
+ python /train/filter_nan.py \
283
+ --input_data_dir "<${i}_4_path_to_openchat_mixtral_solar_representation>" \
284
+ --output_data_dir "<${i}_4_path_to_openchat_mixtral_solar_representation_fnan>"
285
+ done
286
+ ```
287
+
288
+ The final processed data is at `<${i}_4_path_to_openchat_mixtral_solar_representation_fnan>`.
289
+
290
+ ## Pairwise Knowledge Fusion
291
+
292
+ We show the scripts for pairwise knowledge fusion.
293
+
294
+ ```bash
295
+ # OpenChat-3.5-7B <-> NH2-Mixtral-8x7B
296
+ export CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7
297
+ torchrun --nproc_per_node=8 --master_port=20001 /train/train.py \
298
+ --model_name_or_path "openchat/openchat_3.5" \
299
+ --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>" \
300
+ --bf16 True \
301
+ --output_dir "<path_to_save_openchat_mixtral_ckpt>" \
302
+ --num_train_epochs 3 \
303
+ --per_device_train_batch_size 4 \
304
+ --per_device_eval_batch_size 4 \
305
+ --gradient_accumulation_steps 4 \
306
+ --evaluation_strategy "no" \
307
+ --save_strategy "epoch" \
308
+ --save_steps 10000 \
309
+ --save_total_limit 5 \
310
+ --learning_rate 5e-6 \
311
+ --weight_decay 0. \
312
+ --warmup_ratio 0.03 \
313
+ --lr_scheduler_type "cosine" \
314
+ --logging_steps 1 \
315
+ --fsdp "full_shard auto_wrap" \
316
+ --fsdp_transformer_layer_cls_to_wrap 'MistralDecoderLayer' \
317
+ --tf32 True \
318
+ --model_max_length 2048 \
319
+ --gradient_checkpointing True \
320
+ --conv_temp "openchat" \
321
+ --lazy_preprocess True \
322
+ --flash_attn_transformers True \
323
+ --do_train \
324
+ --do_distill \
325
+ --distill_with_ref_model True \
326
+ --distill_with_aligned_model_0 True \
327
+ --distill_with_aligned_model_1 False \
328
+ --distill_loss_type "ce" \
329
+ --distill_teacher_temperature 1.0 \
330
+ --lm_loss_weight 0.9 \
331
+ --distill_greater_as_gt True \
332
+ --distill_greater_as_gt_type hard \
333
+ --dataloader_num_workers 8 \
334
+ --remove_unused_columns False
335
+
336
+ # OpenChat-3.5-7B <-> NH2-Solar-10.7B
337
+ export CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7
338
+ torchrun --nproc_per_node=8 --master_port=20001 /train/train.py \
339
+ --model_name_or_path "openchat/openchat_3.5" \
340
+ --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>" \
341
+ --bf16 True \
342
+ --output_dir "<path_to_save_openchat_solar_ckpt>" \
343
+ --num_train_epochs 3 \
344
+ --per_device_train_batch_size 4 \
345
+ --per_device_eval_batch_size 4 \
346
+ --gradient_accumulation_steps 4 \
347
+ --evaluation_strategy "no" \
348
+ --save_strategy "epoch" \
349
+ --save_steps 10000 \
350
+ --save_total_limit 5 \
351
+ --learning_rate 5e-6 \
352
+ --weight_decay 0. \
353
+ --warmup_ratio 0.03 \
354
+ --lr_scheduler_type "cosine" \
355
+ --logging_steps 1 \
356
+ --fsdp "full_shard auto_wrap" \
357
+ --fsdp_transformer_layer_cls_to_wrap 'MistralDecoderLayer' \
358
+ --tf32 True \
359
+ --model_max_length 2048 \
360
+ --gradient_checkpointing True \
361
+ --conv_temp "openchat" \
362
+ --lazy_preprocess True \
363
+ --flash_attn_transformers True \
364
+ --do_train \
365
+ --do_distill \
366
+ --distill_with_ref_model True \
367
+ --distill_with_aligned_model_0 False \
368
+ --distill_with_aligned_model_1 True \
369
+ --distill_loss_type "ce" \
370
+ --distill_teacher_temperature 1.0 \
371
+ --lm_loss_weight 0.9 \
372
+ --distill_greater_as_gt True \
373
+ --distill_greater_as_gt_type hard \
374
+ --dataloader_num_workers 8 \
375
+ --remove_unused_columns False
376
+ ```
377
+
378
+ ## Model Merging
379
+
380
+ We show the scripts to obtain the final FuseChat using different merging methods.
381
+
382
+ ```bash
383
+ # For "slerp", "ta", "ties", and "dare" methods (Please install "mergekit")
384
+ export CUDA_VISIBLE_DEVICES=0
385
+ mergekit-yaml merge/mergekit_configs/fusechat-slerp.yml "<path_to_save_fusechat_7b_slerp>"
386
+ mergekit-yaml merge/mergekit_configs/fusechat-ta.yml "<path_to_save_fusechat_7b_ta>"
387
+ mergekit-yaml merge/mergekit_configs/fusechat-ties.yml "<path_to_save_fusechat_7b_ties>"
388
+ mergekit-yaml merge/mergekit_configs/fusechat-dare.yml "<path_to_save_fusechat_7b_dare>"
389
+
390
+ # For "linear" method
391
+ python merge/VaRM/merge.py \
392
+ --merged_model_names "FuseAI/OpenChat-3.5-7B-Mixtral,FuseAI/OpenChat-3.5-7B-Solar" \
393
+ --merged_model_save_dir "<path_to_save_fusechat_7b_linear>" \
394
+ --merge_method "linear" \
395
+ --linear_weights "1,2"
396
+
397
+ # For our "varm" method
398
+ python merge/VaRM/analysis.py \
399
+ --model1_path "FuseAI/OpenChat-3.5-7B-Mixtral" \
400
+ --model2_path "FuseAI/OpenChat-3.5-7B-Solar" \
401
+ --save_path "<path_to_save_analysis_result>/analysis.json" \
402
+ --merge_type "square"
403
+
404
+ python merge/VaRM/merge.py \
405
+ --merged_model_names "FuseAI/OpenChat-3.5-7B-Mixtral,FuseAI/OpenChat-3.5-7B-Solar" \
406
+ --analysis_result "<path_to_save_analysis_result>/analysis.json" \
407
+ --merged_model_save_dir "<path_to_save_fusechat_7b_varm>" \
408
+ --merge_method "avg_param" \
409
+ --merge_type "square"
410
+ ```
411
+
412
+ ## Evaluation
413
+
414
+ 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.
415
+
416
+ ```bash
417
+ # Step 1. Generate model answers to MT-bench questions
418
+ export CUDA_VISIBLE_DEVICES=0,1
419
+ python gen_model_answer.py \
420
+ --model-path "FuseAI/FuseChat-7B-VaRM" \
421
+ --model-id "openchat_3.5_fusechat_7b_varm" \
422
+ --num-gpus-per-model 1 \
423
+ --num-gpus-total 2
424
+
425
+ # Step 2. Generate GPT-4 judgments
426
+ export OPENAI_API_KEY=XXXXXX # set the OpenAI API key
427
+ python gen_judgment.py \
428
+ --parallel 2
429
+
430
+ # Step 3. Show MT-bench scores
431
+ python show_result.py
432
+ ```
433
+
434
+ ## Citation
435
+
436
+ If you find this work is relevant with your research or applications, please feel free to cite our work!
437
+ ```
438
+ @article{wan2024fusechat,
439
+ title={FuseChat: Knowledge Fusion of Chat Models},
440
+ author={Fanqi Wan and Ziyi Yang and Longguang Zhong and Xiaojun Quan and Xinting Huang and Wei Bi},
441
+ journal={arXiv preprint arXiv:2402.16107},
442
+ year={2024}
443
+ }
444
+ ```