diff --git a/docs/resources/asyncengine.png b/docs/resources/asyncengine.png new file mode 100644 index 0000000000000000000000000000000000000000..7c2575c7f83371836505f27cc697bfc29a111e8b --- /dev/null +++ b/docs/resources/asyncengine.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e45caf4012a44fd1065d11971fb9fcf7730a18e7ee97fc2455d35fc33229e07b +size 955891 diff --git a/docs/resources/deepeyes.png b/docs/resources/deepeyes.png new file mode 100644 index 0000000000000000000000000000000000000000..670e7b103758c104e9ffd8f91ff8cf00bb052c4e --- /dev/null +++ b/docs/resources/deepeyes.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c36883b9e3ec0c5c104959e2d51558b5ff25678cf7c9916391631aa9692023da +size 873516 diff --git a/docs/resources/dpo_data.png b/docs/resources/dpo_data.png new file mode 100644 index 0000000000000000000000000000000000000000..9fc359fbfcfb744418a97806318c24daf22e5566 --- /dev/null +++ b/docs/resources/dpo_data.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8d87ca58f3ac43a79836ba40f5d9cb788b8fabc26d717fb4e8eb1f1400f6598d +size 354747 diff --git a/docs/resources/grpo.png b/docs/resources/grpo.png new file mode 100644 index 0000000000000000000000000000000000000000..2b4967bf785e1103ff63a87864d9dea7bfd5f25f --- /dev/null +++ b/docs/resources/grpo.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1205d144192ae04901251d52b23424451bb2dece97399bbcdd3ce31671579305 +size 30632 diff --git a/docs/resources/grpo_clevr_count.png b/docs/resources/grpo_clevr_count.png new file mode 100644 index 0000000000000000000000000000000000000000..2c814e28e31908a7250220fde18b5bd024d82b35 --- /dev/null +++ b/docs/resources/grpo_clevr_count.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7192dc4f04801dbdff30bed098a16a7e21212a773ba7b6dc1424b261feca366f +size 671176 diff --git a/docs/resources/grpo_code.png b/docs/resources/grpo_code.png new file mode 100644 index 0000000000000000000000000000000000000000..021f8d996b8b376a75e38dae8dc27226098c90a3 --- /dev/null +++ b/docs/resources/grpo_code.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5f396d9ce5ce9de323d7a6ffa8d53f783d938a242088b191f46a293268193b64 +size 294339 diff --git a/docs/resources/grpo_countdown.png b/docs/resources/grpo_countdown.png new file mode 100644 index 0000000000000000000000000000000000000000..af2ce0c0ce08cb3d8b152f6bafe2c15c056dcd72 --- /dev/null +++ b/docs/resources/grpo_countdown.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1b55fe6864e0c92549940d6989d92b3ab22be38a035cff3694525252737fc91e +size 2226402 diff --git a/docs/resources/grpo_countdown_1.png b/docs/resources/grpo_countdown_1.png new file mode 100644 index 0000000000000000000000000000000000000000..819ab3d992619b077d75e6946d4637b030b8d213 --- /dev/null +++ b/docs/resources/grpo_countdown_1.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b78dc3ce1cd541e76f2c557dea3aff06b278bb3b5413946a92c584cf42c1369f +size 785044 diff --git a/docs/resources/grpo_geoqa.png b/docs/resources/grpo_geoqa.png new file mode 100644 index 0000000000000000000000000000000000000000..071d9b8eacb301bd96e30c2eff1471e68a7632a8 --- /dev/null +++ b/docs/resources/grpo_geoqa.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:71246376b16f2ff288542dca2ff31532b16ef99f5e862797463d548e447e1f8d +size 2238084 diff --git a/docs/resources/grpo_multi_turn.png b/docs/resources/grpo_multi_turn.png new file mode 100644 index 0000000000000000000000000000000000000000..c19cd9ecaf8a38e67f38a53c9a7b931dedd49491 --- /dev/null +++ b/docs/resources/grpo_multi_turn.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:25804a46bf35f8925348064edd8e3fcee501fa95a6cebf45ef1ae0d1cdd6dc02 +size 1519176 diff --git a/docs/resources/grpo_openr1_multimodal.png b/docs/resources/grpo_openr1_multimodal.png new file mode 100644 index 0000000000000000000000000000000000000000..5d91a327b58283acf43de08cbdbdae59a8bca7c3 --- /dev/null +++ b/docs/resources/grpo_openr1_multimodal.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:050f56792468a4c9797a90314e322c16dd916bde3be24a7ce7c7b96381e70d9e +size 2302511 diff --git a/docs/resources/gym_env.png b/docs/resources/gym_env.png new file mode 100644 index 0000000000000000000000000000000000000000..e0d3c16e389b1619943fe2d029fe2ea3ed3e0002 --- /dev/null +++ b/docs/resources/gym_env.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3e5b9827992d1b432fd3b9ff749efe7da01032afce574f5c22c0467c6888450a +size 203107 diff --git a/docs/resources/kto_data.png b/docs/resources/kto_data.png new file mode 100644 index 0000000000000000000000000000000000000000..761ff05fa2151a1d57c8a01179d09be169c9397f --- /dev/null +++ b/docs/resources/kto_data.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:becb20db8a8b890718f3f9e1752dc6669a018ed19a344f155fbe5123521aff49 +size 163811 diff --git a/docs/resources/multiturn_pipeline.png b/docs/resources/multiturn_pipeline.png new file mode 100644 index 0000000000000000000000000000000000000000..c5e53534095994a109e427e6339bb59bfde6968e --- /dev/null +++ b/docs/resources/multiturn_pipeline.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f8c1565822f749f6531bc28b3e854f0066fcf0ae44038a3364ca7d222312bc55 +size 203087 diff --git a/docs/resources/web-ui-en.jpg b/docs/resources/web-ui-en.jpg new file mode 100644 index 0000000000000000000000000000000000000000..2c1c15d1e3e769a276c85dbda5821b4adaf33d1f --- /dev/null +++ b/docs/resources/web-ui-en.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6ad958b680650b4f900f1a99560e825975f1a5807702c6fbbaef8e4f0e2a5efe +size 175371 diff --git a/docs/resources/web-ui.jpg b/docs/resources/web-ui.jpg new file mode 100644 index 0000000000000000000000000000000000000000..1a8a42f1d97d9cda57ccaa283f34ba6ede308027 --- /dev/null +++ b/docs/resources/web-ui.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5e83bb4b4ecda9386286b99c6e83551f1dd1fdcdaf7be2efa3117208e3806000 +size 181923 diff --git a/examples/train/multimodal/ocr.sh b/examples/train/multimodal/ocr.sh new file mode 100644 index 0000000000000000000000000000000000000000..5a9aa9f64f141da9b97a785aba68bee4820752bd --- /dev/null +++ b/examples/train/multimodal/ocr.sh @@ -0,0 +1,27 @@ +# 20GB +CUDA_VISIBLE_DEVICES=0 \ +MAX_PIXELS=1003520 \ +swift sft \ + --model Qwen/Qwen2.5-VL-7B-Instruct \ + --dataset 'AI-ModelScope/LaTeX_OCR:human_handwrite#20000' \ + --load_from_cache_file true \ + --split_dataset_ratio 0.01 \ + --train_type lora \ + --torch_dtype bfloat16 \ + --num_train_epochs 1 \ + --per_device_train_batch_size 1 \ + --per_device_eval_batch_size 1 \ + --learning_rate 1e-4 \ + --lora_rank 8 \ + --lora_alpha 32 \ + --target_modules all-linear \ + --freeze_vit true \ + --gradient_accumulation_steps 16 \ + --eval_steps 50 \ + --save_steps 50 \ + --save_total_limit 2 \ + --logging_steps 5 \ + --max_length 4096 \ + --output_dir output \ + --warmup_ratio 0.05 \ + --dataloader_num_workers 4 diff --git a/examples/train/multimodal/omni/infer.sh b/examples/train/multimodal/omni/infer.sh new file mode 100644 index 0000000000000000000000000000000000000000..6affc476ef1b54ec5000e745996b79b9310374eb --- /dev/null +++ b/examples/train/multimodal/omni/infer.sh @@ -0,0 +1,10 @@ +CUDA_VISIBLE_DEVICES=0 \ +VIDEO_MAX_PIXELS=50176 \ +FPS_MAX_FRAMES=12 \ +MAX_PIXELS=1003520 \ +ENABLE_AUDIO_OUTPUT=0 \ +swift infer \ + --adapters output/vx-xxx/checkpoint-xxx \ + --stream true \ + --load_data_args true \ + --max_new_tokens 2048 diff --git a/examples/train/multimodal/omni/sft.sh b/examples/train/multimodal/omni/sft.sh new file mode 100644 index 0000000000000000000000000000000000000000..25885347049fcc5a643c8809f205d21f122b3a56 --- /dev/null +++ b/examples/train/multimodal/omni/sft.sh @@ -0,0 +1,39 @@ +# 4*35GB +# A demo for four modalities that can be run directly +nproc_per_node=4 + +# If using zero3, please set `ENABLE_AUDIO_OUTPUT=0`. +CUDA_VISIBLE_DEVICES=0,1,2,3 \ +ENABLE_AUDIO_OUTPUT=1 \ +NPROC_PER_NODE=$nproc_per_node \ +VIDEO_MAX_PIXELS=50176 \ +FPS_MAX_FRAMES=12 \ +MAX_PIXELS=1003520 \ +swift sft \ + --model Qwen/Qwen2.5-Omni-7B \ + --dataset 'AI-ModelScope/alpaca-gpt4-data-zh#2000' \ + 'AI-ModelScope/LaTeX_OCR:human_handwrite#2000' \ + 'speech_asr/speech_asr_aishell1_trainsets:validation#2000' \ + 'swift/VideoChatGPT:all#2000' \ + --load_from_cache_file true \ + --split_dataset_ratio 0.01 \ + --train_type lora \ + --torch_dtype bfloat16 \ + --num_train_epochs 1 \ + --per_device_train_batch_size 1 \ + --per_device_eval_batch_size 1 \ + --learning_rate 1e-4 \ + --lora_rank 8 \ + --lora_alpha 32 \ + --target_modules all-linear \ + --freeze_vit true \ + --gradient_accumulation_steps $(expr 16 / $nproc_per_node) \ + --eval_steps 50 \ + --save_steps 50 \ + --save_total_limit 2 \ + --logging_steps 5 \ + --max_length 2048 \ + --output_dir output \ + --warmup_ratio 0.05 \ + --dataloader_num_workers 4 \ + --deepspeed zero2 diff --git a/examples/train/multimodal/rlhf/dpo/full.sh b/examples/train/multimodal/rlhf/dpo/full.sh new file mode 100644 index 0000000000000000000000000000000000000000..a6fd45b70c47fcb7017decd85dd0a4d72d3b5128 --- /dev/null +++ b/examples/train/multimodal/rlhf/dpo/full.sh @@ -0,0 +1,32 @@ +# 4 * 50GiB +nproc_per_node=4 + +PYTORCH_CUDA_ALLOC_CONF='expandable_segments:True' \ +CUDA_VISIBLE_DEVICES=0,1,2,3 \ +NPROC_PER_NODE=$nproc_per_node \ +MAX_PIXELS=1003520 \ +swift rlhf \ + --rlhf_type dpo \ + --model Qwen/Qwen2.5-VL-7B-Instruct \ + --dataset 'swift/RLAIF-V-Dataset#20000' \ + --load_from_cache_file true \ + --split_dataset_ratio 0.01 \ + --train_type full \ + --torch_dtype bfloat16 \ + --num_train_epochs 1 \ + --per_device_train_batch_size 1 \ + --per_device_eval_batch_size 1 \ + --learning_rate 1e-5 \ + --freeze_vit true \ + --gradient_accumulation_steps $(expr 16 / $nproc_per_node) \ + --eval_steps 100 \ + --save_steps 100 \ + --save_total_limit 2 \ + --deepspeed zero3 \ + --logging_steps 5 \ + --max_length 4096 \ + --output_dir output \ + --warmup_ratio 0.05 \ + --dataloader_num_workers 4 \ + --dataset_num_proc 4 \ + --save_only_model true diff --git a/examples/train/multimodal/rlhf/dpo/lora.sh b/examples/train/multimodal/rlhf/dpo/lora.sh new file mode 100644 index 0000000000000000000000000000000000000000..f62d43488c5140aa5b1e8fd7ce07450605be763b --- /dev/null +++ b/examples/train/multimodal/rlhf/dpo/lora.sh @@ -0,0 +1,35 @@ +# 4 * 50GiB +# You can refer to `https://github.com/QwenLM/Qwen2.5-VL` for the meaning of the `MAX_PIXELS` parameter. +# --rlhf_type cpo/orpo/simpo/rm are also supported +nproc_per_node=2 + +CUDA_VISIBLE_DEVICES=0,1 \ +NPROC_PER_NODE=$nproc_per_node \ +MAX_PIXELS=1003520 \ +swift rlhf \ + --rlhf_type dpo \ + --model Qwen/Qwen2.5-VL-7B-Instruct \ + --dataset 'swift/RLAIF-V-Dataset#20000' \ + --load_from_cache_file true \ + --split_dataset_ratio 0.01 \ + --train_type lora \ + --torch_dtype bfloat16 \ + --num_train_epochs 1 \ + --per_device_train_batch_size 1 \ + --per_device_eval_batch_size 1 \ + --learning_rate 1e-4 \ + --lora_rank 8 \ + --lora_alpha 32 \ + --target_modules all-linear \ + --freeze_vit true \ + --gradient_accumulation_steps $(expr 16 / $nproc_per_node) \ + --eval_steps 100 \ + --save_steps 100 \ + --save_total_limit 2 \ + --deepspeed zero2 \ + --logging_steps 5 \ + --max_length 4096 \ + --output_dir output \ + --warmup_ratio 0.05 \ + --dataloader_num_workers 4 \ + --dataset_num_proc 4 diff --git a/examples/train/multimodal/rlhf/gkd/fast.sh b/examples/train/multimodal/rlhf/gkd/fast.sh new file mode 100644 index 0000000000000000000000000000000000000000..3974e0a5b355eb1eaaf70b32ff1abbab51e68074 --- /dev/null +++ b/examples/train/multimodal/rlhf/gkd/fast.sh @@ -0,0 +1,49 @@ + +export teacher_model='OpenGVLab/InternVL3-8B' + +NPROC_PER_NODE=4 \ +CUDA_VISIBLE_DEVICES=0,1,2,3 \ +swift infer \ + --model $teacher_model \ + --infer_backend vllm \ + --val_dataset 'modelscope/coco_2014_caption:validation#5000' \ + --vllm_gpu_memory_utilization 0.9 \ + --vllm_max_model_len 8192 \ + --max_new_tokens 2048 \ + --write_batch_size 1000 \ + --result_path new_coco_dataset.jsonl + + +# 4 * 42GiB, 3.05s/it +NPROC_PER_NODE=4 \ +PYTORCH_CUDA_ALLOC_CONF='expandable_segments:True' \ +CUDA_VISIBLE_DEVICES=0,1,2,3 \ +swift rlhf \ + --rlhf_type gkd \ + --model OpenGVLab/InternVL3-2B-Pretrained \ + --teacher_model $teacher_model \ + --train_type full \ + --dataset 'new_coco_dataset.jsonl' \ + --load_from_cache_file true \ + --split_dataset_ratio 0.01 \ + --torch_dtype bfloat16 \ + --num_train_epochs 1 \ + --per_device_train_batch_size 4 \ + --per_device_eval_batch_size 4 \ + --learning_rate 1e-5 \ + --freeze_vit true \ + --gradient_accumulation_steps 1 \ + --eval_steps 100 \ + --save_steps 100 \ + --save_total_limit 2 \ + --logging_steps 5 \ + --max_length 4096 \ + --output_dir output \ + --warmup_ratio 0.05 \ + --save_only_model true \ + --dataloader_num_workers 4 \ + --dataset_num_proc 4 \ + --deepspeed zero2 \ + --padding_free true \ + --attn_impl flash_attn \ + --lmbda 0 diff --git a/examples/train/multimodal/rlhf/gkd/full.sh b/examples/train/multimodal/rlhf/gkd/full.sh new file mode 100644 index 0000000000000000000000000000000000000000..140669c0499335522bc2c7f68dfd9ebe635f21b3 --- /dev/null +++ b/examples/train/multimodal/rlhf/gkd/full.sh @@ -0,0 +1,34 @@ +# 4 * 45GiB, 10.29s/it +PYTORCH_CUDA_ALLOC_CONF='expandable_segments:True' \ +CUDA_VISIBLE_DEVICES=0,1,2,3 \ +MASTER_PORT=29501 \ +NPROC_PER_NODE=4 \ +swift rlhf \ + --rlhf_type gkd \ + --model OpenGVLab/InternVL3-2B-Pretrained \ + --teacher_model OpenGVLab/InternVL3-8B \ + --dataset 'modelscope/coco_2014_caption:validation#2000' \ + --load_from_cache_file true \ + --split_dataset_ratio 0.01 \ + --train_type full \ + --seq_kd true \ + --torch_dtype bfloat16 \ + --num_train_epochs 1 \ + --per_device_train_batch_size 4 \ + --per_device_eval_batch_size 4 \ + --learning_rate 1e-5 \ + --freeze_vit true \ + --gradient_accumulation_steps 1 \ + --eval_steps 50 \ + --save_steps 50 \ + --save_total_limit 2 \ + --deepspeed zero2 \ + --attn_impl flash_attn \ + --logging_steps 5 \ + --max_length 4096 \ + --max_completion_length 512 \ + --output_dir output \ + --warmup_ratio 0.05 \ + --dataloader_num_workers 4 \ + --dataset_num_proc 4 \ + --save_only_model true diff --git a/examples/train/multimodal/rlhf/kto.sh b/examples/train/multimodal/rlhf/kto.sh new file mode 100644 index 0000000000000000000000000000000000000000..9ffc82dce7e4907edfa94e2a660a52f30f0601c4 --- /dev/null +++ b/examples/train/multimodal/rlhf/kto.sh @@ -0,0 +1,34 @@ +# Due to the absence of a multi-modal open-source dataset for kto, +# we will use a pure text kto dataset as an example here. +nproc_per_node=2 + +CUDA_VISIBLE_DEVICES=0,1 \ +NPROC_PER_NODE=$nproc_per_node \ +MAX_PIXELS=1003520 \ +swift rlhf \ + --rlhf_type kto \ + --model Qwen/Qwen2.5-VL-7B-Instruct \ + --dataset 'AI-ModelScope/ultrafeedback-binarized-preferences-cleaned-kto#10000' \ + --load_from_cache_file true \ + --split_dataset_ratio 0.01 \ + --train_type lora \ + --torch_dtype bfloat16 \ + --num_train_epochs 1 \ + --per_device_train_batch_size 1 \ + --per_device_eval_batch_size 1 \ + --learning_rate 1e-4 \ + --lora_rank 8 \ + --lora_alpha 32 \ + --target_modules all-linear \ + --freeze_vit true \ + --gradient_accumulation_steps $(expr 16 / $nproc_per_node) \ + --eval_steps 100 \ + --save_steps 100 \ + --save_total_limit 2 \ + --deepspeed zero2 \ + --logging_steps 5 \ + --max_length 4096 \ + --output_dir output \ + --warmup_ratio 0.05 \ + --dataloader_num_workers 4 \ + --dataset_num_proc 4 diff --git a/examples/train/multimodal/video.sh b/examples/train/multimodal/video.sh new file mode 100644 index 0000000000000000000000000000000000000000..06aab657be66269f4a2b18f5b3e2ebdcfcbdc555 --- /dev/null +++ b/examples/train/multimodal/video.sh @@ -0,0 +1,33 @@ +# 2*24GB +# You can refer to `https://github.com/QwenLM/Qwen2.5-VL` for the meaning of the `VIDEO_MAX_PIXELS` parameter. +nproc_per_node=2 + +CUDA_VISIBLE_DEVICES=0,1 \ +NPROC_PER_NODE=$nproc_per_node \ +VIDEO_MAX_PIXELS=50176 \ +FPS_MAX_FRAMES=12 \ +swift sft \ + --model Qwen/Qwen2.5-VL-7B-Instruct \ + --dataset swift/VideoChatGPT:all \ + --load_from_cache_file true \ + --split_dataset_ratio 0.01 \ + --train_type lora \ + --torch_dtype bfloat16 \ + --num_train_epochs 1 \ + --per_device_train_batch_size 1 \ + --per_device_eval_batch_size 1 \ + --learning_rate 1e-4 \ + --lora_rank 8 \ + --lora_alpha 32 \ + --target_modules all-linear \ + --freeze_vit true \ + --gradient_accumulation_steps $(expr 16 / $nproc_per_node) \ + --eval_steps 50 \ + --save_steps 50 \ + --save_total_limit 2 \ + --logging_steps 5 \ + --max_length 2048 \ + --output_dir output \ + --warmup_ratio 0.05 \ + --dataloader_num_workers 4 \ + --deepspeed zero2 diff --git a/examples/train/multimodal/vit_gradient_checkpointing.sh b/examples/train/multimodal/vit_gradient_checkpointing.sh new file mode 100644 index 0000000000000000000000000000000000000000..7a4d03a20542961e889ca28fd895fb50b8a58fdd --- /dev/null +++ b/examples/train/multimodal/vit_gradient_checkpointing.sh @@ -0,0 +1,37 @@ +# gc true, vgc true: 48GiB, 2.45s/it +# gc true, vgc false: 62GiB 2.32s/it +# gc false, vgc true: 56GiB 2.16s/it +# gc false, vgc false: 77GiB 1.95s/it +CUDA_VISIBLE_DEVICES=0,1,2,3 \ +NPROC_PER_NODE=4 \ +VIDEO_MAX_PIXELS=50176 \ +FPS_MAX_FRAMES=12 \ +swift sft \ + --model Qwen/Qwen2.5-VL-7B-Instruct \ + --dataset swift/VideoChatGPT:all \ + --load_from_cache_file true \ + --split_dataset_ratio 0.01 \ + --train_type full \ + --torch_dtype bfloat16 \ + --num_train_epochs 1 \ + --per_device_train_batch_size 4 \ + --per_device_eval_batch_size 4 \ + --learning_rate 1e-5 \ + --freeze_vit false \ + --freeze_aligner false \ + --gradient_accumulation_steps 1 \ + --gradient_checkpointing true \ + --vit_gradient_checkpointing true \ + --eval_steps 100 \ + --save_steps 100 \ + --save_total_limit 2 \ + --logging_steps 5 \ + --max_length 2048 \ + --output_dir output \ + --warmup_ratio 0.05 \ + --dataloader_num_workers 4 \ + --deepspeed zero3 \ + --use_liger_kernel true \ + --attn_impl flash_attn \ + --padding_free true \ + --save_only_model true diff --git a/examples/train/new_special_tokens/infer.sh b/examples/train/new_special_tokens/infer.sh new file mode 100644 index 0000000000000000000000000000000000000000..9a1a829f335897a4b18c38b40efca8a3fa7563d1 --- /dev/null +++ b/examples/train/new_special_tokens/infer.sh @@ -0,0 +1,6 @@ +CUDA_VISIBLE_DEVICES=0 \ +swift infer \ + --adapters output/vx-xxx/checkpoint-xxx \ + --max_batch_size 16 \ + --load_data_args true \ + --temperature 0 diff --git a/examples/train/new_special_tokens/merge_lora.sh b/examples/train/new_special_tokens/merge_lora.sh new file mode 100644 index 0000000000000000000000000000000000000000..8c76906055da5f49e33554b3925d0c67fadefc5d --- /dev/null +++ b/examples/train/new_special_tokens/merge_lora.sh @@ -0,0 +1,13 @@ +CUDA_VISIBLE_DEVICES=0 \ +swift export \ + --adapters output/vx-xxx/checkpoint-xxx \ + --merge_lora true + + +# infer +CUDA_VISIBLE_DEVICES=0 \ +swift infer \ + --adapters output/vx-xxx/checkpoint-xxx-merged \ + --max_batch_size 16 \ + --load_data_args true \ + --temperature 0 diff --git a/examples/train/new_special_tokens/tokens.txt b/examples/train/new_special_tokens/tokens.txt new file mode 100644 index 0000000000000000000000000000000000000000..93d54b33ba4bdb2d01e326632a34868a6f811edc --- /dev/null +++ b/examples/train/new_special_tokens/tokens.txt @@ -0,0 +1,100 @@ +<|0|> +<|1|> +<|2|> +<|3|> +<|4|> +<|5|> +<|6|> +<|7|> +<|8|> +<|9|> +<|10|> +<|11|> +<|12|> +<|13|> +<|14|> +<|15|> +<|16|> +<|17|> +<|18|> +<|19|> +<|20|> +<|21|> +<|22|> +<|23|> +<|24|> +<|25|> +<|26|> +<|27|> +<|28|> +<|29|> +<|30|> +<|31|> +<|32|> +<|33|> +<|34|> +<|35|> +<|36|> +<|37|> +<|38|> +<|39|> +<|40|> +<|41|> +<|42|> +<|43|> +<|44|> +<|45|> +<|46|> +<|47|> +<|48|> +<|49|> +<|50|> +<|51|> +<|52|> +<|53|> +<|54|> +<|55|> +<|56|> +<|57|> +<|58|> +<|59|> +<|60|> +<|61|> +<|62|> +<|63|> +<|64|> +<|65|> +<|66|> +<|67|> +<|68|> +<|69|> +<|70|> +<|71|> +<|72|> +<|73|> +<|74|> +<|75|> +<|76|> +<|77|> +<|78|> +<|79|> +<|80|> +<|81|> +<|82|> +<|83|> +<|84|> +<|85|> +<|86|> +<|87|> +<|88|> +<|89|> +<|90|> +<|91|> +<|92|> +<|93|> +<|94|> +<|95|> +<|96|> +<|97|> +<|98|> +<|99|> diff --git a/examples/train/new_special_tokens/train.sh b/examples/train/new_special_tokens/train.sh new file mode 100644 index 0000000000000000000000000000000000000000..62dc9c2512b50dddbbc45e883c76553f3ae11e2d --- /dev/null +++ b/examples/train/new_special_tokens/train.sh @@ -0,0 +1,31 @@ +# 4 * 26GB +# This example is just a demo showing how to add new_special_tokens. +NPROC_PER_NODE=4 \ +CUDA_VISIBLE_DEVICES=0,1,2,3 \ +swift sft \ + --model Qwen/Qwen2.5-7B-Instruct \ + --train_type lora \ + --dataset 'swift/new_special_tokens' \ + --split_dataset_ratio 0.01 \ + --new_special_tokens 'examples/train/new_special_tokens/tokens.txt' \ + --torch_dtype bfloat16 \ + --num_train_epochs 5 \ + --per_device_train_batch_size 16 \ + --per_device_eval_batch_size 16 \ + --padding_free true \ + --attn_impl flash_attn \ + --learning_rate 1e-4 \ + --lora_rank 16 \ + --lora_alpha 32 \ + --target_modules all-linear \ + --modules_to_save embed_tokens lm_head \ + --gradient_accumulation_steps 1 \ + --eval_steps 500 \ + --save_steps 500 \ + --save_total_limit 2 \ + --logging_steps 5 \ + --max_length 2048 \ + --output_dir output \ + --warmup_ratio 0.05 \ + --dataloader_num_workers 4 \ + --deepspeed zero2 diff --git a/examples/train/optimizer/muon.sh b/examples/train/optimizer/muon.sh new file mode 100644 index 0000000000000000000000000000000000000000..22a04ad56b8da94eb13d05a717d756ecff220371 --- /dev/null +++ b/examples/train/optimizer/muon.sh @@ -0,0 +1,31 @@ +# 17GB +# ref: https://github.com/MoonshotAI/Moonlight/blob/master/examples/toy_train.py +# `moonshotai/Moonlight-16B-A3B-Instruct` does not support training; here we use `Qwen/Qwen2.5-7B-Instruct` as an example. +CUDA_VISIBLE_DEVICES=0 \ +swift sft \ + --model Qwen/Qwen2.5-7B-Instruct \ + --train_type lora \ + --dataset 'AI-ModelScope/alpaca-gpt4-data-zh#500' \ + 'AI-ModelScope/alpaca-gpt4-data-en#500' \ + 'swift/self-cognition#500' \ + --optimizer muon \ + --torch_dtype bfloat16 \ + --num_train_epochs 1 \ + --per_device_train_batch_size 1 \ + --per_device_eval_batch_size 1 \ + --learning_rate 1e-4 \ + --lora_rank 8 \ + --lora_alpha 32 \ + --target_modules all-linear \ + --gradient_accumulation_steps 16 \ + --eval_steps 50 \ + --save_steps 50 \ + --save_total_limit 2 \ + --logging_steps 5 \ + --max_length 2048 \ + --output_dir output \ + --system 'You are a helpful assistant.' \ + --warmup_ratio 0.05 \ + --dataloader_num_workers 4 \ + --model_author swift \ + --model_name swift-robot diff --git a/examples/train/packing/dpo.sh b/examples/train/packing/dpo.sh new file mode 100644 index 0000000000000000000000000000000000000000..5a7d1b94e898117c12a95a0a1780d59f6b5f0ad4 --- /dev/null +++ b/examples/train/packing/dpo.sh @@ -0,0 +1,30 @@ +# 4 * 50GiB; 2h +PYTORCH_CUDA_ALLOC_CONF='expandable_segments:True' \ +NPROC_PER_NODE=4 \ +CUDA_VISIBLE_DEVICES=0,1,2,3 \ +swift rlhf \ + --rlhf_type dpo \ + --model Qwen/Qwen2.5-7B-Instruct \ + --train_type full \ + --dataset AI-ModelScope/orpo-dpo-mix-40k \ + --load_from_cache_file true \ + --split_dataset_ratio 0.01 \ + --torch_dtype bfloat16 \ + --num_train_epochs 1 \ + --per_device_train_batch_size 1 \ + --per_device_eval_batch_size 1 \ + --learning_rate 1e-5 \ + --gradient_accumulation_steps 1 \ + --eval_steps 200 \ + --save_steps 200 \ + --save_total_limit 2 \ + --logging_steps 5 \ + --max_length 8192 \ + --output_dir output \ + --warmup_ratio 0.05 \ + --save_only_model true \ + --dataloader_num_workers 4 \ + --dataset_num_proc 4 \ + --deepspeed zero3 \ + --attn_impl flash_attn \ + --packing true diff --git a/examples/train/packing/dpo_vlm.sh b/examples/train/packing/dpo_vlm.sh new file mode 100644 index 0000000000000000000000000000000000000000..73209e070baeaa30b7b6ffa1ce2ab4981eb84033 --- /dev/null +++ b/examples/train/packing/dpo_vlm.sh @@ -0,0 +1,32 @@ +# 50GiB; 6h +PYTORCH_CUDA_ALLOC_CONF='expandable_segments:True' \ +CUDA_VISIBLE_DEVICES=0,1,2,3 \ +NPROC_PER_NODE=4 \ +MAX_PIXELS=1003520 \ +swift rlhf \ + --rlhf_type dpo \ + --model Qwen/Qwen2.5-VL-7B-Instruct \ + --dataset 'swift/RLAIF-V-Dataset' \ + --load_from_cache_file true \ + --split_dataset_ratio 0.01 \ + --train_type full \ + --torch_dtype bfloat16 \ + --num_train_epochs 1 \ + --per_device_train_batch_size 1 \ + --per_device_eval_batch_size 1 \ + --learning_rate 1e-5 \ + --freeze_vit true \ + --gradient_accumulation_steps 1 \ + --eval_steps 200 \ + --save_steps 200 \ + --save_total_limit 2 \ + --deepspeed zero3 \ + --logging_steps 5 \ + --max_length 8192 \ + --output_dir output \ + --warmup_ratio 0.05 \ + --dataloader_num_workers 4 \ + --dataset_num_proc 64 \ + --attn_impl flash_attn \ + --save_only_model true \ + --packing true diff --git a/examples/train/packing/liger_kernel.sh b/examples/train/packing/liger_kernel.sh new file mode 100644 index 0000000000000000000000000000000000000000..2dba2a4a12df773561ccffca01e624ec5ded6f1c --- /dev/null +++ b/examples/train/packing/liger_kernel.sh @@ -0,0 +1,31 @@ +# Env: 4 * A100 +# https://github.com/modelscope/ms-swift/blob/main/examples/megatron/long_text.sh +# Max Length: 16K +# GPU Memory: 4 * 42GB, Training Speed 10s/it +NPROC_PER_NODE=4 \ +CUDA_VISIBLE_DEVICES=0,1,2,3 \ +swift sft \ + --model Qwen/Qwen2.5-7B \ + --train_type full \ + --dataset 'AI-ModelScope/LongAlpaca-12k' \ + --load_from_cache_file true \ + --split_dataset_ratio 0.01 \ + --torch_dtype bfloat16 \ + --per_device_train_batch_size 1 \ + --per_device_eval_batch_size 1 \ + --learning_rate 1e-5 \ + --gradient_accumulation_steps 2 \ + --packing true \ + --eval_steps 200 \ + --save_steps 200 \ + --logging_steps 5 \ + --max_length 16384 \ + --warmup_ratio 0.05 \ + --dataloader_num_workers 8 \ + --dataset_num_proc 8 \ + --save_total_limit 2 \ + --save_only_model true \ + --output_dir output/Qwen2.5-7B \ + --deepspeed zero3 \ + --use_liger_kernel true \ + --attn_impl flash_attn diff --git a/examples/train/packing/llm.sh b/examples/train/packing/llm.sh new file mode 100644 index 0000000000000000000000000000000000000000..c7166df2a6beb1f9bb20d1663d9e78dd4356f13c --- /dev/null +++ b/examples/train/packing/llm.sh @@ -0,0 +1,32 @@ +# 22GB +CUDA_VISIBLE_DEVICES=0 \ +swift sft \ + --model Qwen/Qwen2.5-7B-Instruct \ + --train_type lora \ + --packing true \ + --dataset 'AI-ModelScope/alpaca-gpt4-data-zh#500' \ + 'AI-ModelScope/alpaca-gpt4-data-en#500' \ + 'swift/self-cognition#500' \ + --split_dataset_ratio 0.01 \ + --torch_dtype bfloat16 \ + --num_train_epochs 3 \ + --attn_impl flash_attn \ + --per_device_train_batch_size 1 \ + --per_device_eval_batch_size 1 \ + --learning_rate 1e-4 \ + --lora_rank 8 \ + --lora_alpha 32 \ + --target_modules all-linear \ + --gradient_accumulation_steps 4 \ + --eval_steps 50 \ + --save_steps 50 \ + --save_total_limit 2 \ + --logging_steps 5 \ + --max_length 2048 \ + --output_dir output \ + --system 'You are a helpful assistant.' \ + --warmup_ratio 0.05 \ + --dataloader_num_workers 4 \ + --dataset_num_proc 4 \ + --model_author swift \ + --model_name swift-robot diff --git a/examples/train/packing/qwen2_5_omni.sh b/examples/train/packing/qwen2_5_omni.sh new file mode 100644 index 0000000000000000000000000000000000000000..9118a8c5efc04be8b5fca65aeb581ea09056fee5 --- /dev/null +++ b/examples/train/packing/qwen2_5_omni.sh @@ -0,0 +1,40 @@ +# 4 * 32GB +# Multimodal packing currently only supports qwen2_vl, qwen2_5_vl, qwen2_5_omni, internvl2_5/3 +# A demo for four modalities that can be run directly +# For local datasets, it is recommended to use streaming: `--streaming true` (save memory) +NPROC_PER_NODE=4 \ +ENABLE_AUDIO_OUTPUT=1 \ +CUDA_VISIBLE_DEVICES=0,1,2,3 \ +VIDEO_MAX_PIXELS=50176 \ +FPS_MAX_FRAMES=12 \ +MAX_PIXELS=1003520 \ +swift sft \ + --model Qwen/Qwen2.5-Omni-7B \ + --dataset 'AI-ModelScope/alpaca-gpt4-data-zh#10000' \ + 'AI-ModelScope/LaTeX_OCR#2000' \ + 'speech_asr/speech_asr_aishell1_trainsets:validation#2000' \ + --load_from_cache_file true \ + --split_dataset_ratio 0.01 \ + --train_type lora \ + --torch_dtype bfloat16 \ + --attn_impl flash_attn \ + --packing true \ + --num_train_epochs 3 \ + --per_device_train_batch_size 1 \ + --per_device_eval_batch_size 1 \ + --learning_rate 1e-4 \ + --lora_rank 8 \ + --lora_alpha 32 \ + --target_modules all-linear \ + --freeze_vit true \ + --gradient_accumulation_steps 1 \ + --eval_steps 50 \ + --save_steps 50 \ + --save_total_limit 2 \ + --logging_steps 5 \ + --max_length 4096 \ + --output_dir output \ + --warmup_ratio 0.05 \ + --dataloader_num_workers 4 \ + --dataset_num_proc 8 \ + --deepspeed zero2 diff --git a/examples/train/packing/qwen2_5_vl.sh b/examples/train/packing/qwen2_5_vl.sh new file mode 100644 index 0000000000000000000000000000000000000000..98ed87c066dec2c7a8ece7421ce0e492224aa200 --- /dev/null +++ b/examples/train/packing/qwen2_5_vl.sh @@ -0,0 +1,36 @@ +# 4 * 36GB +# Multimodal packing currently only supports qwen2_vl, qwen2_5_vl, qwen2_5_omni, internvl2_5/3 +# Efficiency: With packing: 10 minutes; Without packing: >=1 hour +# For local datasets, it is recommended to use streaming: `--streaming true` (save memory) +# You can also use padding_free to avoid the space/time cost caused by multi-modal packing: +# https://github.com/modelscope/ms-swift/blob/main/examples/train/padding_free/sft.sh +NPROC_PER_NODE=4 \ +MAX_PIXELS=1003520 \ +CUDA_VISIBLE_DEVICES=0,1,2,3 \ +swift sft \ + --model Qwen/Qwen2.5-VL-7B-Instruct \ + --train_type lora \ + --dataset 'AI-ModelScope/LaTeX_OCR#20000' \ + --load_from_cache_file true \ + --split_dataset_ratio 0.01 \ + --torch_dtype bfloat16 \ + --attn_impl flash_attn \ + --packing true \ + --num_train_epochs 3 \ + --per_device_train_batch_size 1 \ + --per_device_eval_batch_size 1 \ + --learning_rate 1e-4 \ + --lora_rank 8 \ + --lora_alpha 32 \ + --target_modules all-linear \ + --gradient_accumulation_steps 1 \ + --eval_steps 100 \ + --save_steps 100 \ + --save_total_limit 2 \ + --logging_steps 5 \ + --max_length 8192 \ + --output_dir output \ + --warmup_ratio 0.05 \ + --dataloader_num_workers 4 \ + --dataset_num_proc 8 \ + --deepspeed zero2 diff --git a/examples/train/packing/streaming.sh b/examples/train/packing/streaming.sh new file mode 100644 index 0000000000000000000000000000000000000000..15813fa03b043a8ac49e9587bb44d018c9bdcfa4 --- /dev/null +++ b/examples/train/packing/streaming.sh @@ -0,0 +1,34 @@ +# 4 * 36GB +# A demo using the Hugging Face dataset +# The first model weights will be saved around step 70. +NPROC_PER_NODE=4 \ +MAX_PIXELS=1003520 \ +CUDA_VISIBLE_DEVICES=0,1,2,3 \ +HF_ENDPOINT=https://hf-mirror.com \ +swift sft \ + --model Qwen/Qwen2.5-VL-7B-Instruct \ + --train_type lora \ + --dataset 'HF::linxy/LaTeX_OCR:full#20000' \ + --torch_dtype bfloat16 \ + --attn_impl flash_attn \ + --streaming true \ + --shuffle_buffer_size 1000 \ + --packing true \ + --save_strategy epoch \ + --max_steps 1000 \ + --max_epochs 5 \ + --per_device_train_batch_size 1 \ + --per_device_eval_batch_size 1 \ + --learning_rate 1e-4 \ + --lora_rank 8 \ + --lora_alpha 32 \ + --target_modules all-linear \ + --gradient_accumulation_steps 1 \ + --save_total_limit 2 \ + --logging_steps 5 \ + --max_length 8192 \ + --output_dir output \ + --warmup_ratio 0.05 \ + --dataloader_num_workers 1 \ + --dataset_num_proc 8 \ + --deepspeed zero2 diff --git a/examples/train/padding_free/dpo_vlm.sh b/examples/train/padding_free/dpo_vlm.sh new file mode 100644 index 0000000000000000000000000000000000000000..f704aaf5b1724eefa656896b367ab14c4869ed39 --- /dev/null +++ b/examples/train/padding_free/dpo_vlm.sh @@ -0,0 +1,33 @@ +# with padding_free: 4 * 53GiB, 3.55s/it +# without padding_free: 4 * 62GiB 4.41s/it +PYTORCH_CUDA_ALLOC_CONF='expandable_segments:True' \ +CUDA_VISIBLE_DEVICES=0,1,2,3 \ +NPROC_PER_NODE=4 \ +MAX_PIXELS=1003520 \ +swift rlhf \ + --rlhf_type dpo \ + --model Qwen/Qwen2.5-VL-7B-Instruct \ + --dataset 'swift/RLAIF-V-Dataset#20000' \ + --load_from_cache_file true \ + --split_dataset_ratio 0.01 \ + --train_type full \ + --torch_dtype bfloat16 \ + --num_train_epochs 1 \ + --per_device_train_batch_size 4 \ + --per_device_eval_batch_size 4 \ + --learning_rate 1e-5 \ + --freeze_vit true \ + --gradient_accumulation_steps 1 \ + --eval_steps 100 \ + --save_steps 100 \ + --save_total_limit 2 \ + --deepspeed zero3 \ + --logging_steps 5 \ + --max_length 4096 \ + --output_dir output \ + --warmup_ratio 0.05 \ + --dataloader_num_workers 4 \ + --dataset_num_proc 4 \ + --attn_impl flash_attn \ + --save_only_model true \ + --padding_free true diff --git a/examples/train/padding_free/sft.sh b/examples/train/padding_free/sft.sh new file mode 100644 index 0000000000000000000000000000000000000000..c5a1d1c1242c2708eea02a13cc7e71a7c0442ac4 --- /dev/null +++ b/examples/train/padding_free/sft.sh @@ -0,0 +1,31 @@ +# Supported multimodal models reference: +# https://github.com/modelscope/ms-swift/blob/main/examples/train/packing/qwen2_5_vl.sh +# without padding_free: 4 * 60GiB, 26h +# padding_free: 4 * 44GiB, 13h +NPROC_PER_NODE=4 \ +CUDA_VISIBLE_DEVICES=0,1,2,3 \ +swift sft \ + --model Qwen/Qwen2.5-7B \ + --train_type full \ + --dataset 'liucong/Chinese-DeepSeek-R1-Distill-data-110k-SFT' \ + --load_from_cache_file true \ + --split_dataset_ratio 0.01 \ + --torch_dtype bfloat16 \ + --per_device_train_batch_size 8 \ + --per_device_eval_batch_size 8 \ + --learning_rate 1e-5 \ + --gradient_accumulation_steps 1 \ + --eval_steps 200 \ + --save_steps 200 \ + --logging_steps 5 \ + --max_length 8192 \ + --warmup_ratio 0.05 \ + --dataloader_num_workers 8 \ + --dataset_num_proc 8 \ + --save_total_limit 2 \ + --save_only_model true \ + --output_dir output/Qwen2.5-7B \ + --deepspeed zero3 \ + --use_liger_kernel true \ + --attn_impl flash_attn \ + --padding_free true diff --git a/examples/train/plugins/loss_scale.sh b/examples/train/plugins/loss_scale.sh new file mode 100644 index 0000000000000000000000000000000000000000..3722c497d8f6b7f71d4651dd798d1f0c6a4200c8 --- /dev/null +++ b/examples/train/plugins/loss_scale.sh @@ -0,0 +1,22 @@ +# loss_scale all to train all tokens +# use loss_type loss_scale +# This is just an example +CUDA_VISIBLE_DEVICES=0 \ +swift sft \ + --model Qwen/Qwen2.5-7B-Instruct \ + --train_type lora \ + --dataset 'swift/self-cognition#1000' \ + --num_train_epochs 1 \ + --per_device_train_batch_size 1 \ + --learning_rate 1e-4 \ + --lora_rank 8 \ + --lora_alpha 32 \ + --gradient_accumulation_steps 16 \ + --eval_steps 100 \ + --save_steps 100 \ + --save_total_limit 2 \ + --logging_steps 5 \ + --model_author swift \ + --model_name swift-robot \ + --loss_scale all \ + --loss_type loss_scale diff --git a/examples/train/plugins/tuner_phi4_mm.sh b/examples/train/plugins/tuner_phi4_mm.sh new file mode 100644 index 0000000000000000000000000000000000000000..aa388b4925d3532668dd52bded729851086396e8 --- /dev/null +++ b/examples/train/plugins/tuner_phi4_mm.sh @@ -0,0 +1,22 @@ +# `--train_type dummy` +CUDA_VISIBLE_DEVICES=0 \ +swift sft \ + --model LLM-Research/Phi-4-multimodal-instruct \ + --dataset 'AI-ModelScope/LaTeX_OCR:human_handwrite#20000' \ + --load_from_cache_file true \ + --split_dataset_ratio 0.01 \ + --train_type dummy \ + --torch_dtype bfloat16 \ + --num_train_epochs 1 \ + --per_device_train_batch_size 1 \ + --per_device_eval_batch_size 1 \ + --learning_rate 1e-4 \ + --gradient_accumulation_steps 16 \ + --eval_steps 200 \ + --save_steps 200 \ + --save_total_limit 2 \ + --logging_steps 5 \ + --max_length 2048 \ + --output_dir output \ + --warmup_ratio 0.05 \ + --dataloader_num_workers 4 diff --git a/examples/train/predict_with_generate/train.sh b/examples/train/predict_with_generate/train.sh new file mode 100644 index 0000000000000000000000000000000000000000..af5eef5d127ccaa7c46e98666a03b92a9ac4f241 --- /dev/null +++ b/examples/train/predict_with_generate/train.sh @@ -0,0 +1,30 @@ +# 20GiB +CUDA_VISIBLE_DEVICES=0 \ +MAX_PIXELS=1003520 \ +swift sft \ + --model Qwen/Qwen2.5-VL-7B-Instruct \ + --dataset 'AI-ModelScope/LaTeX_OCR:human_handwrite#20000' \ + --load_from_cache_file true \ + --split_dataset_ratio 0.01 \ + --train_type lora \ + --torch_dtype bfloat16 \ + --num_train_epochs 1 \ + --per_device_train_batch_size 1 \ + --per_device_eval_batch_size 2 \ + --learning_rate 1e-4 \ + --lora_rank 8 \ + --lora_alpha 32 \ + --target_modules all-linear \ + --freeze_vit true \ + --gradient_accumulation_steps 16 \ + --eval_steps 100 \ + --save_steps 100 \ + --save_total_limit 2 \ + --logging_steps 5 \ + --max_length 2048 \ + --output_dir output \ + --warmup_ratio 0.05 \ + --dataloader_num_workers 4 \ + --predict_with_generate true \ + --metric_for_best_model rouge-l \ + --greater_is_better true diff --git a/examples/train/pretrain/train.sh b/examples/train/pretrain/train.sh new file mode 100644 index 0000000000000000000000000000000000000000..3b2e22ae1370403eb51086f4e157b33372d3f830 --- /dev/null +++ b/examples/train/pretrain/train.sh @@ -0,0 +1,31 @@ +# If not using flash_attn, or transformers<4.44, +# or encountering an abnormally large loss (i.e., the model does not support packing), +# please remove `--packing true`. +nproc_per_node=4 + +NPROC_PER_NODE=$nproc_per_node \ +CUDA_VISIBLE_DEVICES=0,1,2,3 \ +swift pt \ + --model Qwen/Qwen2.5-7B \ + --train_type full \ + --dataset swift/chinese-c4 \ + --torch_dtype bfloat16 \ + --streaming true \ + --per_device_train_batch_size 1 \ + --per_device_eval_batch_size 1 \ + --learning_rate 1e-5 \ + --gradient_accumulation_steps $(expr 64 / $nproc_per_node) \ + --packing true \ + --eval_steps 500 \ + --save_steps 500 \ + --save_total_limit 2 \ + --logging_steps 5 \ + --deepspeed zero3 \ + --max_length 8192 \ + --max_steps 10000 \ + --warmup_ratio 0.05 \ + --dataloader_num_workers 4 \ + --dataset_num_proc 8 \ + --save_only_model true \ + --output_dir output/Qwen2.5-7B \ + --attn_impl flash_attn diff --git a/examples/train/qlora/awq/merge_lora.sh b/examples/train/qlora/awq/merge_lora.sh new file mode 100644 index 0000000000000000000000000000000000000000..c698236c376294d3d018f7e7c7ca3167111f1699 --- /dev/null +++ b/examples/train/qlora/awq/merge_lora.sh @@ -0,0 +1,5 @@ +# This will store the full, unquantized weights. +swift export \ + --model Qwen/Qwen2.5-7B-Instruct \ + --adapters output/vx-xxx/checkpoint-xxx \ + --merge_lora true diff --git a/examples/train/qlora/awq/train.sh b/examples/train/qlora/awq/train.sh new file mode 100644 index 0000000000000000000000000000000000000000..fff724d19568bdd6409bfe6392e525ebfa8d2904 --- /dev/null +++ b/examples/train/qlora/awq/train.sh @@ -0,0 +1,28 @@ +# 10GB +CUDA_VISIBLE_DEVICES=0 \ +swift sft \ + --model Qwen/Qwen2.5-7B-Instruct-AWQ \ + --train_type lora \ + --dataset 'AI-ModelScope/alpaca-gpt4-data-zh#500' \ + 'AI-ModelScope/alpaca-gpt4-data-en#500' \ + 'swift/self-cognition#500' \ + --torch_dtype bfloat16 \ + --num_train_epochs 1 \ + --per_device_train_batch_size 1 \ + --per_device_eval_batch_size 1 \ + --learning_rate 1e-4 \ + --lora_rank 8 \ + --lora_alpha 32 \ + --target_modules all-linear \ + --gradient_accumulation_steps 16 \ + --eval_steps 50 \ + --save_steps 50 \ + --save_total_limit 2 \ + --logging_steps 5 \ + --max_length 2048 \ + --output_dir output \ + --system 'You are a helpful assistant.' \ + --warmup_ratio 0.05 \ + --dataloader_num_workers 4 \ + --model_author swift \ + --model_name swift-robot diff --git a/examples/train/qlora/bnb/merge_lora.sh b/examples/train/qlora/bnb/merge_lora.sh new file mode 100644 index 0000000000000000000000000000000000000000..1b02d103b4080d71de9b2d4c82236c47bd762b74 --- /dev/null +++ b/examples/train/qlora/bnb/merge_lora.sh @@ -0,0 +1,4 @@ +# This will store the full, unquantized weights. +swift export \ + --adapters output/vx-xxx/checkpoint-xxx \ + --merge_lora true diff --git a/examples/train/qlora/bnb/train.sh b/examples/train/qlora/bnb/train.sh new file mode 100644 index 0000000000000000000000000000000000000000..cf2fea09fb5938632490a23acc36f96668618249 --- /dev/null +++ b/examples/train/qlora/bnb/train.sh @@ -0,0 +1,34 @@ +# 10GB +# pip install bitsandbytes +CUDA_VISIBLE_DEVICES=0 \ +swift sft \ + --model Qwen/Qwen2.5-7B-Instruct \ + --train_type lora \ + --dataset 'AI-ModelScope/alpaca-gpt4-data-zh#500' \ + 'AI-ModelScope/alpaca-gpt4-data-en#500' \ + 'swift/self-cognition#500' \ + --torch_dtype bfloat16 \ + --bnb_4bit_compute_dtype bfloat16 \ + --bnb_4bit_quant_type nf4 \ + --bnb_4bit_use_double_quant true \ + --quant_method bnb \ + --quant_bits 4 \ + --num_train_epochs 1 \ + --per_device_train_batch_size 1 \ + --per_device_eval_batch_size 1 \ + --learning_rate 1e-4 \ + --lora_rank 8 \ + --lora_alpha 32 \ + --target_modules all-linear \ + --gradient_accumulation_steps 16 \ + --eval_steps 50 \ + --save_steps 50 \ + --save_total_limit 2 \ + --logging_steps 5 \ + --max_length 2048 \ + --output_dir output \ + --system 'You are a helpful assistant.' \ + --warmup_ratio 0.05 \ + --dataloader_num_workers 4 \ + --model_author swift \ + --model_name swift-robot diff --git a/examples/train/qlora/gptq.sh b/examples/train/qlora/gptq.sh new file mode 100644 index 0000000000000000000000000000000000000000..df4bf8c9730133cbcc37c3741ca960207449e6ec --- /dev/null +++ b/examples/train/qlora/gptq.sh @@ -0,0 +1,27 @@ +# 2 * 30GiB +CUDA_VISIBLE_DEVICES=0,1 \ +MAX_PIXELS=1003520 \ +swift sft \ + --model Qwen/Qwen2.5-VL-72B-Instruct-GPTQ-Int4 \ + --dataset 'modelscope/coco_2014_caption:validation#20000' \ + --load_from_cache_file true \ + --split_dataset_ratio 0.01 \ + --train_type lora \ + --torch_dtype bfloat16 \ + --num_train_epochs 1 \ + --per_device_train_batch_size 1 \ + --per_device_eval_batch_size 1 \ + --learning_rate 1e-4 \ + --lora_rank 8 \ + --lora_alpha 32 \ + --target_modules all-linear \ + --freeze_vit true \ + --gradient_accumulation_steps 16 \ + --eval_steps 100 \ + --save_steps 100 \ + --save_total_limit 2 \ + --logging_steps 5 \ + --max_length 2048 \ + --output_dir output \ + --warmup_ratio 0.05 \ + --dataloader_num_workers 4 diff --git a/examples/train/qlora/hqq.sh b/examples/train/qlora/hqq.sh new file mode 100644 index 0000000000000000000000000000000000000000..aaec6d45273ee3a05ab004791417a1e7aa0194c8 --- /dev/null +++ b/examples/train/qlora/hqq.sh @@ -0,0 +1,31 @@ +# 10GB +# pip install hqq +CUDA_VISIBLE_DEVICES=0 \ +swift sft \ + --model Qwen/Qwen2.5-7B-Instruct \ + --train_type lora \ + --dataset 'AI-ModelScope/alpaca-gpt4-data-zh#500' \ + 'AI-ModelScope/alpaca-gpt4-data-en#500' \ + 'swift/self-cognition#500' \ + --torch_dtype bfloat16 \ + --quant_method hqq \ + --quant_bits 4 \ + --num_train_epochs 1 \ + --per_device_train_batch_size 1 \ + --per_device_eval_batch_size 1 \ + --learning_rate 1e-4 \ + --lora_rank 8 \ + --lora_alpha 32 \ + --target_modules all-linear \ + --gradient_accumulation_steps 16 \ + --eval_steps 50 \ + --save_steps 50 \ + --save_total_limit 2 \ + --logging_steps 5 \ + --max_length 2048 \ + --output_dir output \ + --system 'You are a helpful assistant.' \ + --warmup_ratio 0.05 \ + --dataloader_num_workers 4 \ + --model_author swift \ + --model_name swift-robot diff --git a/examples/train/reranker/train_generative_reranker.sh b/examples/train/reranker/train_generative_reranker.sh new file mode 100644 index 0000000000000000000000000000000000000000..04ca4cb0376da6ddd3789e8d8887663bf2251d81 --- /dev/null +++ b/examples/train/reranker/train_generative_reranker.sh @@ -0,0 +1,26 @@ +nproc_per_node=4 +# 4*47G +# losses: plugin/loss.py +# only support --padding_side left +NPROC_PER_NODE=$nproc_per_node \ +swift sft \ + --model Qwen/Qwen3-Reranker-4B \ + --task_type generative_reranker \ + --loss_type generative_reranker \ + --train_type full \ + --dataset MTEB/scidocs-reranking \ + --load_from_cache_file true \ + --split_dataset_ratio 0.05 \ + --eval_strategy steps \ + --padding_side left \ + --output_dir output \ + --eval_steps 100 \ + --num_train_epochs 1 \ + --save_steps 200 \ + --per_device_train_batch_size 2 \ + --per_device_eval_batch_size 2 \ + --gradient_accumulation_steps 8 \ + --dataset_num_proc 8 \ + --learning_rate 6e-6 \ + --label_names labels \ + --dataloader_drop_last true diff --git a/examples/train/reranker/train_generative_reranker_listwise.sh b/examples/train/reranker/train_generative_reranker_listwise.sh new file mode 100644 index 0000000000000000000000000000000000000000..5ea60cc76a39fc9f174dfc4228b2b9b6cf16b705 --- /dev/null +++ b/examples/train/reranker/train_generative_reranker_listwise.sh @@ -0,0 +1,26 @@ +nproc_per_node=4 +# 4*47G +# losses: plugin/loss.py +# only support --padding_side left +NPROC_PER_NODE=$nproc_per_node \ +swift sft \ + --model Qwen/Qwen3-Reranker-4B \ + --task_type generative_reranker \ + --loss_type listwise_generative_reranker \ + --train_type full \ + --dataset MTEB/scidocs-reranking \ + --load_from_cache_file true \ + --split_dataset_ratio 0.05 \ + --padding_side left \ + --eval_strategy steps \ + --output_dir output \ + --eval_steps 100 \ + --num_train_epochs 1 \ + --save_steps 200 \ + --per_device_train_batch_size 2 \ + --per_device_eval_batch_size 2 \ + --gradient_accumulation_steps 8 \ + --dataset_num_proc 8 \ + --learning_rate 6e-6 \ + --label_names labels \ + --dataloader_drop_last true diff --git a/examples/train/reranker/train_reranker.sh b/examples/train/reranker/train_reranker.sh new file mode 100644 index 0000000000000000000000000000000000000000..f56d29c339d76daad119db422d64f39b742a50a0 --- /dev/null +++ b/examples/train/reranker/train_reranker.sh @@ -0,0 +1,22 @@ +# 1*5G +CUDA_VISIBLE_DEVICES=0 \ +swift sft \ + --model iic/gte-reranker-modernbert-base \ + --task_type reranker \ + --loss_type reranker \ + --train_type full \ + --dataset MTEB/scidocs-reranking \ + --load_from_cache_file true \ + --split_dataset_ratio 0.05 \ + --eval_strategy steps \ + --output_dir output \ + --eval_steps 100 \ + --num_train_epochs 1 \ + --save_steps 200 \ + --per_device_train_batch_size 64 \ + --per_device_eval_batch_size 64 \ + --gradient_accumulation_steps 1 \ + --dataset_num_proc 8 \ + --learning_rate 6e-6 \ + --label_names labels \ + --dataloader_drop_last true \ diff --git a/examples/train/reranker/train_reranker_listwise.sh b/examples/train/reranker/train_reranker_listwise.sh new file mode 100644 index 0000000000000000000000000000000000000000..200f400dae042a2259b73f0bfdd143a3f6177b6d --- /dev/null +++ b/examples/train/reranker/train_reranker_listwise.sh @@ -0,0 +1,22 @@ +# 1*5G +CUDA_VISIBLE_DEVICES=0 \ +swift sft \ + --model iic/gte-reranker-modernbert-base \ + --task_type reranker \ + --loss_type listwise_reranker \ + --train_type full \ + --dataset MTEB/scidocs-reranking \ + --load_from_cache_file true \ + --split_dataset_ratio 0.05 \ + --eval_strategy steps \ + --output_dir output \ + --eval_steps 100 \ + --num_train_epochs 1 \ + --save_steps 200 \ + --per_device_train_batch_size 64 \ + --per_device_eval_batch_size 64 \ + --gradient_accumulation_steps 1 \ + --dataset_num_proc 8 \ + --learning_rate 6e-6 \ + --label_names labels \ + --dataloader_drop_last true \