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