๐ FuseLLM - Knowledge Fusion of Large Language Models
FuseLLM explores knowledge fusion for LLMs, combining capabilities of multiple diverse - structured LLMs into a unified and more powerful model.
Knowledge Fusion of Large Language Models
Fanqi Wanโ , Xinting Huangโก, Deng Caiโก, Xiaojun Quanโ , Wei Biโก, Shuming Shiโก
โ Sun Yat-sen University,
โก Tencent AI Lab
Model |
BBH |
ARC-easy |
ARC-challenge |
BoolQ |
HellaSwag |
OpenBookQA |
OpenLLaMA-7B |
33.87 |
69.70 |
41.38 |
72.29 |
74.53 |
41.00 |
MPT-7B |
33.38 |
70.12 |
42.15 |
74.74 |
76.25 |
42.40 |
Llama-2-7B |
39.70 |
74.58 |
46.33 |
77.71 |
76.00 |
44.20 |
Llama-2-CLM-7B |
40.44 |
74.54 |
46.50 |
76.88 |
76.57 |
44.80 |
๐ค FuseLLM-7B |
41.75 |
75.04 |
47.44 |
78.13 |
76.78 |
45.40 |
Model |
MultiPL-E |
TrivialQA |
DROP |
LAMBADA |
IWSLT2017 |
SciBench |
OpenLLaMA-7B |
18.11 |
39.96 |
22.31 |
70.31 |
5.51 |
0.68 |
MPT-7B |
17.26 |
28.89 |
23.54 |
70.08 |
5.49 |
0.88 |
Llama-2-7B |
14.63 |
52.46 |
27.25 |
73.28 |
6.48 |
0.14 |
Llama-2-CLM-7B |
14.83 |
53.14 |
28.51 |
73.45 |
6.91 |
0.94 |
๐ค FuseLLM-7B |
15.56 |
54.49 |
28.97 |
73.72 |
6.75 |
1.65 |
๐ฐ News
๐ง WIP
Source LLMs |
Target LLM |
Mixtral-8x7B-v0.1, SOLAR-10.7B-v1.0, Mistral-7B-v0.1 |
Mistral-7B-v0.1 |
Mixtral-8x7B-v0.1, SOLAR-10.7B-v1.0, Mistral-7B-v0.1 |
SOLAR-10.7B-v1.0 |
Mixtral-8x7B-v0.1, SOLAR-10.7B-v1.0, Mistral-7B-v0.1 |
Mixtral-8x7B-v0.1 |
๐ Contents
๐ Overview
In this study, we explore the realm of knowledge fusion for LLMs to create a unified model that combines the capabilities and distinctive strengths of multiple structurally diverse LLMs. To achieve this, we introduce FuseLLM, which first leverages the generative distributions of these source LLMs to externalize both their collective knowledge and individual strengths, and subsequently transfer them to the target LLM through lightweight continual training.
Unlike model ensemble approaches that require the parallel deployment of multiple LLMs, or weight merging techniques that are typically limited to LLMs with identical architectures, FuseLLM is designed to support the fusion of multiple LLMs with diverse architectures into a more potent LLM. By explicitly transferring their knowledge and capabilities to a single target LLM, FuseLLM offers a powerful and flexible solution for the knowledge fusion of LLMs.
๐ Model Release
We release the FuseLLM-7B on ๐ค Huggingface Models, which is the fusion of three popular open - source LLMs that possess distinct architectures and functionalities: Llama-2-7B, OpenLLaMA-7B, and MPT-7B.
Here are the evaluation results of FuseLLM.
๐ง General Reasoning & Commonsense Reasoning
We first show the performance of FuseLLM on Big - Bench Hard and CommonSense benchmarks, which evaluate the general reasoning and commonsense reasoning abilities respectively.
๐ป Code Generation & Text Generation
We then evaluate FuseLLM on MultiPL - E, which is a multilingual programming benchmark to assess the code generation performance. We also conduct experiments on several text generation benchmarks, including TrivialQA (question - answering), DROP (reading comprehension), LAMBADA (content analysis), IWSLT2017 (machine translation), and SCIBench (theorem application).
๐ Instruction Following
FuseLLM is also applicable to the fusion of instruction - tuned LLMs. We further evaluate the Vicuna Benchmark, which assesses the instruction following ability.
โ๏ธ FuseLLM vs. Knowledge Distillation
As knowledge distillation is also a method for enhancing the performance of LLMs by utilizing representations, we compare FuseLLM with Llama - 2 KD, which is distilled from Llama - 2 13B.
โ๏ธ FuseLLM vs. Model Ensemble & Weight Merging
To compare FuseLLM with existing fusion methods (such as model ensemble and weight merging), we simulate scenarios to ensure model fusion with an identical structure where multiple source LLMs are derived from the same base model but are continually trained on different corpus. We then test the perplexity of these fusion methods on different benchmarks.
๐ Quick Start
โ๏ธ Setup
We use python 3.9
in this project.
Then, we have to install all the libraries listed in requirements.txt
.
pip install -r requirements.txt
๐ป Usage
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("Wanfq/FuseLLM-7B", use_fast=False)
model = AutoModelForCausalLM.from_pretrained("Wanfq/FuseLLM-7B", torch_dtype="auto")
model.cuda()
inputs = tokenizer("<your text here>", return_tensors="pt").to(model.device)
tokens = model.generate(
**inputs,
max_new_tokens=512,
temperature=0.6,
top_p=0.9,
do_sample=True,
)
print(tokenizer.decode(tokens[0], skip_special_tokens=True))
We also find Exllama v2 Quantizations
version on FuseLLM-7B-exl2, it uses ExLlamaV2 v0.0.11 for quantization.
๐ ๏ธ Data Construction
We use the MiniPile dataset for continual training.
Here we show the scripts to obtain representations from multiple LLMs for model fusion.
1. Split long text
python ./src/utils/split_long_text.py \
--base_model_name_or_path "<path_to_llama_2_7b>" \
--blending_model_name_or_path "<path_to_open_llama_7b_v2>" \
--another_blending_model_name_or_path "<path_to_mpt_7b>" \
--dataset "<path_to_minipile>" \
--dataset_save_dir "<path_to_minipile_split>" \
--cache_dir "<path_to_cache_dir>" \
--block_size 2048 \
--preprocessing_num_workers 80
2. Get representations for each LLM
for i in {0..7}; do
export CUDA_VISIBLE_DEVICES=${i}
python ./src/utils/forward_for_logits.py \
--model_name_or_path "<path_to_each_model>" \
--dataset "<path_to_minipile_split>" \
--dataset_save_dir "${i}_8_<path_to_minipile_split_each_model_representation>" \
--dataset_split_num 8 \
--dataset_index ${i} \
--cache_dir "<path_to_cache_dir>" \
--model_max_length 2048 \
--training_mode full \
--load_in_half bf16 \
--batch_size 8 \
--preprocessing_num_workers 80 \
--top_k_logits 10 \
--save_per_token_metric 2>&1 > "${i}_8_<path_to_log_file>" 2>&1 &
unset CUDA_VISIBLE_DEVICES
sleep 30
done
wait
3. Align representations from different LLMs
python ./src/utils/vocab_mapping.py \
--base_model_name_or_path "<path_to_llama_2_7b>" \
--blending_model_name_or_path "<path_to_open_llama_7b_v2>" \
--dataset_dir "<path_to_minipile_split>" \
--vocab_mapping_save_dir "<path_to_llama_2_7b_open_llama_7b_v2_vocab_mapping>" \
--cache_dir "<path_to_cache_dir>" \
--model_max_length 2048 \
--vocab_mapping_type "default" \
--num_process 1
python ./src/utils/vocab_mapping.py \
--base_model_name_or_path "<path_to_llama_2_7b>" \
--blending_model_name_or_path "<path_to_mpt_7b>" \
--dataset_dir "<path_to_minipile_split>" \
--vocab_mapping_save_dir "<path_to_llama_2_7b_mpt_7b_vocab_mapping>" \
--cache_dir "<path_to_cache_dir>" \
--model_max_length 2048 \
--vocab_mapping_type "default" \
--num_process 1
for i in {0..7}; do
python ./src/utils/token_alignmen