Views
No views yet
| Name | Quant method | Size |
|---|---|---|
| FuseChat-7B-v2.0.Q2_K.gguf | Q2_K | 2.53GB |
| FuseChat-7B-v2.0.IQ3_XS.gguf | IQ3_XS | 2.81GB |
| FuseChat-7B-v2.0.IQ3_S.gguf | IQ3_S | 2.96GB |
| FuseChat-7B-v2.0.Q3_K_S.gguf | Q3_K_S | 2.95GB |
| FuseChat-7B-v2.0.IQ3_M.gguf | IQ3_M | 3.06GB |
| FuseChat-7B-v2.0.Q3_K.gguf | Q3_K | 3.28GB |
| FuseChat-7B-v2.0.Q3_K_M.gguf | Q3_K_M | 3.28GB |
| FuseChat-7B-v2.0.Q3_K_L.gguf | Q3_K_L | 3.56GB |
| FuseChat-7B-v2.0.IQ4_XS.gguf | IQ4_XS | 3.67GB |
| FuseChat-7B-v2.0.Q4_0.gguf | Q4_0 | 3.83GB |
| FuseChat-7B-v2.0.IQ4_NL.gguf | IQ4_NL | 3.87GB |
| FuseChat-7B-v2.0.Q4_K_S.gguf | Q4_K_S | 3.86GB |
| FuseChat-7B-v2.0.Q4_K.gguf | Q4_K | 4.07GB |
| FuseChat-7B-v2.0.Q4_K_M.gguf | Q4_K_M | 4.07GB |
| FuseChat-7B-v2.0.Q4_1.gguf | Q4_1 | 4.24GB |
| FuseChat-7B-v2.0.Q5_0.gguf | Q5_0 | 4.65GB |
| FuseChat-7B-v2.0.Q5_K_S.gguf | Q5_K_S | 4.65GB |
| FuseChat-7B-v2.0.Q5_K.gguf | Q5_K | 4.78GB |
| FuseChat-7B-v2.0.Q5_K_M.gguf | Q5_K_M | 4.78GB |
| FuseChat-7B-v2.0.Q5_1.gguf | Q5_1 | 5.07GB |
| FuseChat-7B-v2.0.Q6_K.gguf | Q6_K | 5.53GB |
| FuseChat-7B-v2.0.Q8_0.gguf | Q8_0 | 7.17GB |



python 3.11 in this project.requirements.txt.pip install -r requirements.txt1import transformers
2tokenizer = transformers.AutoTokenizer.from_pretrained("FuseAI/FuseChat-7B-v2.0")
3# Single-turn
4tokens = tokenizer("GPT4 Correct User: Hello<|end_of_turn|>GPT4 Correct Assistant:").input_ids
5assert tokens == [1, 420, 6316, 28781, 3198, 3123, 1247, 28747, 22557, 32000, 420, 6316, 28781, 3198, 3123, 21631, 28747]
6# Multi-turn
7tokens = 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
8assert 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]tokenizer.chat_template, which can be used instead of manually specifying the template:1messages = [
2 {"role": "user", "content": "Hello"},
3 {"role": "assistant", "content": "Hi"},
4 {"role": "user", "content": "How are you today?"}
5]
6tokens = tokenizer.apply_chat_template(messages, add_generation_prompt=True)
7assert 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]| Model | Model size | Chat Template |
|---|---|---|
| openchat_3.5/Starling-LM-7B-alpha | 7B | openchat_3.5 |
| Mistral/Mixtral | 7B/8x7B/8x22B | mistral |
| Llama 3/Llama 3.1 | 8B/70B | llama-3 |
| Gemma/Gemma 2/CodeGemma | 2B/7B/9B/27B | gemma |
| Phi-3 | 4B/7B/14B | phi-3 |
| Qwen1.5/Qwen2 | 0.5B/1.5B/4B/7B/14B/32B/72B/110B | qwen |
| InternLM2/InternLM2.5 | 7B/20B | internlm2 |
| Yi/Yi-1.5 | 6B/9B/34B | yi |
register_conv_template to add a new one.register_model_adapter to add a new one.preprocess() Function in train.py./models before experiments.data/fusechat_v1_clean_split_2048_filter_wrong.json before experiments.1# We split the dataset into 4 splits, then process each split on one or multiple GPUs.
2# OpenChat-3.5-7B Starling-LM-7B-alpha Nous-Hermes-2-SOLAR-10.7B internlm2-chat-20b Mixtral-8x7B-Instruct-v0.1 Qwen1.5-72B-Chat
3export CUDA_VISIBLE_DEVICES=0 # specify one or multiple GPUs
4PROJ_PATH=FuseChat # specify your own project path
5DATA_NAME="fusechat_v1_clean_split_2048_filter_wrong"
6MODEL_NAME=openchat_3.5 # model to get representation
7CONV_TEMP=openchat_3.5 # conversation template, should be the same for all models, see more template names in train/conversation.py
8
9for i in {0..3}; do
10python ${PROJ_PATH}/train/get_data_representation.py \
11 --model_name_or_path ${PROJ_PATH}/models/${MODEL_NAME} \
12 --data_path ${PROJ_PATH}/data/${DATA_NAME}.json \
13 --dataset_save_dir ${PROJ_PATH}/representations/${MODEL_NAME}_representation_split${i} \
14 --tknz_dataset_path ${PROJ_PATH}/representations/${MODEL_NAME}_representation_tknz_split${i} \
15 --cache_dir ${PROJ_PATH}/.cache/huggingface/datasets \
16 --model_max_length 2048 \
17 --load_in_half bf16 \
18 --batch_size 32 \
19 --top_k_logits 10 \
20 --save_per_token_metric \
21 --no_assert \
22 --conv_temp ${CONV_TEMP} \
23 --mask_instruction \
24 --dataset_split_num 4 \
25 --dataset_index ${i} \
26 --get_representation \
27 --device_map "auto"
28done1# Pivot LLM:OpenChat-3.5-7B <-> Source LLMs: Starling-LM-7B-alpha Nous-Hermes-2-SOLAR-10.7B Mixtral-8x7B-Instruct-v0.1
2PROJ_PATH=FuseChat # specify your own project path
3PIVOT_NAME=openchat_3.5 # Pivot LLM
4SOURCE_NAME=Starling-LM-7B-alpha # Source LLMs with the same vocab as Pivot
5
6for i in {0..3}; do
7python ${PROJ_PATH}/train/replace_model.py \
8 --dataset_dir ${PROJ_PATH}/representations/${PIVOT_NAME}_representation_split${i} \
9 --replace_dataset_dir ${PROJ_PATH}/representations/${SOURCE_NAME}_representation_split${i} \
10 --dataset_save_dir ${PROJ_PATH}/representations/${PIVOT_NAME}_${SOURCE_NAME}_representation_split${i} \
11 --preprocessing_num_workers 32 \
12 --batch_size 1000
13done1# Pivot LLM:OpenChat-3.5-7B <->Source LLMs: internlm2-chat-20b Qwen1.5-72B-Chat
2PROJ_PATH=FuseChat # specify your own project path
3PIVOT_NAME=openchat_3.5 # Pivot LLM
4SOURCE_NAME=internlm2-chat-20b # Source LLMs have different vocab with Pivot
5align_type="default" # different alignment method hard -> EM, soft -> MinED, default -> MS
6token_alignment_matrix_file=${PROJ_PATH}/aligned_representations/${PIVOT_NAME}_${SOURCE_NAME}_token_sparse_matrix_${align_type}.npz
7blending_to_base_file=${PROJ_PATH}/aligned_representations/${PIVOT_NAME}_${SOURCE_NAME}_token_mapping_${align_type}.json
8
9# token alignment
10python ${PROJ_PATH}/train/align_token_and_vocab.py \
11 --align_type ${align_type} \
12 --base_model_name_or_path ${PROJ_PATH}/models/${PIVOT_NAME} \
13 --blending_model_name_or_path ${PROJ_PATH}/models/${SOURCE_NAME} \
14 --base_dataset_dir "${PROJ_PATH}/representations/${PIVOT_NAME}_representation_tknz_split0,${PROJ_PATH}/representations/${PIVOT_NAME}_representation_tknz_split1,${PROJ_PATH}/representations/${PIVOT_NAME}_representation_tknz_split2,${PROJ_PATH}/representations/${PIVOT_NAME}_representation_tknz_split3" \
15 --blending_dataset_dir "${PROJ_PATH}/representations/${SOURCE_NAME}_representation_tknz_split0,${PROJ_PATH}/representations/${SOURCE_NAME}_representation_tknz_split1,${PROJ_PATH}/representations/${SOURCE_NAME}_representation_tknz_split2,${PROJ_PATH}/representations/${SOURCE_NAME}_representation_tknz_split3" \
16 --aligned_dataset_tknz_save_dir ${PROJ_PATH}/aligned_representations/${PIVOT_NAME}_${SOURCE_NAME}_representation_tknz \
17 --model_max_length 2048 \
18 --preprocessing_num_workers 32 \
19 --batch_size 16 \
20 --token_alignment_matrix_file ${token_alignment_matrix_file} \
21 --blending_to_base_file ${blending_to_base_file} \
22 --do_token_alignment \
23 --metric_level "sequence" \
24 --use_token_alignment_matrix
25
26# distribution alignment
27for i in {0..3}; do
28python ${PROJ_PATH}/train/align_token_and_vocab.py \
29 --align_type ${align_type} \
30 --base_model_name_or_path ${PROJ_PATH}/models/${PIVOT_NAME} \
31 --blending_model_name_or_path ${PROJ_PATH}/models/${SOURCE_NAME} \
32 --base_dataset_dir ${PROJ_PATH}/representations/${PIVOT_NAME}_representation_split${i} \
33 --blending_dataset_dir ${PROJ_PATH}/representations/${SOURCE_NAME}_representation_split${i} \
34 --aligned_dataset_save_dir ${PROJ_PATH}/aligned_representations/${PIVOT_NAME}_${SOURCE_NAME}_representation_split${i} \
35 --model_max_length 2048 \
36 --preprocessing_num_workers 32 \
37 --batch_size 16 \
38 --temperature 0.5 \
39 --token_alignment_matrix_file ${token_alignment_matrix_file} \
40 --blending_to_base_file ${blending_to_base_file} \
41 --do_distribution_alignment \
42 --metric_level "sequence" \
43 --use_token_alignment_matrix
44done1for i in {0..3}; do
2python ${PROJ_PATH}/train/filter_nan.py \
3 --input_data_dir ${PROJ_PATH}/aligned_representations/${PIVOT_NAME}_${SOURCE_NAME}_representation_split${i} \
4 --output_data_dir ${PROJ_PATH}/aligned_representations/${PIVOT_NAME}_${SOURCE_NAME}_representation_split${i}_fnan \
5done${PROJ_PATH}/aligned_representations/${PIVOT_NAME}_${SOURCE_NAME}_representation_split${i}_fnan1# OpenChat-3.5-7B <-> Starling-LM-7B-alpha Nous-Hermes-2-SOLAR-10.7B internlm2-chat-20b Mixtral-8x7B-Instruct-v0.1 Qwen1.5-72B-Chat
2export CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7
3torchrun --nproc_per_node=8 --master_port=20001 ${PROJ_PATH}/train/train.py \
4 --model_name_or_path "openchat/openchat_3.5" \
5 --data_path "${PROJ_PATH}/aligned_representations/${PIVOT_NAME}_${SOURCE_NAME}_representation_split0_fnan,${PROJ_PATH}/aligned_representations/${PIVOT_NAME}_${SOURCE_NAME}_representation_split1_fnan,${PROJ_PATH}/aligned_representations/${PIVOT_NAME}_${SOURCE_NAME}_representation_split2_fnan,${PROJ_PATH}/aligned_representations/${PIVOT_NAME}_${SOURCE_NAME}_representation_split3_fnan" \
6 --bf16 True \
7 --output_dir "${PROJ_PATH}/checkpoints/${PIVOT_NAME}_${SOURCE_NAME}_pairwise_fusion_ckpt" \
8 --num_train_epochs 3 \
9 --per_device_train_batch_size 4 \
10 --per_device_eval_batch_size 4 \
11 --gradient_accumulation_steps 4 \
12 --evaluation_strategy "no" \
13 --save_strategy "epoch" \
14 --save_steps 10000 \
15 --save_total_limit 5 \
16 --learning_rate 5e-6 \
17 --weight_decay 0. \
18 --warmup_ratio 0.03 \
19 --lr_scheduler_type "cosine" \
20 --logging_steps 1 \
21 --fsdp "full_shard auto_wrap" \
22 --fsdp_transformer_layer_cls_to_wrap 'MistralDecoderLayer' \
23 --tf32 True \
24 --model_max_length 2048 \
25 --gradient_checkpointing True \
26 --conv_temp "openchat_3.5" \
27 --lazy_preprocess True \
28 --flash_attn_transformers True \
29 --do_train \
30 --do_fuse \
31 --fuse_with_ref_model True \
32 --fuse_loss_type "ce" \
33 --fuse_temperature 1.0 \
34 --lm_loss_weight 0.9 \
35 --dataloader_num_workers 8 \
36 --remove_unused_columns False1cd mergekit
2pip install -e .mergekit/mergekit/merge_methods/sce_merging.py.1model_save_dir=xx # specify your path to save the merged models
2mergekit-yaml mergekit/fusechat_configs/fusechat-sce.yml ${model_save_dir}/FuseChat-7B-SCE1model_save_dir=xx # your path to save the merged models
2mergekit-yaml mergekit/fusechat_configs/fusechat-linear.yml ${model_save_dir}/FuseChat-7B-LINEAR
3
4mergekit-yaml mergekit/fusechat_configs/fusechat-ta.yml ${model_save_dir}/FuseChat-7B-TA
5
6mergekit-yaml mergekit/fusechat_configs/fusechat-ties.yml ${model_save_dir}/FuseChat-7B-TIES
7
8mergekit-yaml mergekit/fusechat_configs/fusechat-dare.yml ${model_save_dir}/FuseChat-7B-DAREllm_judge/data/mt_bench/reference_answer. Then, add "gpt-4-0125-preview" as a valid judge model in common.py.1# Step 1. Generate model answers to MT-bench questions
2export CUDA_VISIBLE_DEVICES=0,1
3python gen_model_answer.py \
4 --model-path "FuseChat-7B-v2.0" \
5 --model-id "openchat_3.5_fusechat_7b_sce" \
6 --num-gpus-per-model 1 \
7 --num-gpus-total 2
8
9# Step 2. Generate GPT-4-0125-Preview judgments
10export OPENAI_API_KEY=XXXXXX # set the OpenAI API key
11python gen_judgment.py \
12 --model-list "openchat_3.5_fusechat_7b_sce" \
13 --judge-model "gpt-4-0125-preview" \
14 --parallel 8
15
16# Step 3. Show MT-bench scores
17python show_result.py --model-list "openchat_3.5_fusechat_7b_sce" alpaca_eval_gpt4_turbo_fn for evaluation. The prompt for generation is:GPT4 Correct User: {instruction}<|end_of_turn|>GPT4 Correct Assistant: @article{wan2024fusechat,
title={FuseChat: Knowledge Fusion of Chat Models},
author={Fanqi Wan and Longguang Zhong and Ziyi Yang and Ruijun Chen and Xiaojun Quan},
journal={arXiv preprint arXiv:2408.07990},
year={2024}
}