BBBBCHAN TRAE CLI commited on
Commit
21d87c3
·
verified ·
1 Parent(s): 2a482a9

Sync StreamDelta directory

Browse files

Co-authored-by: TRAE CLI <noreply@bytedance.com>

This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. examples/train/rft/math.json +0 -0
  2. examples/train/rft/rft.py +224 -0
  3. examples/train/rlhf/README.md +3 -0
  4. examples/train/rlhf/cpo.sh +30 -0
  5. examples/train/rlhf/dpo/full.sh +31 -0
  6. examples/train/rlhf/dpo/lora.sh +30 -0
  7. examples/train/rlhf/gkd/fast.sh +48 -0
  8. examples/train/rlhf/gkd/full.sh +31 -0
  9. examples/train/rlhf/gkd/think_model.sh +50 -0
  10. examples/train/rlhf/kto.sh +29 -0
  11. examples/train/rlhf/mpo.sh +35 -0
  12. examples/train/rlhf/orpo.sh +30 -0
  13. examples/train/rlhf/ppo/full.sh +37 -0
  14. examples/train/rlhf/ppo/lora.sh +40 -0
  15. examples/train/rlhf/rm.sh +30 -0
  16. examples/train/rlhf/simpo.sh +28 -0
  17. examples/train/seq_cls/bert/deploy.sh +11 -0
  18. examples/train/seq_cls/bert/infer.sh +7 -0
  19. examples/train/seq_cls/bert/sft.sh +30 -0
  20. examples/train/seq_cls/multi_label/sft.sh +30 -0
  21. examples/train/seq_cls/qwen2_5/deploy.sh +8 -0
  22. examples/train/seq_cls/qwen2_5/infer.sh +5 -0
  23. examples/train/seq_cls/qwen2_5/sft.sh +30 -0
  24. examples/train/seq_cls/qwen2_5_omni/infer.py +21 -0
  25. examples/train/seq_cls/qwen2_5_omni/infer.sh +5 -0
  26. examples/train/seq_cls/qwen2_5_omni/sft.sh +28 -0
  27. examples/train/seq_cls/regression/deploy.sh +8 -0
  28. examples/train/seq_cls/regression/infer.sh +5 -0
  29. examples/train/seq_cls/regression/sft.sh +30 -0
  30. examples/train/sequence_parallel/sequence_parallel.sh +24 -0
  31. examples/train/sequence_parallel/sequence_parallel_512k.sh +32 -0
  32. examples/train/sequence_parallel/sequence_parallel_dpo.sh +29 -0
  33. examples/train/sequence_parallel/sequence_parallel_grpo.sh +44 -0
  34. examples/train/streaming/lazy_tokenize.sh +19 -0
  35. examples/train/streaming/streaming.sh +17 -0
  36. examples/train/think_model/deepseek_r1.sh +29 -0
  37. examples/train/think_model/qwen3_demo1.sh +31 -0
  38. examples/train/think_model/qwen3_demo2.sh +30 -0
  39. examples/train/tuners/adalora/train.sh +16 -0
  40. examples/train/tuners/adapter/train.sh +16 -0
  41. examples/train/tuners/boft/train.sh +16 -0
  42. examples/train/tuners/bone/train.sh +16 -0
  43. examples/train/tuners/dora/train.sh +19 -0
  44. examples/train/tuners/galore/train_galore.sh +18 -0
  45. examples/train/tuners/galore/train_qgalore.sh +22 -0
  46. examples/train/tuners/lisa/train.sh +17 -0
  47. examples/train/tuners/llamapro/train.sh +17 -0
  48. examples/train/tuners/longlora/train.sh +18 -0
  49. examples/train/tuners/lora-ga/train.sh +33 -0
  50. examples/train/tuners/lora/train.sh +18 -0
examples/train/rft/math.json ADDED
The diff for this file is too large to render. See raw diff
 
examples/train/rft/rft.py ADDED
@@ -0,0 +1,224 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import shutil
3
+ import subprocess
4
+ import time
5
+ from typing import List
6
+
7
+ from swift.utils import get_device_count
8
+
9
+ # NOTE: this script supports at most 8 GPUS in a node, if using multi node, please use custom logic.
10
+
11
+ # Paste conda env
12
+ # conda_prefix = 'source /root/miniconda3/etc/profile.d/conda.sh && conda activate py311 && '
13
+ conda_prefix = ''
14
+
15
+
16
+ def do_sample(model: str, model_type: str, dataset: List[str], iter: int):
17
+ device_count = get_device_count()
18
+ handlers = []
19
+ datasets = []
20
+ # Sampling cache, to avoid lmdeploy & PRM run at the same time
21
+ # Why lmdeploy not vllm? we found that the responses generated by lmdeploy are more similar than ones of vllm.
22
+ for device in range(device_count):
23
+ sample_cmd = (f'{conda_prefix} USE_OPENCOMPASS_EVALUATOR=True CUDA_VISIBLE_DEVICES={device} swift sample '
24
+ f'--model {model} --model_type {model_type} '
25
+ f'--dataset {" ".join(dataset)} '
26
+ f'--data_range {device} {device_count} '
27
+ f'--max_length 2048 '
28
+ f'--system "You are a math model, you should **think step by step** carefully, '
29
+ f'and always consider the basic math principles to avoid making calculating mistakes.'
30
+ f'Give the final answer wrapped with \\boxed{{}}" '
31
+ f'--load_args false '
32
+ f'--sampler_engine vllm '
33
+ f'--max_new_tokens 768 '
34
+ f'--override_exist_file true '
35
+ f'--num_sampling_per_gpu_batch_size 1 '
36
+ f'--num_return_sequences 64 '
37
+ f'--cache_files sample_output/iter_{iter}_proc_{device}_cache.jsonl '
38
+ f'--output_file iter_{iter}_proc_{device}_cache.jsonl '
39
+ f'--top_p 1.0 '
40
+ f'--temperature 1.0 ')
41
+ print(f'Sampling caches of iter {iter}, part {device}.', flush=True)
42
+ env = os.environ.copy()
43
+ env['CUDA_VISIBLE_DEVICES'] = str(device)
44
+ handler = subprocess.Popen(
45
+ f'{sample_cmd}' + f' > logs/sample_iter_{iter}_proc_{device}_cache.log 2>&1',
46
+ env=os.environ.copy(),
47
+ shell=True,
48
+ executable='/bin/bash')
49
+ handlers.append(handler)
50
+
51
+ for proc, handler in enumerate(handlers):
52
+ handler.wait()
53
+ assert os.path.exists(os.path.join('sample_output', f'iter_{iter}_proc_{proc}_cache.jsonl'))
54
+
55
+ handlers = []
56
+ # Sample again, this time to filter with ORM & PRM
57
+ # Provide your PRM model or PRM name(add PRM in plugin/prm.py first)
58
+ # You can define your custom PRM logic in the plugin
59
+ # (like, split your steps, use the worst score/last score/avg score)
60
+ for device in range(device_count):
61
+ sample_cmd = (
62
+ f'{conda_prefix} USE_OPENCOMPASS_EVALUATOR=True CUDA_VISIBLE_DEVICES={device} swift sample '
63
+ f'--model {model} --model_type {model_type} ' # change to --resume_from_checkpoint to use the latest optimizer state # noqa
64
+ f'--dataset {" ".join(dataset)} '
65
+ f'--data_range {device} {device_count} '
66
+ f'--max_length 2048 '
67
+ f'--system "You are a math model, you should **think step by step** carefully, '
68
+ f'and always consider the basic math principles to avoid making calculating mistakes.'
69
+ f'Give the final answer wrapped with \\boxed{{}}" '
70
+ f'--load_args false '
71
+ f'--sampler_engine no '
72
+ f'--orm_model math ' # math defines in plugin/orm.py
73
+ f'--prm_model Qwen/Qwen2.5-Math-PRM-7B '
74
+ f'--prm_threshold {min(0.7 + 0.1*iter, 0.9)} '
75
+ f'--max_new_tokens 768 '
76
+ f'--override_exist_file true ' # no not override the existing sample files
77
+ f'--num_sampling_per_gpu_batch_size 1 '
78
+ f'--num_return_sequences 64 '
79
+ f'--output_file iter_{iter}_proc_{device}_sampling.jsonl '
80
+ f'--cache_files sample_output/iter_{iter}_proc_{device}_cache.jsonl ')
81
+ print(f'Sampling iter {iter}, part {device}.', flush=True)
82
+ env = os.environ.copy()
83
+ env['CUDA_VISIBLE_DEVICES'] = str(device)
84
+ handler = subprocess.Popen(
85
+ f'{sample_cmd}' + f' > logs/sample_iter_{iter}_proc_{device}.log 2>&1',
86
+ env=os.environ.copy(),
87
+ shell=True,
88
+ executable='/bin/bash')
89
+ handlers.append(handler)
90
+
91
+ for proc, handler in enumerate(handlers):
92
+ handler.wait()
93
+ assert os.path.exists(os.path.join('sample_output', f'iter_{iter}_proc_{proc}_sampling.jsonl')), (
94
+ f'{os.path.join("sample_output", f"iter_{iter}_proc_{proc}_sampling.jsonl")} not exists, '
95
+ 'please check the sample logs to get the detail error.')
96
+ datasets.append(os.path.join('sample_output', f'iter_{iter}_proc_{proc}_sampling.jsonl'))
97
+ print(f'Sampling done, files:{datasets}', flush=True)
98
+ return datasets
99
+
100
+
101
+ def do_train(model: str, model_type: str, datasets: List[str], iter, cmd='sft'):
102
+ gpu_prefix = ''
103
+ ds_config = ''
104
+ if get_device_count() > 1:
105
+ gpu_prefix = f'NPROC_PER_NODE={get_device_count()} '
106
+ ds_config = '--deepspeed zero3 '
107
+ extra_args = ''
108
+ if cmd == 'rlhf':
109
+ extra_args = '--rlhf_type dpo --beta 0.3 ' # use another reinforce learning method supported by swift
110
+ ga = 128 // get_device_count() // 2
111
+ train_cmd = (f'{conda_prefix} {gpu_prefix} swift {cmd} '
112
+ f'--model {model} --model_type {model_type} '
113
+ f'--dataset {" ".join(datasets)} '
114
+ f'--max_length 2048 '
115
+ f'--num_train_epochs 1 '
116
+ f'--load_args false '
117
+ f'--train_type full '
118
+ f'{extra_args} '
119
+ f'--eval_strategy no '
120
+ f'--split_dataset_ratio 0 '
121
+ f'--per_device_train_batch_size 2 '
122
+ f'--gradient_accumulation_steps {ga} '
123
+ f'--save_steps 1 '
124
+ f'--save_strategy epoch '
125
+ f'{ds_config} '
126
+ f'--learning_rate 4e-6 ')
127
+
128
+ print(f'Training iter {iter}.', flush=True)
129
+ handler = subprocess.Popen(
130
+ f'{train_cmd}' + f' > logs/train_iter_{iter}.log 2>&1',
131
+ shell=True,
132
+ env=os.environ.copy(),
133
+ executable='/bin/bash')
134
+ handler.wait()
135
+ ckpt = None
136
+ with open(f'logs/train_iter_{iter}.log', 'r') as f:
137
+ for line in f.readlines():
138
+ if 'last_model_checkpoint: ' in line:
139
+ ckpt = line.split('last_model_checkpoint: ')[1]
140
+ break
141
+ assert ckpt is not None
142
+ print(f'Training done, ckpt: {ckpt.strip()}.', flush=True)
143
+ return ckpt.strip()
144
+
145
+
146
+ def do_eval(model, model_type: str, iter):
147
+ eval_cmd = (
148
+ f'{conda_prefix} swift eval '
149
+ '--eval_dataset competition_math ' # eval another dataset
150
+ '--infer_backend vllm --eval_limit 500 '
151
+ f'--model {model} --model_type {model_type} '
152
+ '--system "You are a math model, you should **think step by step** carefully, '
153
+ 'and always consider the basic math principles to avoid making calculating mistakes. '
154
+ 'Give the final answer wrapped with \\boxed{}"')
155
+ print('Evaluating.', flush=True)
156
+ # Replace the original dataset to the math.json, this is for test, comment this if not need
157
+ replace_math_dataset()
158
+
159
+ if iter is None:
160
+ iter = 'origin'
161
+ env = os.environ.copy()
162
+ env['CUDA_VISIBLE_DEVICES'] = '0'
163
+ handler = subprocess.Popen(
164
+ f'{eval_cmd}' + f' > logs/eval_iter_{iter}.log 2>&1', shell=True, env=env, executable='/bin/bash')
165
+ handler.wait()
166
+
167
+ acc = None
168
+ # | math | 393424 | accuracy | gen | 39.00 |
169
+ with open(f'logs/eval_iter_{iter}.log', 'r') as f:
170
+ for line in f.readlines():
171
+ if 'Level 5' in line and 'AveragePass@1' in line:
172
+ parts = [p for p in line.split('|') if p.strip()]
173
+ acc = float(parts[-2])
174
+ break
175
+
176
+ print(f'Iter {iter} eval done with acc: {acc}.', flush=True)
177
+ return acc
178
+
179
+
180
+ def replace_math_dataset():
181
+ # Note: This may run failed because this is special for math test,
182
+ # and one must run swift eval --eval_dataset math first to make sure opencompass has created
183
+ # the folder.
184
+ # You can use original math dataset either. just comment this call.
185
+ user_dir = os.path.expanduser('~')
186
+ if os.path.exists(os.path.join(user_dir, '.cache', 'opencompass', 'data', 'math', 'math.json')):
187
+ os.remove(os.path.join(user_dir, '.cache', 'opencompass', 'data', 'math', 'math.json'))
188
+ shutil.copy(
189
+ os.path.join('examples', 'train', 'rft', 'math.json'),
190
+ os.path.join(user_dir, '.cache', 'opencompass', 'data', 'math', 'math.json'))
191
+
192
+
193
+ def main():
194
+ os.makedirs('logs', exist_ok=True)
195
+ max_acc = 0.
196
+ first_model = 'Qwen/Qwen2.5-Math-7B-Instruct'
197
+ model_type = 'qwen2_5_math'
198
+
199
+ if False:
200
+ # eval the original model
201
+ do_eval(first_model, None)
202
+
203
+ model = first_model
204
+ for i in range(5):
205
+ ts = time.time()
206
+ datasets = do_sample(model, model_type, ['tastelikefeet/competition_math'], i)
207
+ # add custom data filter here, for example: length or diversity control
208
+ print(f'do sample cost: {(time.time()-ts) / 60:.1f} minutes.', flush=True)
209
+ ts = time.time()
210
+ # if want to train the original dataset with datasets, add the original dataset here
211
+ # if want to train the original model everytime, change to first_model
212
+ ckpt = do_train(model, model_type, datasets, i)
213
+ print(f'do train cost: {(time.time() - ts) / 60:.1f} minutes.', flush=True)
214
+ ts = time.time()
215
+ acc = do_eval(ckpt, model_type, i)
216
+ print(f'do eval cost: {(time.time() - ts) / 60:.1f} minutes.', flush=True)
217
+ if acc > max_acc:
218
+ max_acc = acc
219
+ model = ckpt
220
+ print(f'acc: {acc}, upgrade model to : {model}', flush=True)
221
+
222
+
223
+ if __name__ == '__main__':
224
+ main()
examples/train/rlhf/README.md ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ # TIPS
2
+
3
+ Multi-modal models' RLHF are also supported! Check the multimodal folder for details.
examples/train/rlhf/cpo.sh ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ nproc_per_node=2
2
+
3
+ CUDA_VISIBLE_DEVICES=0,1 \
4
+ NPROC_PER_NODE=$nproc_per_node \
5
+ swift rlhf \
6
+ --rlhf_type cpo \
7
+ --model Qwen/Qwen2.5-7B-Instruct \
8
+ --train_type lora \
9
+ --dataset hjh0119/shareAI-Llama3-DPO-zh-en-emoji \
10
+ --load_from_cache_file true \
11
+ --split_dataset_ratio 0.01 \
12
+ --torch_dtype bfloat16 \
13
+ --num_train_epochs 1 \
14
+ --per_device_train_batch_size 1 \
15
+ --per_device_eval_batch_size 1 \
16
+ --learning_rate 1e-4 \
17
+ --lora_rank 8 \
18
+ --lora_alpha 32 \
19
+ --target_modules all-linear \
20
+ --gradient_accumulation_steps $(expr 16 / $nproc_per_node) \
21
+ --eval_steps 100 \
22
+ --save_steps 100 \
23
+ --save_total_limit 2 \
24
+ --logging_steps 5 \
25
+ --max_length 2048 \
26
+ --output_dir output \
27
+ --warmup_ratio 0.05 \
28
+ --dataloader_num_workers 4 \
29
+ --deepspeed zero2 \
30
+ --dataset_num_proc 4
examples/train/rlhf/dpo/full.sh ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # with padding_free: 4 * 47GiB, 1.90s/it
2
+ # without padding_free: 4 * 57GiB 3.32s/it
3
+ NPROC_PER_NODE=4 \
4
+ CUDA_VISIBLE_DEVICES=0,1,2,3 \
5
+ swift rlhf \
6
+ --rlhf_type dpo \
7
+ --model Qwen/Qwen2.5-7B-Instruct \
8
+ --train_type full \
9
+ --dataset hjh0119/shareAI-Llama3-DPO-zh-en-emoji \
10
+ --load_from_cache_file true \
11
+ --split_dataset_ratio 0.01 \
12
+ --torch_dtype bfloat16 \
13
+ --num_train_epochs 1 \
14
+ --per_device_train_batch_size 4 \
15
+ --per_device_eval_batch_size 4 \
16
+ --learning_rate 1e-5 \
17
+ --gradient_accumulation_steps 1 \
18
+ --eval_steps 100 \
19
+ --save_steps 100 \
20
+ --save_total_limit 2 \
21
+ --logging_steps 5 \
22
+ --max_length 8192 \
23
+ --output_dir output \
24
+ --warmup_ratio 0.05 \
25
+ --save_only_model true \
26
+ --dataloader_num_workers 4 \
27
+ --dataset_num_proc 4 \
28
+ --deepspeed zero3 \
29
+ --attn_impl flash_attn \
30
+ --rpo_alpha 0.1 \
31
+ --padding_free true
examples/train/rlhf/dpo/lora.sh ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 24GiB
2
+ # It is recommended to use padding_free. For more details, please refer to:
3
+ # https://github.com/modelscope/ms-swift/blob/main/examples/train/padding_free/dpo.sh
4
+ CUDA_VISIBLE_DEVICES=0 \
5
+ swift rlhf \
6
+ --rlhf_type dpo \
7
+ --model Qwen/Qwen2.5-7B-Instruct \
8
+ --train_type lora \
9
+ --dataset hjh0119/shareAI-Llama3-DPO-zh-en-emoji \
10
+ --load_from_cache_file true \
11
+ --split_dataset_ratio 0.01 \
12
+ --torch_dtype bfloat16 \
13
+ --num_train_epochs 1 \
14
+ --per_device_train_batch_size 1 \
15
+ --per_device_eval_batch_size 1 \
16
+ --learning_rate 1e-4 \
17
+ --lora_rank 8 \
18
+ --lora_alpha 32 \
19
+ --target_modules all-linear \
20
+ --gradient_accumulation_steps 16 \
21
+ --eval_steps 50 \
22
+ --save_steps 50 \
23
+ --save_total_limit 2 \
24
+ --logging_steps 5 \
25
+ --max_length 2048 \
26
+ --output_dir output \
27
+ --warmup_ratio 0.05 \
28
+ --dataloader_num_workers 4 \
29
+ --rpo_alpha 0.1 \
30
+ --dataset_num_proc 4
examples/train/rlhf/gkd/fast.sh ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ export teacher_model='Qwen/Qwen2.5-14B-Instruct'
3
+
4
+ NPROC_PER_NODE=4 \
5
+ CUDA_VISIBLE_DEVICES=0,1,2,3 \
6
+ swift infer \
7
+ --model $teacher_model \
8
+ --infer_backend vllm \
9
+ --val_dataset 'AI-ModelScope/alpaca-gpt4-data-en#5000' 'AI-ModelScope/alpaca-gpt4-data-zh#5000' \
10
+ --vllm_gpu_memory_utilization 0.9 \
11
+ --vllm_max_model_len 8192 \
12
+ --max_new_tokens 2048 \
13
+ --write_batch_size 10000 \
14
+ --result_path new_dataset.jsonl
15
+
16
+
17
+ # 4 * 56GiB, 1.55s/it
18
+ NPROC_PER_NODE=4 \
19
+ PYTORCH_CUDA_ALLOC_CONF='expandable_segments:True' \
20
+ CUDA_VISIBLE_DEVICES=0,1,2,3 \
21
+ swift rlhf \
22
+ --rlhf_type gkd \
23
+ --model Qwen/Qwen2.5-7B \
24
+ --teacher_model $teacher_model \
25
+ --train_type full \
26
+ --dataset 'new_dataset.jsonl' \
27
+ --load_from_cache_file true \
28
+ --split_dataset_ratio 0.01 \
29
+ --torch_dtype bfloat16 \
30
+ --num_train_epochs 1 \
31
+ --per_device_train_batch_size 4 \
32
+ --per_device_eval_batch_size 4 \
33
+ --learning_rate 1e-5 \
34
+ --gradient_accumulation_steps 1 \
35
+ --eval_steps 100 \
36
+ --save_steps 100 \
37
+ --save_total_limit 2 \
38
+ --logging_steps 5 \
39
+ --max_length 4096 \
40
+ --output_dir output \
41
+ --warmup_ratio 0.05 \
42
+ --save_only_model true \
43
+ --dataloader_num_workers 4 \
44
+ --dataset_num_proc 4 \
45
+ --deepspeed zero3 \
46
+ --padding_free true \
47
+ --attn_impl flash_attn \
48
+ --lmbda 0
examples/train/rlhf/gkd/full.sh ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 4 * 66GiB, 46s/it
2
+ NPROC_PER_NODE=4 \
3
+ PYTORCH_CUDA_ALLOC_CONF='expandable_segments:True' \
4
+ CUDA_VISIBLE_DEVICES=0,1,2,3 \
5
+ swift rlhf \
6
+ --rlhf_type gkd \
7
+ --model Qwen/Qwen2.5-7B \
8
+ --teacher_model Qwen/Qwen2.5-14B-Instruct \
9
+ --train_type full \
10
+ --dataset 'AI-ModelScope/alpaca-gpt4-data-en#2000' 'AI-ModelScope/alpaca-gpt4-data-zh#2000' \
11
+ --split_dataset_ratio 0.01 \
12
+ --seq_kd true \
13
+ --torch_dtype bfloat16 \
14
+ --num_train_epochs 1 \
15
+ --per_device_train_batch_size 4 \
16
+ --per_device_eval_batch_size 4 \
17
+ --learning_rate 1e-5 \
18
+ --gradient_accumulation_steps 1 \
19
+ --eval_steps 50 \
20
+ --save_steps 50 \
21
+ --save_total_limit 2 \
22
+ --logging_steps 5 \
23
+ --max_length 2048 \
24
+ --max_completion_length 512 \
25
+ --output_dir output \
26
+ --warmup_ratio 0.05 \
27
+ --save_only_model true \
28
+ --dataloader_num_workers 4 \
29
+ --dataset_num_proc 4 \
30
+ --deepspeed zero3 \
31
+ --attn_impl flash_attn
examples/train/rlhf/gkd/think_model.sh ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ export teacher_model='Qwen/Qwen3-8B'
3
+
4
+ NPROC_PER_NODE=4 \
5
+ CUDA_VISIBLE_DEVICES=0,1,2,3 \
6
+ swift infer \
7
+ --model $teacher_model \
8
+ --infer_backend vllm \
9
+ --val_dataset 'AI-ModelScope/alpaca-gpt4-data-en#5000' 'AI-ModelScope/alpaca-gpt4-data-zh#5000' \
10
+ --vllm_gpu_memory_utilization 0.9 \
11
+ --vllm_max_model_len 8192 \
12
+ --max_new_tokens 2048 \
13
+ --write_batch_size 10000 \
14
+ --result_path new_dataset.jsonl
15
+
16
+
17
+ # 4 * 67GiB, 2.50s/it
18
+ # You need to additionally add sft_loss, because tokens like '<think>' have not been trained.
19
+ NPROC_PER_NODE=4 \
20
+ PYTORCH_CUDA_ALLOC_CONF='expandable_segments:True' \
21
+ CUDA_VISIBLE_DEVICES=0,1,2,3 \
22
+ swift rlhf \
23
+ --rlhf_type gkd \
24
+ --model Qwen/Qwen3-8B-Base \
25
+ --teacher_model $teacher_model \
26
+ --train_type full \
27
+ --dataset 'new_dataset.jsonl' \
28
+ --load_from_cache_file true \
29
+ --split_dataset_ratio 0.01 \
30
+ --torch_dtype bfloat16 \
31
+ --num_train_epochs 1 \
32
+ --learning_rate 1e-5 \
33
+ --per_device_train_batch_size 1 \
34
+ --per_device_eval_batch_size 1 \
35
+ --gradient_accumulation_steps 1 \
36
+ --eval_steps 100 \
37
+ --save_steps 100 \
38
+ --save_total_limit 2 \
39
+ --logging_steps 5 \
40
+ --max_length 4096 \
41
+ --output_dir output \
42
+ --warmup_ratio 0.05 \
43
+ --save_only_model true \
44
+ --dataloader_num_workers 4 \
45
+ --dataset_num_proc 4 \
46
+ --deepspeed zero3 \
47
+ --packing true \
48
+ --attn_impl flash_attn \
49
+ --sft_alpha 0.1 \
50
+ --lmbda 0
examples/train/rlhf/kto.sh ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ nproc_per_node=2
2
+
3
+ CUDA_VISIBLE_DEVICES=0,1 \
4
+ NPROC_PER_NODE=$nproc_per_node \
5
+ swift rlhf \
6
+ --rlhf_type kto \
7
+ --model Qwen/Qwen2.5-7B-Instruct \
8
+ --train_type lora \
9
+ --dataset 'AI-ModelScope/ultrafeedback-binarized-preferences-cleaned-kto#10000' \
10
+ --load_from_cache_file true \
11
+ --split_dataset_ratio 0.01 \
12
+ --num_train_epochs 1 \
13
+ --per_device_train_batch_size 1 \
14
+ --per_device_eval_batch_size 1 \
15
+ --learning_rate 1e-4 \
16
+ --lora_rank 8 \
17
+ --lora_alpha 32 \
18
+ --target_modules all-linear \
19
+ --gradient_accumulation_steps $(expr 16 / $nproc_per_node) \
20
+ --eval_steps 100 \
21
+ --save_steps 100 \
22
+ --save_total_limit 2 \
23
+ --logging_steps 5 \
24
+ --max_length 2048 \
25
+ --output_dir output \
26
+ --warmup_ratio 0.05 \
27
+ --dataloader_num_workers 4 \
28
+ --deepspeed zero2 \
29
+ --dataset_num_proc 4
examples/train/rlhf/mpo.sh ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # https://arxiv.org/abs/2411.10442
2
+ # modified from swift/examples/train/multimodal/rlhf/dpo/full.sh
3
+ nproc_per_node=4
4
+
5
+ PYTORCH_CUDA_ALLOC_CONF='expandable_segments:True' \
6
+ CUDA_VISIBLE_DEVICES=0,1,2,3 \
7
+ NPROC_PER_NODE=$nproc_per_node \
8
+ MAX_PIXELS=1003520 \
9
+ swift rlhf \
10
+ --rlhf_type dpo \
11
+ --model Qwen/Qwen2.5-VL-7B-Instruct \
12
+ --dataset 'swift/RLAIF-V-Dataset#20000' \
13
+ --load_from_cache_file true \
14
+ --split_dataset_ratio 0.01 \
15
+ --train_type full \
16
+ --torch_dtype bfloat16 \
17
+ --loss_type sigmoid bco_pair sft \
18
+ --loss_weights 0.8 0.2 1.0 \
19
+ --rpo_alpha 0.0 \
20
+ --num_train_epochs 1 \
21
+ --per_device_train_batch_size 1 \
22
+ --per_device_eval_batch_size 1 \
23
+ --learning_rate 1e-5 \
24
+ --freeze_vit true \
25
+ --gradient_accumulation_steps $(expr 16 / $nproc_per_node) \
26
+ --eval_steps 100 \
27
+ --save_steps 100 \
28
+ --save_total_limit 2 \
29
+ --deepspeed zero3 \
30
+ --logging_steps 5 \
31
+ --max_length 4096 \
32
+ --warmup_ratio 0.05 \
33
+ --dataloader_num_workers 4 \
34
+ --dataset_num_proc 4 \
35
+ --save_only_model true
examples/train/rlhf/orpo.sh ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ nproc_per_node=2
2
+
3
+ CUDA_VISIBLE_DEVICES=0,1 \
4
+ NPROC_PER_NODE=$nproc_per_node \
5
+ swift rlhf \
6
+ --rlhf_type orpo \
7
+ --model Qwen/Qwen2.5-7B-Instruct \
8
+ --train_type lora \
9
+ --dataset hjh0119/shareAI-Llama3-DPO-zh-en-emoji \
10
+ --load_from_cache_file true \
11
+ --split_dataset_ratio 0.01 \
12
+ --torch_dtype bfloat16 \
13
+ --num_train_epochs 1 \
14
+ --per_device_train_batch_size 1 \
15
+ --per_device_eval_batch_size 1 \
16
+ --learning_rate 1e-4 \
17
+ --lora_rank 8 \
18
+ --lora_alpha 32 \
19
+ --target_modules all-linear \
20
+ --gradient_accumulation_steps $(expr 16 / $nproc_per_node) \
21
+ --eval_steps 100 \
22
+ --save_steps 100 \
23
+ --save_total_limit 2 \
24
+ --logging_steps 5 \
25
+ --max_length 2048 \
26
+ --output_dir output \
27
+ --warmup_ratio 0.05 \
28
+ --dataloader_num_workers 4 \
29
+ --deepspeed zero2 \
30
+ --dataset_num_proc 4
examples/train/rlhf/ppo/full.sh ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 8 * 65 GiB
2
+ # Currently, it only supports the case where the model and reward_model use the same template/tokenizer.
3
+ # Currently, multimodal model PPO is not supported.
4
+
5
+ # pip install "deepspeed==0.14.*"
6
+ nproc_per_node=8
7
+
8
+ PYTORCH_CUDA_ALLOC_CONF='expandable_segments:True' \
9
+ CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 \
10
+ NPROC_PER_NODE=$nproc_per_node \
11
+ swift rlhf \
12
+ --rlhf_type ppo \
13
+ --model LLM-Research/Meta-Llama-3.1-8B-Instruct \
14
+ --reward_model 'AI-ModelScope/Skywork-Reward-Llama-3.1-8B-v0.2' \
15
+ --train_type full \
16
+ --dataset 'AI-ModelScope/alpaca-gpt4-data-zh#20000' 'AI-ModelScope/alpaca-gpt4-data-en#20000' \
17
+ --load_from_cache_file true \
18
+ --split_dataset_ratio 0.01 \
19
+ --torch_dtype bfloat16 \
20
+ --num_train_epochs 1 \
21
+ --per_device_train_batch_size 1 \
22
+ --per_device_eval_batch_size 1 \
23
+ --learning_rate 1e-6 \
24
+ --gradient_accumulation_steps $(expr 16 / $nproc_per_node) \
25
+ --eval_steps 100 \
26
+ --save_steps 100 \
27
+ --save_total_limit 2 \
28
+ --logging_steps 5 \
29
+ --max_length 2048 \
30
+ --output_dir output \
31
+ --warmup_ratio 0.05 \
32
+ --dataloader_num_workers 4 \
33
+ --deepspeed zero3 \
34
+ --response_length 512 \
35
+ --temperature 0.7 \
36
+ --dataset_num_proc 4 \
37
+ --save_only_model true
examples/train/rlhf/ppo/lora.sh ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 4 * 50GiB
2
+ # Currently, it only supports the case where the model and reward_model use the same template/tokenizer.
3
+ # Currently, multimodal model PPO is not supported.
4
+
5
+ # pip install "deepspeed==0.14.*"
6
+ nproc_per_node=4
7
+
8
+ PYTORCH_CUDA_ALLOC_CONF='expandable_segments:True' \
9
+ CUDA_VISIBLE_DEVICES=0,1,2,3 \
10
+ NPROC_PER_NODE=$nproc_per_node \
11
+ swift rlhf \
12
+ --rlhf_type ppo \
13
+ --model LLM-Research/Meta-Llama-3.1-8B-Instruct \
14
+ --reward_model 'AI-ModelScope/Skywork-Reward-Llama-3.1-8B-v0.2' \
15
+ --train_type lora \
16
+ --dataset 'AI-ModelScope/alpaca-gpt4-data-zh#20000' 'AI-ModelScope/alpaca-gpt4-data-en#20000' \
17
+ --load_from_cache_file true \
18
+ --split_dataset_ratio 0.01 \
19
+ --torch_dtype bfloat16 \
20
+ --num_train_epochs 1 \
21
+ --per_device_train_batch_size 1 \
22
+ --per_device_eval_batch_size 1 \
23
+ --learning_rate 1e-5 \
24
+ --lora_rank 8 \
25
+ --lora_alpha 32 \
26
+ --target_modules all-linear \
27
+ --gradient_accumulation_steps $(expr 16 / $nproc_per_node) \
28
+ --eval_steps 100 \
29
+ --save_steps 100 \
30
+ --save_total_limit 2 \
31
+ --logging_steps 5 \
32
+ --max_length 2048 \
33
+ --output_dir output \
34
+ --warmup_ratio 0.05 \
35
+ --dataloader_num_workers 4 \
36
+ --deepspeed zero2 \
37
+ --response_length 512 \
38
+ --temperature 0.7 \
39
+ --dataset_num_proc 4 \
40
+ --save_only_model true
examples/train/rlhf/rm.sh ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ nproc_per_node=2
2
+
3
+ CUDA_VISIBLE_DEVICES=0,1 \
4
+ NPROC_PER_NODE=$nproc_per_node \
5
+ swift rlhf \
6
+ --rlhf_type rm \
7
+ --model Qwen/Qwen2.5-7B-Instruct \
8
+ --train_type lora \
9
+ --dataset hjh0119/shareAI-Llama3-DPO-zh-en-emoji \
10
+ --load_from_cache_file true \
11
+ --split_dataset_ratio 0.01 \
12
+ --torch_dtype bfloat16 \
13
+ --num_train_epochs 1 \
14
+ --per_device_train_batch_size 1 \
15
+ --per_device_eval_batch_size 1 \
16
+ --learning_rate 1e-4 \
17
+ --lora_rank 8 \
18
+ --lora_alpha 32 \
19
+ --target_modules all-linear \
20
+ --gradient_accumulation_steps $(expr 16 / $nproc_per_node) \
21
+ --eval_steps 100 \
22
+ --save_steps 100 \
23
+ --save_total_limit 2 \
24
+ --logging_steps 5 \
25
+ --max_length 2048 \
26
+ --output_dir output \
27
+ --warmup_ratio 0.05 \
28
+ --dataloader_num_workers 4 \
29
+ --deepspeed zero2 \
30
+ --dataset_num_proc 4
examples/train/rlhf/simpo.sh ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 2*50GB
2
+ nproc_per_node=2
3
+
4
+ CUDA_VISIBLE_DEVICES=0,1 \
5
+ NPROC_PER_NODE=$nproc_per_node \
6
+ swift rlhf \
7
+ --rlhf_type simpo \
8
+ --model Qwen/Qwen2.5-3B-Instruct \
9
+ --train_type full \
10
+ --dataset hjh0119/shareAI-Llama3-DPO-zh-en-emoji \
11
+ --load_from_cache_file true \
12
+ --split_dataset_ratio 0.01 \
13
+ --torch_dtype bfloat16 \
14
+ --num_train_epochs 1 \
15
+ --per_device_train_batch_size 1 \
16
+ --per_device_eval_batch_size 1 \
17
+ --learning_rate 1e-5 \
18
+ --gradient_accumulation_steps $(expr 16 / $nproc_per_node) \
19
+ --eval_steps 100 \
20
+ --save_steps 100 \
21
+ --save_total_limit 2 \
22
+ --logging_steps 5 \
23
+ --max_length 2048 \
24
+ --output_dir output \
25
+ --warmup_ratio 0.05 \
26
+ --dataloader_num_workers 4 \
27
+ --deepspeed zero2 \
28
+ --dataset_num_proc 4
examples/train/seq_cls/bert/deploy.sh ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ CUDA_VISIBLE_DEVICES=0 \
2
+ swift deploy \
3
+ --adapters output/vx-xxx/checkpoint-xxx \
4
+ --served_model_name bert-base-chinese \
5
+ --truncation_strategy right \
6
+ --max_length 512
7
+
8
+ # curl http://localhost:8000/v1/chat/completions -H "Content-Type: application/json" -d '{
9
+ # "model": "bert-base-chinese",
10
+ # "messages": [{"role": "user", "content": "包装差,容易被调包。"}]
11
+ # }'
examples/train/seq_cls/bert/infer.sh ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ CUDA_VISIBLE_DEVICES=0 \
2
+ swift infer \
3
+ --adapters output/vx-xxx/checkpoint-xxx \
4
+ --load_data_args true \
5
+ --max_batch_size 16 \
6
+ --truncation_strategy right \
7
+ --max_length 512
examples/train/seq_cls/bert/sft.sh ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # If `num_labels` is provided, it will be considered a classification task,
2
+ # and AutoModelForSequenceClassification will be used to load the model.
3
+ # The BERT model does not require templates, so it can usually be used without registration.
4
+ CUDA_VISIBLE_DEVICES=0 \
5
+ swift sft \
6
+ --model AI-ModelScope/bert-base-chinese \
7
+ --train_type lora \
8
+ --dataset 'DAMO_NLP/jd:cls#2000' \
9
+ --load_from_cache_file true \
10
+ --split_dataset_ratio 0.01 \
11
+ --torch_dtype bfloat16 \
12
+ --num_train_epochs 1 \
13
+ --per_device_train_batch_size 1 \
14
+ --per_device_eval_batch_size 1 \
15
+ --learning_rate 1e-4 \
16
+ --lora_rank 8 \
17
+ --lora_alpha 32 \
18
+ --target_modules all-linear \
19
+ --gradient_accumulation_steps 16 \
20
+ --eval_steps 50 \
21
+ --save_steps 50 \
22
+ --save_total_limit 2 \
23
+ --logging_steps 5 \
24
+ --max_length 512 \
25
+ --truncation_strategy right \
26
+ --output_dir output \
27
+ --warmup_ratio 0.05 \
28
+ --dataloader_num_workers 4 \
29
+ --num_labels 2 \
30
+ --task_type seq_cls
examples/train/seq_cls/multi_label/sft.sh ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Custom dataset format reference: https://swift.readthedocs.io/en/latest/Customization/Custom-dataset.html
2
+ CUDA_VISIBLE_DEVICES=0 \
3
+ swift sft \
4
+ --model Qwen/Qwen2.5-0.5B \
5
+ --train_type lora \
6
+ --dataset '<your-dataset>' \
7
+ --load_from_cache_file true \
8
+ --split_dataset_ratio 0.01 \
9
+ --torch_dtype bfloat16 \
10
+ --num_train_epochs 1 \
11
+ --per_device_train_batch_size 16 \
12
+ --per_device_eval_batch_size 16 \
13
+ --learning_rate 1e-4 \
14
+ --lora_rank 8 \
15
+ --lora_alpha 32 \
16
+ --target_modules all-linear \
17
+ --gradient_accumulation_steps 1 \
18
+ --eval_steps 100 \
19
+ --save_steps 100 \
20
+ --save_total_limit 2 \
21
+ --logging_steps 5 \
22
+ --max_length 2048 \
23
+ --output_dir output \
24
+ --warmup_ratio 0.05 \
25
+ --dataloader_num_workers 4 \
26
+ --dataset_num_proc 4 \
27
+ --num_labels '<num-labels>' \
28
+ --task_type seq_cls \
29
+ --use_chat_template false \
30
+ --problem_type multi_label_classification
examples/train/seq_cls/qwen2_5/deploy.sh ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ CUDA_VISIBLE_DEVICES=0 \
2
+ swift deploy \
3
+ --adapters output/vx-xxx/checkpoint-xxx
4
+
5
+ # curl http://localhost:8000/v1/chat/completions -H "Content-Type: application/json" -d '{
6
+ # "model": "Qwen2.5-0.5B",
7
+ # "messages": [{"role": "user", "content": "包装差,容易被调包。"}]
8
+ # }'
examples/train/seq_cls/qwen2_5/infer.sh ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ CUDA_VISIBLE_DEVICES=0 \
2
+ swift infer \
3
+ --adapters output/vx-xxx/checkpoint-xxx \
4
+ --load_data_args true \
5
+ --max_batch_size 16
examples/train/seq_cls/qwen2_5/sft.sh ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # If `num_labels` is provided, it will be considered a classification task,
2
+ # and AutoModelForSequenceClassification will be used to load the model.
3
+ # You can also specify `--model Qwen/Qwen2.5-0.5B-Instruct --use_chat_template true`.
4
+ CUDA_VISIBLE_DEVICES=0 \
5
+ swift sft \
6
+ --model Qwen/Qwen2.5-0.5B \
7
+ --train_type lora \
8
+ --dataset 'DAMO_NLP/jd:cls#2000' \
9
+ --load_from_cache_file true \
10
+ --split_dataset_ratio 0.01 \
11
+ --torch_dtype bfloat16 \
12
+ --num_train_epochs 1 \
13
+ --per_device_train_batch_size 1 \
14
+ --per_device_eval_batch_size 1 \
15
+ --learning_rate 1e-4 \
16
+ --lora_rank 8 \
17
+ --lora_alpha 32 \
18
+ --target_modules all-linear \
19
+ --gradient_accumulation_steps 16 \
20
+ --eval_steps 50 \
21
+ --save_steps 50 \
22
+ --save_total_limit 2 \
23
+ --logging_steps 5 \
24
+ --max_length 2048 \
25
+ --output_dir output \
26
+ --warmup_ratio 0.05 \
27
+ --dataloader_num_workers 4 \
28
+ --num_labels 2 \
29
+ --task_type seq_cls \
30
+ --use_chat_template false
examples/train/seq_cls/qwen2_5_omni/infer.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+
3
+ from swift.llm import BaseArguments, InferRequest, PtEngine, get_template
4
+
5
+ os.environ['MAX_PIXELS'] = '1003520'
6
+
7
+ infer_request = InferRequest(
8
+ messages=[{
9
+ 'role': 'user',
10
+ 'content': 'Task: Classify household waste.'
11
+ }], images=['xxx.jpg'])
12
+ adapter_path = 'output/vx-xxx/checkpoint-xxx'
13
+ args = BaseArguments.from_pretrained(adapter_path)
14
+
15
+ engine = PtEngine(args.model, adapters=[adapter_path], task_type='seq_cls', num_labels=args.num_labels)
16
+ template = get_template(args.template, engine.processor, args.system, use_chat_template=args.use_chat_template)
17
+ engine.default_template = template
18
+
19
+ resp_list = engine.infer([infer_request])
20
+ response: int = resp_list[0].choices[0].message.content
21
+ print(f'response: {response}')
examples/train/seq_cls/qwen2_5_omni/infer.sh ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ CUDA_VISIBLE_DEVICES=0 \
2
+ MAX_PIXELS=1003520 \
3
+ swift infer \
4
+ --adapters output/vx-xxx/checkpoint-xxx \
5
+ --load_data_args true
examples/train/seq_cls/qwen2_5_omni/sft.sh ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ CUDA_VISIBLE_DEVICES=0 \
2
+ MAX_PIXELS=1003520 \
3
+ swift sft \
4
+ --model Qwen/Qwen2.5-Omni-3B \
5
+ --train_type lora \
6
+ --dataset 'tany0699/garbage265#20000' \
7
+ --load_from_cache_file true \
8
+ --split_dataset_ratio 0.01 \
9
+ --torch_dtype bfloat16 \
10
+ --num_train_epochs 1 \
11
+ --per_device_train_batch_size 1 \
12
+ --per_device_eval_batch_size 1 \
13
+ --learning_rate 1e-4 \
14
+ --lora_rank 8 \
15
+ --lora_alpha 32 \
16
+ --target_modules all-linear \
17
+ --gradient_accumulation_steps 16 \
18
+ --eval_steps 50 \
19
+ --save_steps 50 \
20
+ --save_total_limit 2 \
21
+ --logging_steps 5 \
22
+ --max_length 2048 \
23
+ --output_dir output \
24
+ --warmup_ratio 0.05 \
25
+ --dataloader_num_workers 4 \
26
+ --num_labels 265 \
27
+ --task_type seq_cls \
28
+ --use_chat_template true
examples/train/seq_cls/regression/deploy.sh ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ CUDA_VISIBLE_DEVICES=0 \
2
+ swift deploy \
3
+ --adapters output/vx-xxx/checkpoint-xxx
4
+
5
+ # curl http://localhost:8000/v1/chat/completions -H "Content-Type: application/json" -d '{
6
+ # "model": "Qwen2.5-0.5B",
7
+ # "messages": [{"role": "user", "content": "Task: Based on the given two sentences, provide a similarity score between 0.0 and 1.0.\nSentence 1: The animal is eating.\nSentence 2: A woman is dancing.\nSimilarity score: "}]
8
+ # }'
examples/train/seq_cls/regression/infer.sh ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ CUDA_VISIBLE_DEVICES=0 \
2
+ swift infer \
3
+ --adapters output/vx-xxx/checkpoint-xxx \
4
+ --load_data_args true \
5
+ --max_batch_size 16
examples/train/seq_cls/regression/sft.sh ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 2GB
2
+ CUDA_VISIBLE_DEVICES=0 \
3
+ swift sft \
4
+ --model Qwen/Qwen2.5-0.5B \
5
+ --train_type lora \
6
+ --dataset 'sentence-transformers/stsb:reg#20000' \
7
+ --load_from_cache_file true \
8
+ --split_dataset_ratio 0.01 \
9
+ --torch_dtype bfloat16 \
10
+ --num_train_epochs 1 \
11
+ --per_device_train_batch_size 16 \
12
+ --per_device_eval_batch_size 16 \
13
+ --learning_rate 1e-4 \
14
+ --lora_rank 8 \
15
+ --lora_alpha 32 \
16
+ --target_modules all-linear \
17
+ --gradient_accumulation_steps 1 \
18
+ --eval_steps 100 \
19
+ --save_steps 100 \
20
+ --save_total_limit 2 \
21
+ --logging_steps 5 \
22
+ --max_length 2048 \
23
+ --output_dir output \
24
+ --warmup_ratio 0.05 \
25
+ --dataloader_num_workers 4 \
26
+ --dataset_num_proc 4 \
27
+ --num_labels 1 \
28
+ --task_type seq_cls \
29
+ --use_chat_template false \
30
+ --problem_type regression
examples/train/sequence_parallel/sequence_parallel.sh ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Env: 8 * A100
2
+ # Max Length: 65536
3
+ # GPU Memory: 8 * 40GiB, Training Speed 26s/it
4
+ NPROC_PER_NODE=8 \
5
+ CELOSS_PARALLEL_SIZE=2048 \
6
+ swift sft \
7
+ --model Qwen/Qwen2.5-3B-Instruct \
8
+ --dataset 'AI-ModelScope/LongAlpaca-12k' \
9
+ --load_from_cache_file true \
10
+ --train_type lora \
11
+ --torch_dtype bfloat16 \
12
+ --per_device_train_batch_size 4 \
13
+ --target_modules all-linear \
14
+ --gradient_accumulation_steps 8 \
15
+ --save_total_limit 2 \
16
+ --save_only_model true \
17
+ --save_steps 50 \
18
+ --max_length 65536 \
19
+ --warmup_ratio 0.05 \
20
+ --attn_impl flash_attn \
21
+ --sequence_parallel_size 8 \
22
+ --logging_steps 1 \
23
+ --use_logits_to_keep false \
24
+ --padding_free true \
examples/train/sequence_parallel/sequence_parallel_512k.sh ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Env: 8 * A100
2
+ # Max Length: 512000
3
+ # GPU Memory: 8 * 80GiB, Training Speed 150s/it
4
+ NPROC_PER_NODE=8 \
5
+ CELOSS_PARALLEL_SIZE=2048 \
6
+ swift sft \
7
+ --model Qwen/QwQ-32B \
8
+ --train_type lora \
9
+ --dataset 'AI-ModelScope/LongAlpaca-12k' \
10
+ --load_from_cache_file true \
11
+ --split_dataset_ratio 0.01 \
12
+ --torch_dtype bfloat16 \
13
+ --per_device_train_batch_size 1 \
14
+ --per_device_eval_batch_size 1 \
15
+ --learning_rate 1e-5 \
16
+ --gradient_accumulation_steps 2 \
17
+ --packing true \
18
+ --rope_scaling yarn \
19
+ --max_length 512000 \
20
+ --max_model_len 512000 \
21
+ --eval_steps 200 \
22
+ --save_steps 200 \
23
+ --logging_steps 5 \
24
+ --warmup_ratio 0.05 \
25
+ --dataloader_num_workers 8 \
26
+ --dataset_num_proc 8 \
27
+ --save_total_limit 2 \
28
+ --use_liger_kernel true \
29
+ --save_only_model true \
30
+ --deepspeed zero3_offload \
31
+ --attn_impl flash_attn \
32
+ --sequence_parallel_size 8
examples/train/sequence_parallel/sequence_parallel_dpo.sh ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Env: 4 * A100
2
+ # GPU Memory: 4 * 25GiB, Training Speed 14s/it
3
+ NPROC_PER_NODE=4 \
4
+ CUDA_VISIBLE_DEVICES=0,1,2,3 \
5
+ swift rlhf \
6
+ --rlhf_type dpo \
7
+ --model Qwen/Qwen2.5-VL-3B-Instruct \
8
+ --train_type full \
9
+ --dataset swift/RLAIF-V-Dataset \
10
+ --load_from_cache_file true \
11
+ --split_dataset_ratio 0.01 \
12
+ --torch_dtype bfloat16 \
13
+ --per_device_train_batch_size 1 \
14
+ --per_device_eval_batch_size 1 \
15
+ --learning_rate 1e-5 \
16
+ --gradient_accumulation_steps 8 \
17
+ --eval_steps 200 \
18
+ --save_steps 200 \
19
+ --logging_steps 5 \
20
+ --warmup_ratio 0.05 \
21
+ --dataloader_num_workers 8 \
22
+ --dataset_num_proc 8 \
23
+ --save_total_limit 2 \
24
+ --save_only_model true \
25
+ --output_dir output/Qwen2.5-VL-3B-Instruct \
26
+ --deepspeed zero3 \
27
+ --attn_impl flash_attn \
28
+ --use_liger_kernel true \
29
+ --sequence_parallel_size 4
examples/train/sequence_parallel/sequence_parallel_grpo.sh ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ NPROC_PER_NODE=8 \
2
+ PYTORCH_CUDA_ALLOC_CONF='' \
3
+ swift rlhf \
4
+ --rlhf_type grpo \
5
+ --model Qwen/Qwen2.5-7B \
6
+ --train_type full \
7
+ --use_vllm true \
8
+ --vllm_mode colocate \
9
+ --vllm_gpu_memory_utilization 0.5 \
10
+ --vllm_max_model_len 2048 \
11
+ --vllm_tensor_parallel_size 4 \
12
+ --dataset AI-MO/NuminaMath-TIR#5000 \
13
+ --load_from_cache_file true \
14
+ --torch_dtype bfloat16 \
15
+ --num_train_epochs 1 \
16
+ --max_length 2048 \
17
+ --per_device_train_batch_size 4 \
18
+ --per_device_eval_batch_size 4 \
19
+ --gradient_accumulation_steps 8 \
20
+ --eval_steps 1000 \
21
+ --save_steps 1000 \
22
+ --learning_rate 1e-6 \
23
+ --save_total_limit 2 \
24
+ --logging_steps 5 \
25
+ --output_dir output \
26
+ --warmup_ratio 0.05 \
27
+ --dataloader_num_workers 4 \
28
+ --max_completion_length 1024 \
29
+ --reward_funcs accuracy format \
30
+ --num_generations 32 \
31
+ --system examples/train/grpo/prompt.txt \
32
+ --deepspeed zero3 \
33
+ --temperature 1.0 \
34
+ --top_p 1.0 \
35
+ --top_k 80 \
36
+ --attn_impl flash_attn \
37
+ --log_completions true \
38
+ --async_generate false \
39
+ --offload_optimizer true \
40
+ --offload_model true \
41
+ --padding_free true \
42
+ --sequence_parallel_size 4 \
43
+ --dataloader_drop_last true \
44
+ --sleep_level 1
examples/train/streaming/lazy_tokenize.sh ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 17GiB
2
+ CUDA_VISIBLE_DEVICES=0 \
3
+ swift sft \
4
+ --model Qwen/Qwen2.5-7B-Instruct \
5
+ --train_type lora \
6
+ --dataset 'swift/self-cognition#1000' \
7
+ --num_train_epochs 1 \
8
+ --per_device_train_batch_size 1 \
9
+ --learning_rate 1e-4 \
10
+ --lora_rank 8 \
11
+ --lora_alpha 32 \
12
+ --gradient_accumulation_steps 16 \
13
+ --eval_steps 100 \
14
+ --save_steps 100 \
15
+ --save_total_limit 2 \
16
+ --logging_steps 5 \
17
+ --lazy_tokenize true \
18
+ --model_author swift \
19
+ --model_name swift-robot
examples/train/streaming/streaming.sh ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ CUDA_VISIBLE_DEVICES=0 \
2
+ swift sft \
3
+ --model Qwen/Qwen2.5-7B-Instruct \
4
+ --train_type lora \
5
+ --dataset 'swift/self-cognition#1000' \
6
+ --streaming true \
7
+ --max_steps 1000 \
8
+ --learning_rate 1e-4 \
9
+ --lora_rank 8 \
10
+ --lora_alpha 32 \
11
+ --gradient_accumulation_steps 16 \
12
+ --eval_steps 100 \
13
+ --save_steps 100 \
14
+ --save_total_limit 2 \
15
+ --logging_steps 5 \
16
+ --model_author swift \
17
+ --model_name swift-robot
examples/train/think_model/deepseek_r1.sh ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 18GB
2
+ CUDA_VISIBLE_DEVICES=0 \
3
+ swift sft \
4
+ --model deepseek-ai/DeepSeek-R1-0528-Qwen3-8B \
5
+ --train_type lora \
6
+ --dataset 'swift/DeepSeek-R1-Qwen3-8B-Distill#1800' \
7
+ 'swift/self-cognition:empty_think#600' \
8
+ --loss_scale ignore_empty_think \
9
+ --torch_dtype bfloat16 \
10
+ --num_train_epochs 1 \
11
+ --per_device_train_batch_size 1 \
12
+ --per_device_eval_batch_size 1 \
13
+ --learning_rate 1e-4 \
14
+ --lora_rank 8 \
15
+ --lora_alpha 32 \
16
+ --target_modules all-linear \
17
+ --gradient_accumulation_steps 16 \
18
+ --load_from_cache_file false \
19
+ --eval_steps 50 \
20
+ --save_steps 50 \
21
+ --save_total_limit 2 \
22
+ --logging_steps 5 \
23
+ --max_length 2048 \
24
+ --output_dir output \
25
+ --warmup_ratio 0.05 \
26
+ --dataloader_num_workers 4 \
27
+ --use_liger_kernel true \
28
+ --model_author swift \
29
+ --model_name swift-robot
examples/train/think_model/qwen3_demo1.sh ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # use `--loss_scale ignore_empty_think`
2
+ # Avoid losing the think capability by ignoring the loss of empty `<think>\n\n</think>\n\n`
3
+ # This method is also applicable to the Deepseek-R1 series of models.
4
+ CUDA_VISIBLE_DEVICES=0 \
5
+ swift sft \
6
+ --model Qwen/Qwen3-8B \
7
+ --train_type lora \
8
+ --dataset 'swift/Qwen3-SFT-Mixin#2000' \
9
+ 'swift/self-cognition:empty_think#600' \
10
+ --torch_dtype bfloat16 \
11
+ --num_train_epochs 1 \
12
+ --per_device_train_batch_size 1 \
13
+ --per_device_eval_batch_size 1 \
14
+ --learning_rate 1e-4 \
15
+ --lora_rank 8 \
16
+ --lora_alpha 32 \
17
+ --target_modules all-linear \
18
+ --gradient_accumulation_steps 16 \
19
+ --eval_steps 50 \
20
+ --save_steps 50 \
21
+ --save_total_limit 2 \
22
+ --logging_steps 5 \
23
+ --max_length 2048 \
24
+ --output_dir output \
25
+ --warmup_ratio 0.05 \
26
+ --dataloader_num_workers 4 \
27
+ --use_liger_kernel true \
28
+ --load_from_cache_file false \
29
+ --loss_scale ignore_empty_think \
30
+ --model_author swift \
31
+ --model_name swift-robot
examples/train/think_model/qwen3_demo2.sh ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # use `swift/self-cognition:qwen3`
2
+ # Avoid losing the thinking capability by appending `/no_think` to the dataset query.
3
+ # https://github.com/modelscope/ms-swift/blob/77985c2ccdac8ed4037174ee222e79d1f1d5059d/swift/llm/dataset/dataset/llm.py#L835
4
+ CUDA_VISIBLE_DEVICES=0 \
5
+ swift sft \
6
+ --model Qwen/Qwen3-8B \
7
+ --train_type lora \
8
+ --dataset 'swift/Qwen3-SFT-Mixin#2000' \
9
+ 'swift/self-cognition:qwen3#600' \
10
+ --torch_dtype bfloat16 \
11
+ --num_train_epochs 1 \
12
+ --per_device_train_batch_size 1 \
13
+ --per_device_eval_batch_size 1 \
14
+ --learning_rate 1e-4 \
15
+ --lora_rank 8 \
16
+ --lora_alpha 32 \
17
+ --target_modules all-linear \
18
+ --gradient_accumulation_steps 16 \
19
+ --eval_steps 50 \
20
+ --save_steps 50 \
21
+ --save_total_limit 2 \
22
+ --logging_steps 5 \
23
+ --max_length 2048 \
24
+ --output_dir output \
25
+ --warmup_ratio 0.05 \
26
+ --dataloader_num_workers 4 \
27
+ --use_liger_kernel true \
28
+ --load_from_cache_file false \
29
+ --model_author swift \
30
+ --model_name swift-robot
examples/train/tuners/adalora/train.sh ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 17GiB
2
+ CUDA_VISIBLE_DEVICES=0 \
3
+ swift sft \
4
+ --model Qwen/Qwen2.5-7B-Instruct \
5
+ --train_type adalora \
6
+ --dataset 'swift/self-cognition#1000' \
7
+ --num_train_epochs 1 \
8
+ --per_device_train_batch_size 1 \
9
+ --learning_rate 1e-4 \
10
+ --gradient_accumulation_steps 16 \
11
+ --eval_steps 100 \
12
+ --save_steps 100 \
13
+ --save_total_limit 2 \
14
+ --logging_steps 5 \
15
+ --model_author swift \
16
+ --model_name swift-robot
examples/train/tuners/adapter/train.sh ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 17GiB
2
+ CUDA_VISIBLE_DEVICES=0 \
3
+ swift sft \
4
+ --model Qwen/Qwen2.5-7B-Instruct \
5
+ --train_type adapter \
6
+ --dataset 'swift/self-cognition#1000' \
7
+ --num_train_epochs 1 \
8
+ --per_device_train_batch_size 1 \
9
+ --learning_rate 1e-4 \
10
+ --gradient_accumulation_steps 16 \
11
+ --eval_steps 100 \
12
+ --save_steps 100 \
13
+ --save_total_limit 2 \
14
+ --logging_steps 5 \
15
+ --model_author swift \
16
+ --model_name swift-robot
examples/train/tuners/boft/train.sh ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 17GiB
2
+ CUDA_VISIBLE_DEVICES=0 \
3
+ swift sft \
4
+ --model Qwen/Qwen2.5-7B-Instruct \
5
+ --train_type boft \
6
+ --dataset 'swift/self-cognition#1000' \
7
+ --num_train_epochs 1 \
8
+ --per_device_train_batch_size 1 \
9
+ --learning_rate 1e-4 \
10
+ --gradient_accumulation_steps 16 \
11
+ --eval_steps 100 \
12
+ --save_steps 100 \
13
+ --save_total_limit 2 \
14
+ --logging_steps 5 \
15
+ --model_author swift \
16
+ --model_name swift-robot
examples/train/tuners/bone/train.sh ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 17.3GiB
2
+ CUDA_VISIBLE_DEVICES=0 \
3
+ swift sft \
4
+ --model Qwen/Qwen2.5-7B-Instruct \
5
+ --train_type bone \
6
+ --dataset 'swift/self-cognition#1000' \
7
+ --num_train_epochs 1 \
8
+ --per_device_train_batch_size 1 \
9
+ --learning_rate 1e-4 \
10
+ --gradient_accumulation_steps 16 \
11
+ --eval_steps 100 \
12
+ --save_steps 100 \
13
+ --save_total_limit 2 \
14
+ --logging_steps 5 \
15
+ --model_author swift \
16
+ --model_name swift-robot
examples/train/tuners/dora/train.sh ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 17.2GiB
2
+ CUDA_VISIBLE_DEVICES=0 \
3
+ swift sft \
4
+ --model Qwen/Qwen2.5-7B-Instruct \
5
+ --train_type lora \
6
+ --use_dora true \
7
+ --dataset 'swift/self-cognition#1000' \
8
+ --num_train_epochs 1 \
9
+ --per_device_train_batch_size 1 \
10
+ --learning_rate 1e-4 \
11
+ --lora_rank 8 \
12
+ --lora_alpha 32 \
13
+ --gradient_accumulation_steps 16 \
14
+ --eval_steps 100 \
15
+ --save_steps 100 \
16
+ --save_total_limit 2 \
17
+ --logging_steps 5 \
18
+ --model_author swift \
19
+ --model_name swift-robot
examples/train/tuners/galore/train_galore.sh ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 38GiB
2
+ CUDA_VISIBLE_DEVICES=0 \
3
+ swift sft \
4
+ --model Qwen/Qwen2.5-7B-Instruct \
5
+ --train_type full \
6
+ --dataset 'swift/self-cognition#1000' \
7
+ --num_train_epochs 1 \
8
+ --per_device_train_batch_size 1 \
9
+ --learning_rate 1e-5 \
10
+ --gradient_accumulation_steps 16 \
11
+ --eval_steps 100 \
12
+ --save_steps 100 \
13
+ --save_total_limit 2 \
14
+ --logging_steps 5 \
15
+ --model_author swift \
16
+ --model_name swift-robot \
17
+ --use_galore true \
18
+ --galore_optim_per_parameter true
examples/train/tuners/galore/train_qgalore.sh ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 35GiB
2
+ # pip install bitsandbytes==0.40.0
3
+ CUDA_VISIBLE_DEVICES=0 \
4
+ swift sft \
5
+ --model Qwen/Qwen2.5-7B-Instruct \
6
+ --train_type full \
7
+ --torch_dtype bfloat16 \
8
+ --dataset 'lvjianjin/AdvertiseGen#1000' \
9
+ --load_from_cache_file true \
10
+ --split_dataset_ratio 0.01 \
11
+ --num_train_epochs 1 \
12
+ --per_device_train_batch_size 1 \
13
+ --learning_rate 1e-5 \
14
+ --gradient_accumulation_steps 16 \
15
+ --eval_steps 100 \
16
+ --save_steps 100 \
17
+ --save_total_limit 2 \
18
+ --logging_steps 5 \
19
+ --model_author swift \
20
+ --model_name swift-robot \
21
+ --use_galore true \
22
+ --galore_quantization true
examples/train/tuners/lisa/train.sh ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 29GiB
2
+ CUDA_VISIBLE_DEVICES=0 \
3
+ swift sft \
4
+ --model Qwen/Qwen2.5-7B-Instruct \
5
+ --train_type full \
6
+ --dataset 'swift/self-cognition#1000' \
7
+ --lisa_activated_layers 2 \
8
+ --num_train_epochs 1 \
9
+ --per_device_train_batch_size 1 \
10
+ --learning_rate 1e-5 \
11
+ --gradient_accumulation_steps 16 \
12
+ --eval_steps 100 \
13
+ --save_steps 100 \
14
+ --save_total_limit 2 \
15
+ --logging_steps 5 \
16
+ --model_author swift \
17
+ --model_name swift-robot
examples/train/tuners/llamapro/train.sh ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 25.4GiB
2
+ CUDA_VISIBLE_DEVICES=0 \
3
+ swift sft \
4
+ --model Qwen/Qwen2.5-7B-Instruct \
5
+ --train_type llamapro \
6
+ --dataset 'swift/self-cognition#1000' \
7
+ --llamapro_num_new_blocks 4 \
8
+ --num_train_epochs 1 \
9
+ --per_device_train_batch_size 1 \
10
+ --learning_rate 1e-4 \
11
+ --gradient_accumulation_steps 16 \
12
+ --eval_steps 100 \
13
+ --save_steps 100 \
14
+ --save_total_limit 2 \
15
+ --logging_steps 5 \
16
+ --model_author swift \
17
+ --model_name swift-robot
examples/train/tuners/longlora/train.sh ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ CUDA_VISIBLE_DEVICES=0 \
2
+ swift sft \
3
+ --model LLM-Research/Meta-Llama-3.1-8B-Instruct \
4
+ --train_type longlora \
5
+ --dataset 'AI-ModelScope/LongAlpaca-12k#1000' \
6
+ --load_from_cache_file true \
7
+ --split_dataset_ratio 0.01 \
8
+ --num_train_epochs 1 \
9
+ --learning_rate 1e-4 \
10
+ --attn_impl flash_attn \
11
+ --gradient_accumulation_steps 16 \
12
+ --lora_rank 8 \
13
+ --lora_alpha 32 \
14
+ --eval_steps 100 \
15
+ --save_steps 100 \
16
+ --max_length 10000 \
17
+ --save_total_limit 2 \
18
+ --logging_steps 5
examples/train/tuners/lora-ga/train.sh ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Train
2
+ CUDA_VISIBLE_DEVICES=0 \
3
+ swift sft \
4
+ --model Qwen/Qwen2-1.5B-Instruct \
5
+ --train_type lora \
6
+ --dataset 'swift/self-cognition#1000' \
7
+ --num_train_epochs 1 \
8
+ --per_device_train_batch_size 1 \
9
+ --learning_rate 1e-4 \
10
+ --lora_rank 8 \
11
+ --lora_alpha 32 \
12
+ --init_weights lora-ga \
13
+ --lora_ga_batch_size 2 \
14
+ --lora_ga_iters 2 \
15
+ --lora_ga_max_length 1024 \
16
+ --lora_ga_direction ArB2r \
17
+ --lora_ga_scale stable \
18
+ --lora_ga_stable_gamma 16 \
19
+ --gradient_accumulation_steps 16 \
20
+ --eval_steps 100 \
21
+ --save_steps 100 \
22
+ --save_total_limit 2 \
23
+ --logging_steps 5 \
24
+ --model_author swift \
25
+ --model_name swift-robot
26
+
27
+ # Infer
28
+ # swift infer \
29
+ # --model Qwen/Qwen2-1.5B-Instruct \
30
+ # --ckpt_dir ./output/Qwen2-1.5B-Instruct/v0-20241214-191235/checkpoint-62/converted/default \
31
+ # --infer_backend pt \
32
+ # --stream true \
33
+ # --max_new_tokens 2048
examples/train/tuners/lora/train.sh ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 17.2GiB
2
+ CUDA_VISIBLE_DEVICES=0 \
3
+ swift sft \
4
+ --model Qwen/Qwen2.5-7B-Instruct \
5
+ --train_type lora \
6
+ --dataset 'swift/self-cognition#1000' \
7
+ --num_train_epochs 1 \
8
+ --per_device_train_batch_size 1 \
9
+ --learning_rate 1e-4 \
10
+ --lora_rank 8 \
11
+ --lora_alpha 32 \
12
+ --gradient_accumulation_steps 16 \
13
+ --eval_steps 100 \
14
+ --save_steps 100 \
15
+ --save_total_limit 2 \
16
+ --logging_steps 5 \
17
+ --model_author swift \
18
+ --model_name swift-robot