Skip to content

Commit 29ca8f5

Browse files
committed
Merge commit 'a60c2c8f9eb21b2dd108a2a5bdfc88fd2ad8babb' into release/1.5
* commit 'a60c2c8f9eb21b2dd108a2a5bdfc88fd2ad8babb': fix_ziya_template_bug (#303) fix a bug may cause module on gpu throws error (#302) fix text label (#301) Support studio (#300) fix chatglm3 template bug (#298)
2 parents d9756cd + a60c2c8 commit 29ca8f5

File tree

20 files changed

+261
-39
lines changed

20 files changed

+261
-39
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Experimental environment: A100
2+
PYTHONPATH=../../.. \
3+
CUDA_VISIBLE_DEVICES=0 \
4+
python llm_infer.py \
5+
--ckpt_dir "output/llama2-13b-chat/vx_xxx/checkpoint-xxx" \
6+
--load_dataset_config true \
7+
--max_length 4096 \
8+
--max_new_tokens 2048 \
9+
--temperature 0.1 \
10+
--top_p 0.7 \
11+
--repetition_penalty 1.05 \
12+
--do_sample true \
13+
--merge_lora_and_save false \
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Experimental environment: 2 * A100
2+
# 2 * 37GB GPU memory
3+
nproc_per_node=2
4+
5+
PYTHONPATH=../../.. \
6+
CUDA_VISIBLE_DEVICES=0,1 \
7+
torchrun \
8+
--nproc_per_node=$nproc_per_node \
9+
--master_port 29500 \
10+
llm_sft.py \
11+
--model_id_or_path modelscope/Llama-2-13b-chat-ms \
12+
--model_revision master \
13+
--sft_type longlora \
14+
--tuner_backend swift \
15+
--template_type llama \
16+
--dtype AUTO \
17+
--output_dir output \
18+
--ddp_backend nccl \
19+
--dataset leetcode-python-en \
20+
--train_dataset_sample -1 \
21+
--num_train_epochs 1 \
22+
--max_length 4096 \
23+
--check_dataset_strategy warning \
24+
--lora_rank 8 \
25+
--lora_alpha 32 \
26+
--lora_dropout_p 0.05 \
27+
--lora_target_modules ALL \
28+
--gradient_checkpointing true \
29+
--batch_size 1 \
30+
--weight_decay 0.01 \
31+
--learning_rate 1e-4 \
32+
--gradient_accumulation_steps $(expr 16 / $nproc_per_node) \
33+
--max_grad_norm 0.5 \
34+
--warmup_ratio 0.03 \
35+
--eval_steps 100 \
36+
--save_steps 100 \
37+
--save_total_limit 2 \
38+
--logging_steps 10 \
39+
--push_to_hub false \
40+
--hub_model_id llama2-13b-chat-longlora \
41+
--hub_private_repo true \
42+
--hub_token 'your-sdk-token' \
43+
--deepspeed_config_path 'ds_config/zero2.json' \
44+
--save_only_model true \
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Experimental environment: V100, A10, 3090
2+
PYTHONPATH=../../.. \
3+
CUDA_VISIBLE_DEVICES=0 \
4+
python llm_infer.py \
5+
--ckpt_dir "output/qwen-7b-chat-int4/vx_xxx/checkpoint-xxx" \
6+
--load_dataset_config true \
7+
--max_length 4096 \
8+
--use_flash_attn false \
9+
--max_new_tokens 2048 \
10+
--temperature 0.1 \
11+
--top_p 0.7 \
12+
--repetition_penalty 1.05 \
13+
--do_sample true \
14+
--merge_lora_and_save false \
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Experimental environment: V100, A10, 3090
2+
# 14GB GPU memory
3+
PYTHONPATH=../../.. \
4+
CUDA_VISIBLE_DEVICES=0 \
5+
python llm_sft.py \
6+
--model_id_or_path qwen/Qwen-7B-Chat-Int4 \
7+
--model_revision master \
8+
--sft_type qalora \
9+
--tuner_backend swift \
10+
--template_type qwen \
11+
--dtype fp16 \
12+
--output_dir output \
13+
--dataset leetcode-python-en \
14+
--train_dataset_sample -1 \
15+
--num_train_epochs 1 \
16+
--max_length 4096 \
17+
--check_dataset_strategy warning \
18+
--lora_rank 8 \
19+
--lora_alpha 32 \
20+
--lora_dropout_p 0.05 \
21+
--lora_target_modules ALL \
22+
--gradient_checkpointing true \
23+
--batch_size 1 \
24+
--weight_decay 0.01 \
25+
--learning_rate 1e-4 \
26+
--gradient_accumulation_steps 16 \
27+
--max_grad_norm 0.5 \
28+
--warmup_ratio 0.03 \
29+
--eval_steps 100 \
30+
--save_steps 100 \
31+
--save_total_limit 2 \
32+
--logging_steps 10 \
33+
--use_flash_attn false \
34+
--push_to_hub false \
35+
--hub_model_id qwen-7b-chat-int4-qalora \
36+
--hub_private_repo true \
37+
--hub_token 'your-sdk-token' \

swift/llm/sft.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,8 @@ def llm_sft(args: SftArguments) -> Dict[str, Union[str, Any]]:
181181
greater_is_better=args.predict_with_generate,
182182
sortish_sampler=True,
183183
optim=args.optim,
184+
adam_beta1=args.adam_beta1,
185+
adam_beta2=args.adam_beta2,
184186
hub_model_id=args.hub_model_id,
185187
hub_private_repo=args.hub_private_repo,
186188
push_hub_strategy=args.push_hub_strategy,
@@ -200,7 +202,8 @@ def llm_sft(args: SftArguments) -> Dict[str, Union[str, Any]]:
200202
disable_tqdm=args.disable_tqdm,
201203
save_on_each_node=args.save_on_each_node,
202204
acc_strategy=args.acc_strategy,
203-
save_safetensors=args.save_safetensors)
205+
save_safetensors=args.save_safetensors,
206+
logging_first_step=True)
204207

205208
if args.gradient_checkpointing:
206209
model.config.use_cache = False # fix transformers==4.36

swift/llm/utils/argument.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ class SftArguments:
104104
# if max_steps >= 0, override num_train_epochs
105105
max_steps: int = -1
106106
optim: str = 'adamw_torch'
107+
adam_beta1: float = 0.9
108+
adam_beta2: float = 0.999
107109
learning_rate: Optional[float] = None
108110
weight_decay: float = 0.01
109111
gradient_accumulation_steps: Optional[int] = None

swift/llm/utils/dataset.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ def _repair_agent_conversations(conversations: str,
409409

410410
advertise_gen_prompt = """Task: Generating advertisements based on keywords.
411411
Keywords: {query}
412-
Advertisements: """
412+
Advertisements:"""
413413
register_dataset(
414414
DatasetName.advertise_gen_zh,
415415
'lvjianjin/AdvertiseGen', ['train'], ['validation'],
@@ -513,7 +513,7 @@ def _preprocess_dureader_robust(dataset: HfDataset) -> HfDataset:
513513
prompt = """Task: Question Generation
514514
Context: {context}
515515
Answer: {answer}
516-
Question: """
516+
Question:"""
517517
query = []
518518
response = []
519519
for d in dataset:
@@ -850,7 +850,7 @@ def _preprocess_hc3(dataset: HfDataset) -> HfDataset:
850850
Question: {question}
851851
Answer: {answer}
852852
Category: Human, ChatGPT
853-
Output: """
853+
Output:"""
854854
query = []
855855
response = []
856856
for d in dataset:
@@ -978,6 +978,9 @@ def add_self_cognition_dataset(
978978
return concatenate_datasets([train_dataset, dataset])
979979

980980

981+
NoneType = type(None)
982+
983+
981984
def _check_dataset(
982985
dataset: Optional[None],
983986
check_dataset_strategy: Literal['none', 'discard', 'error', 'warning']
@@ -1003,7 +1006,7 @@ def _check_dataset(
10031006
continue
10041007
else:
10051008
raise ValueError(f"d['response']: {d['response']}, i: {i}")
1006-
if has_query and not isinstance(d['response'], str):
1009+
if has_query and not isinstance(d['query'], (str, NoneType)):
10071010
is_modified = True
10081011
if check_dataset_strategy == 'discard':
10091012
continue
@@ -1012,7 +1015,7 @@ def _check_dataset(
10121015
continue
10131016
else:
10141017
raise ValueError(f"d['query']: {d['query']}, i: {i}")
1015-
if has_history and not isinstance(d['history'], (list, type(None))):
1018+
if has_history and not isinstance(d['history'], (list, NoneType)):
10161019
is_modified = True
10171020
if check_dataset_strategy == 'discard':
10181021
continue
@@ -1021,7 +1024,7 @@ def _check_dataset(
10211024
continue
10221025
else:
10231026
raise ValueError(f"d['history']: {d['history']}, i: {i}")
1024-
if has_system and not isinstance(d['system'], str):
1027+
if has_system and not isinstance(d['system'], (str, NoneType)):
10251028
is_modified = True
10261029
if check_dataset_strategy == 'discard':
10271030
continue

swift/llm/utils/preprocess.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ def __init__(self, labels: List[str], task_name: str,
232232
self.prompt = f"""Task: {task_name}
233233
{inputs}
234234
Category: {category}
235-
Output: """
235+
Output:"""
236236
self.task_name = task_name
237237
self.is_pair_seq = is_pair_seq
238238

swift/llm/utils/template.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -618,13 +618,13 @@ def register_template(template_type: str,
618618

619619
register_template(
620620
TemplateType.chatglm3,
621-
Template([[64790, 64792]], [[64795], '\n {{QUERY}}', [64796], '\n '], [],
621+
Template([[64790, 64792]], [[64795], '\n {{QUERY}}', [64796], '\n'], [],
622622
[['eos_token_id']], None,
623623
[[64790, 64792, 64794], '\n {{SYSTEM}}']))
624624

625625
register_template(
626626
TemplateType.deepseek,
627-
Template([['bos_token_id']], ['User: {{QUERY}}\n\nAssistant: '],
627+
Template([['bos_token_id']], ['User: {{QUERY}}\n\nAssistant:'],
628628
[['eos_token_id']], [['eos_token_id']], None,
629629
[['bos_token_id'], '{{SYSTEM}}\n\n']))
630630

@@ -660,7 +660,7 @@ def register_template(template_type: str,
660660
)
661661
register_template(
662662
TemplateType.openbuddy,
663-
Template([['bos_token_id']], ['User: {{QUERY}}\nAssistant: '], ['\n'],
663+
Template([['bos_token_id']], ['User: {{QUERY}}\nAssistant:'], ['\n'],
664664
[['eos_token_id']], OPENBUDDY_DEFAULT_SYSTEM,
665665
[['bos_token_id'], '{{SYSTEM}}\n\n']))
666666

@@ -674,7 +674,7 @@ def register_template(template_type: str,
674674
[['eos_token_id']], [['eos_token_id']], ''))
675675
register_template(
676676
TemplateType.ziya,
677-
Template([['bos_token_id', '{{SYSTEM}}']], ['<human>:{{QUERY}}\n<bot>:'],
677+
Template([['bos_token_id'], '{{SYSTEM}}'], ['<human>:{{QUERY}}\n<bot>:'],
678678
['\n'], [['eos_token_id']], ''))
679679

680680
register_template(

swift/tuners/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ def set_active_adapters(self,
461461
adapter_names: Union[List[str], str],
462462
offload=None):
463463
if not adapter_names:
464-
return
464+
adapter_names = []
465465

466466
if isinstance(adapter_names, str):
467467
adapter_names = [adapter_names]

0 commit comments

Comments
 (0)