Skip to content

Commit 2e57a3b

Browse files
cyyeverchesterxgchenZiyueXu77
authored
Fix examples for latest SFT (#3613)
### Description Fix example code for latest SFT (for huggingface-trl == v0.21.0). ### Types of changes <!--- Put an `x` in all the boxes that apply, and remove the not applicable items --> - [x] Non-breaking change (fix or new feature that would not break existing functionality). - [ ] Breaking change (fix or new feature that would cause existing functionality to change). - [ ] New tests added to cover the changes. - [ ] Quick tests passed locally by running `./runtest.sh`. - [ ] In-line docstrings updated. - [ ] Documentation updated. Signed-off-by: cyy <[email protected]> Co-authored-by: Chester Chen <[email protected]> Co-authored-by: Ziyue Xu <[email protected]>
1 parent 814a847 commit 2e57a3b

File tree

8 files changed

+12
-44
lines changed

8 files changed

+12
-44
lines changed

examples/advanced/llm_hf/src/hf_sft_peft_fl.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,7 @@ def on_epoch_end(self, args, state, control, logs=None, **kwargs):
4545

4646

4747
def format_instruction(example):
48-
output_texts = []
49-
for i in range(len(example["input"])):
50-
text = f"### Instruction: Generate Output according to the information and question given by Input. ### Input:{example['input'][i]} ### Response: {example['output'][i]}"
51-
output_texts.append(text)
52-
return output_texts
48+
return f"### Instruction: Generate Output according to the information and question given by Input. ### Input:{example['input']} ### Response: {example['output']}"
5349

5450

5551
def setup_distributed_training():
@@ -210,7 +206,7 @@ def main():
210206
lr_scheduler_type=args.lr_scheduler,
211207
lr_scheduler_kwargs={"num_cycles": 2},
212208
disable_tqdm=True,
213-
max_seq_length=1024,
209+
max_length=1024,
214210
save_total_limit=2,
215211
# safetensors will remove shared layers, e.g. lm_head.weight
216212
# disable for local checkpointing

examples/tutorials/self-paced-training/part-4_advanced_federated_learning/chapter-8_federated_LLM_training/08.2_llm_sft/src/hf_sft_peft_fl.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,7 @@
3434

3535

3636
def format_instruction(example):
37-
output_texts = []
38-
for i in range(len(example["input"])):
39-
text = f"### Instruction: Generate Output according to the information and question given by Input. ### Input:{example['input'][i]} ### Response: {example['output'][i]}"
40-
output_texts.append(text)
41-
return output_texts
37+
return f"### Instruction: Generate Output according to the information and question given by Input. ### Input:{example['input']} ### Response: {example['output']}"
4238

4339

4440
def main():
@@ -142,7 +138,7 @@ def main():
142138
warmup_ratio=0.03,
143139
lr_scheduler_type="constant",
144140
disable_tqdm=True,
145-
max_seq_length=1024,
141+
max_length=1024,
146142
save_total_limit=2,
147143
# safetensors has some issues in saving lm_head.weight, disable it for now
148144
save_safetensors=False,

examples/tutorials/self-paced-training/part-4_advanced_federated_learning/chapter-8_federated_LLM_training/08.2_llm_sft/utils/hf_sft_peft.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,7 @@
3030

3131

3232
def format_instruction(example):
33-
output_texts = []
34-
for i in range(len(example["input"])):
35-
text = f"### Instruction: Generate Output according to the information and question given by Input. ### Input:{example['input'][i]} ### Response: {example['output'][i]}"
36-
output_texts.append(text)
37-
return output_texts
33+
return f"### Instruction: Generate Output according to the information and question given by Input. ### Input:{example['input']} ### Response: {example['output']}"
3834

3935

4036
def main():

examples/tutorials/self-paced-training/part-4_advanced_federated_learning/chapter-8_federated_LLM_training/08.2_llm_sft/utils/hf_sft_peft_iter.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,7 @@
3131

3232

3333
def format_instruction(example):
34-
output_texts = []
35-
for i in range(len(example["input"])):
36-
text = f"### Instruction: Generate Output according to the information and question given by Input. ### Input:{example['input'][i]} ### Response: {example['output'][i]}"
37-
output_texts.append(text)
38-
return output_texts
34+
return f"### Instruction: Generate Output according to the information and question given by Input. ### Input:{example['input']} ### Response: {example['output']}"
3935

4036

4137
def main():

examples/tutorials/self-paced-training/part-4_advanced_federated_learning/chapter-8_federated_LLM_training/08.3_llm_peft/src/hf_sft_peft_fl.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,7 @@
3434

3535

3636
def format_instruction(example):
37-
output_texts = []
38-
for i in range(len(example["input"])):
39-
text = f"### Instruction: Generate Output according to the information and question given by Input. ### Input:{example['input'][i]} ### Response: {example['output'][i]}"
40-
output_texts.append(text)
41-
return output_texts
37+
return f"### Instruction: Generate Output according to the information and question given by Input. ### Input:{example['input']} ### Response: {example['output']}"
4238

4339

4440
def main():
@@ -142,7 +138,7 @@ def main():
142138
warmup_ratio=0.03,
143139
lr_scheduler_type="constant",
144140
disable_tqdm=True,
145-
max_seq_length=1024,
141+
max_length=1024,
146142
save_total_limit=2,
147143
# safetensors has some issues in saving lm_head.weight, disable it for now
148144
save_safetensors=False,

examples/tutorials/self-paced-training/part-4_advanced_federated_learning/chapter-8_federated_LLM_training/08.3_llm_peft/utils/hf_sft_peft.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,7 @@
3030

3131

3232
def format_instruction(example):
33-
output_texts = []
34-
for i in range(len(example["input"])):
35-
text = f"### Instruction: Generate Output according to the information and question given by Input. ### Input:{example['input'][i]} ### Response: {example['output'][i]}"
36-
output_texts.append(text)
37-
return output_texts
33+
return f"### Instruction: Generate Output according to the information and question given by Input. ### Input:{example['input']} ### Response: {example['output']}"
3834

3935

4036
def main():

examples/tutorials/self-paced-training/part-4_advanced_federated_learning/chapter-8_federated_LLM_training/08.4_llm_quantization/src/hf_sft_peft_fl.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,7 @@
3434

3535

3636
def format_instruction(example):
37-
output_texts = []
38-
for i in range(len(example["input"])):
39-
text = f"### Instruction: Generate Output according to the information and question given by Input. ### Input:{example['input'][i]} ### Response: {example['output'][i]}"
40-
output_texts.append(text)
41-
return output_texts
37+
return f"### Instruction: Generate Output according to the information and question given by Input. ### Input:{example['input']} ### Response: {example['output']}"
4238

4339

4440
def main():
@@ -142,7 +138,7 @@ def main():
142138
warmup_ratio=0.03,
143139
lr_scheduler_type="constant",
144140
disable_tqdm=True,
145-
max_seq_length=1024,
141+
max_length=1024,
146142
save_total_limit=2,
147143
# safetensors has some issues in saving lm_head.weight, disable it for now
148144
save_safetensors=False,

examples/tutorials/self-paced-training/part-4_advanced_federated_learning/chapter-8_federated_LLM_training/08.4_llm_quantization/utils/hf_sft_peft.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,7 @@
3030

3131

3232
def format_instruction(example):
33-
output_texts = []
34-
for i in range(len(example["input"])):
35-
text = f"### Instruction: Generate Output according to the information and question given by Input. ### Input:{example['input'][i]} ### Response: {example['output'][i]}"
36-
output_texts.append(text)
37-
return output_texts
33+
return f"### Instruction: Generate Output according to the information and question given by Input. ### Input:{example['input']} ### Response: {example['output']}"
3834

3935

4036
def main():

0 commit comments

Comments
 (0)