Views
No views yet



python 3.11 in this project.requirements.txt.pip install -r requirements.txt1import transformers
2tokenizer = transformers.AutoTokenizer.from_pretrained("FuseAI/FuseChat-7B-VaRM")
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]1# We split the dataset into 4 splits, then process each split on one or multiple GPU.
2
3# OpenChat-3.5-7B
4export CUDA_VISIBLE_DEVICES=0
5for i in {0..3}; do
6python /train/get_data_representation.py \
7 --model_name_or_path "openchat/openchat_3.5" \
8 --data_path "/data/fusechat_v1_clean_split_2048_filter_wrong.json" \
9 --dataset_save_dir "<${i}_4_path_to_openchat_representation>" \
10 --tknz_dataset_path "<${i}_4_path_to_openchat_tknz>" \
11 --cache_dir "/.cache/huggingface/datasets" \
12 --model_max_length 2048 \
13 --load_in_half bf16 \
14 --batch_size 32 \
15 --top_k_logits 10 \
16 --save_per_token_metric \
17 --no_assert \
18 --conv_temp "openchat" \
19 --flash_attn_transformers \
20 --mask_instruction \
21 --dataset_split_num 4 \
22 --dataset_index ${i}
23done
24
25# NH2-Mixtral-8x7B
26export CUDA_VISIBLE_DEVICES=0,1,2
27for i in {0..3}; do
28python /train/get_data_representation.py \
29 --model_name_or_path "NousResearch/Nous-Hermes-2-Mixtral-8x7B-DPO" \
30 --data_path "/data/fusechat_v1_clean_split_2048_filter_wrong.json" \
31 --dataset_save_dir "<${i}_4_path_to_mixtral_representation>" \
32 --tknz_dataset_path "<${i}_4_path_to_mixtral_tknz>" \
33 --cache_dir "/.cache/huggingface/datasets" \
34 --model_max_length 2048 \
35 --load_in_half bf16 \
36 --batch_size 4 \
37 --top_k_logits 10 \
38 --save_per_token_metric \
39 --no_assert \
40 --conv_temp "openchat" \
41 --flash_attn_transformers \
42 --mask_instruction \
43 --device_map "auto" \
44 --dataset_split_num 4 \
45 --dataset_index ${i}
46done
47
48# NH2-Solar-10.7B
49export CUDA_VISIBLE_DEVICES=0
50for i in {0..3}; do
51python /train/get_data_representation.py \
52 --model_name_or_path "NousResearch/Nous-Hermes-2-SOLAR-10.7B" \
53 --data_path "/data/fusechat_v1_clean_split_2048_filter_wrong.json" \
54 --dataset_save_dir "<${i}_4_path_to_solar_representation>" \
55 --tknz_dataset_path "<${i}_4_path_to_solar_tknz>" \
56 --cache_dir "/.cache/huggingface/datasets" \
57 --model_max_length 2048 \
58 --load_in_half bf16 \
59 --batch_size 8 \
60 --top_k_logits 10 \
61 --save_per_token_metric \
62 --no_assert \
63 --conv_temp "openchat" \
64 --flash_attn_transformers \
65 --mask_instruction \
66 --dataset_split_num 4 \
67 --dataset_index ${i}
68done 1# Since the tokenizers and vocabularies of these source LLMs are identical, we do not align.
2
3# OpenChat-3.5-7B <-> NH2-Mixtral-8x7B
4for i in {0..3}; do
5python /train/replace_model.py \
6 --dataset_dir "<${i}_4_path_to_openchat_representation>" \
7 --replace_dataset_dir "<${i}_4_path_to_mixtral_representation>" \
8 --dataset_save_dir "<${i}_4_path_to_openchat_mixtral_representation>" \
9 --preprocessing_num_workers 64 \
10 --batch_size 1000 \
11 --replace_model model_0
12done
13
14# OpenChat-3.5-7B <-> NH2-Solar-10.7B
15for i in {0..3}; do
16python /train/replace_model.py \
17 --dataset_dir "<${i}_4_path_to_openchat_mixtral_representation>" \
18 --replace_dataset_dir "<${i}_4_path_to_solar_representation>" \
19 --dataset_save_dir "<${i}_4_path_to_openchat_mixtral_solar_representation>" \
20 --preprocessing_num_workers 64 \
21 --batch_size 1000 \
22 --replace_model model_1
23done1for i in {0..3}; do
2python /train/filter_nan.py \
3 --input_data_dir "<${i}_4_path_to_openchat_mixtral_solar_representation>" \
4 --output_data_dir "<${i}_4_path_to_openchat_mixtral_solar_representation_fnan>"
5done<${i}_4_path_to_openchat_mixtral_solar_representation_fnan>.1# OpenChat-3.5-7B <-> NH2-Mixtral-8x7B
2export CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7
3torchrun --nproc_per_node=8 --master_port=20001 /train/train.py \
4 --model_name_or_path "openchat/openchat_3.5" \
5 --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>" \
6 --bf16 True \
7 --output_dir "<path_to_save_openchat_mixtral_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" \
27 --lazy_preprocess True \
28 --flash_attn_transformers True \
29 --do_train \
30 --do_distill \
31 --distill_with_ref_model True \
32 --distill_with_aligned_model_0 True \
33 --distill_with_aligned_model_1 False \
34 --distill_loss_type "ce" \
35 --distill_teacher_temperature 1.0 \
36 --lm_loss_weight 0.9 \
37 --distill_greater_as_gt True \
38 --distill_greater_as_gt_type hard \
39 --dataloader_num_workers 8 \
40 --remove_unused_columns False
41
42# OpenChat-3.5-7B <-> NH2-Solar-10.7B
43export CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7
44torchrun --nproc_per_node=8 --master_port=20001 /train/train.py \
45 --model_name_or_path "openchat/openchat_3.5" \
46 --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>" \
47 --bf16 True \
48 --output_dir "<path_to_save_openchat_solar_ckpt>" \
49 --num_train_epochs 3 \
50 --per_device_train_batch_size 4 \
51 --per_device_eval_batch_size 4 \
52 --gradient_accumulation_steps 4 \
53 --evaluation_strategy "no" \
54 --save_strategy "epoch" \
55 --save_steps 10000 \
56 --save_total_limit 5 \
57 --learning_rate 5e-6 \
58 --weight_decay 0. \
59 --warmup_ratio 0.03 \
60 --lr_scheduler_type "cosine" \
61 --logging_steps 1 \
62 --fsdp "full_shard auto_wrap" \
63 --fsdp_transformer_layer_cls_to_wrap 'MistralDecoderLayer' \
64 --tf32 True \
65 --model_max_length 2048 \
66 --gradient_checkpointing True \
67 --conv_temp "openchat" \
68 --lazy_preprocess True \
69 --flash_attn_transformers True \
70 --do_train \
71 --do_distill \
72 --distill_with_ref_model True \
73 --distill_with_aligned_model_0 False \
74 --distill_with_aligned_model_1 True \
75 --distill_loss_type "ce" \
76 --distill_teacher_temperature 1.0 \
77 --lm_loss_weight 0.9 \
78 --distill_greater_as_gt True \
79 --distill_greater_as_gt_type hard \
80 --dataloader_num_workers 8 \
81 --remove_unused_columns False1# For "slerp", "ta", "ties", and "dare" methods
2export CUDA_VISIBLE_DEVICES=0
3mergekit-yaml merge/mergekit_configs/fusechat-slerp.yml "<path_to_save_fusechat_7b_slerp>"
4mergekit-yaml merge/mergekit_configs/fusechat-ta.yml "<path_to_save_fusechat_7b_ta>"
5mergekit-yaml merge/mergekit_configs/fusechat-ties.yml "<path_to_save_fusechat_7b_ties>"
6mergekit-yaml merge/mergekit_configs/fusechat-dare.yml "<path_to_save_fusechat_7b_dare>"
7
8# For "linear" method
9python merge/VaRM/merge.py \
10 --merged_model_names "FuseAI/OpenChat-3.5-7B-Mixtral,FuseAI/OpenChat-3.5-7B-Solar" \
11 --merged_model_save_dir "<path_to_save_fusechat_7b_linear>" \
12 --merge_method "linear" \
13 --linear_weights "1,2"
14
15# For our "varm" method
16python merge/VaRM/analysis.py \
17 --model1_path "FuseAI/OpenChat-3.5-7B-Mixtral" \
18 --model2_path "FuseAI/OpenChat-3.5-7B-Solar" \
19 --save_path "<path_to_save_analysis_result>/analysis.json" \
20 --merge_type "square"
21
22python merge/VaRM/merge.py \
23 --merged_model_names "FuseAI/OpenChat-3.5-7B-Mixtral,FuseAI/OpenChat-3.5-7B-Solar" \
24 --analysis_result "<path_to_save_analysis_result>/analysis.json" \
25 --merged_model_save_dir "<path_to_save_fusechat_7b_varm>" \
26 --merge_method "avg_param" \
27 --merge_type "square"1# Step 1. Generate model answers to MT-bench questions
2export CUDA_VISIBLE_DEVICES=0,1
3python gen_model_answer.py \
4 --model-path "FuseAI/FuseChat-7B-VaRM" \
5 --model-id "openchat_3.5_fusechat_7b_varm" \
6 --num-gpus-per-model 1 \
7 --num-gpus-total 2
8
9# Step 2. Generate GPT-4 judgments
10export OPENAI_API_KEY=XXXXXX # set the OpenAI API key
11python gen_judgment.py \
12 --parallel 2
13
14# Step 3. Show MT-bench scores
15python show_result.py@article{wan2024fusechat,
title={FuseChat: Knowledge Fusion of Chat Models},
author={Fanqi Wan and Ziyi Yang and Longguang Zhong and Xiaojun Quan and Xinting Huang and Wei Bi},
journal={arXiv preprint arXiv:2402.16107},
year={2024}
}