From e155cb8a6643c6e48eae87190ade39d20cae5a25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Quentin=20Gallou=C3=A9dec?= <45557362+qgallouedec@users.noreply.github.com> Date: Mon, 28 Oct 2024 11:40:51 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9B=93=EF=B8=8F=E2=80=8D=F0=9F=92=A5=20Don't?= =?UTF-8?q?=20use=20`eval=5Fdataset`=20in=20scripts=20when=20no=20eval=20s?= =?UTF-8?q?trategy=20(#2270)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/scripts/bco.py | 2 +- examples/scripts/cpo.py | 2 +- examples/scripts/dpo.py | 2 +- examples/scripts/dpo_online.py | 2 +- examples/scripts/dpo_vlm.py | 2 +- examples/scripts/gkd.py | 2 +- examples/scripts/kto.py | 2 +- examples/scripts/nash_md.py | 2 +- examples/scripts/orpo.py | 2 +- examples/scripts/ppo/ppo_tldr.py | 8 +++++--- examples/scripts/reward_modeling.py | 2 +- examples/scripts/rloo/rloo_tldr.py | 2 +- examples/scripts/sft.py | 2 +- examples/scripts/sft_vlm.py | 2 +- examples/scripts/xpo.py | 2 +- 15 files changed, 19 insertions(+), 17 deletions(-) diff --git a/examples/scripts/bco.py b/examples/scripts/bco.py index ac46766c2d..d37a1fb3a9 100644 --- a/examples/scripts/bco.py +++ b/examples/scripts/bco.py @@ -151,7 +151,7 @@ def mean_pooling(model_output, attention_mask): ref_model, args=training_args, train_dataset=dataset[script_args.dataset_train_split], - eval_dataset=dataset[script_args.dataset_test_split], + eval_dataset=dataset[script_args.dataset_test_split] if training_args.eval_strategy != "no" else None, processing_class=tokenizer, peft_config=get_peft_config(model_args), embedding_func=embedding_func, diff --git a/examples/scripts/cpo.py b/examples/scripts/cpo.py index 34e897c557..019e9ef714 100644 --- a/examples/scripts/cpo.py +++ b/examples/scripts/cpo.py @@ -91,7 +91,7 @@ model, args=training_args, train_dataset=dataset[script_args.dataset_train_split], - eval_dataset=dataset[script_args.dataset_test_split], + eval_dataset=dataset[script_args.dataset_test_split] if training_args.eval_strategy != "no" else None, processing_class=tokenizer, peft_config=get_peft_config(model_config), ) diff --git a/examples/scripts/dpo.py b/examples/scripts/dpo.py index 302e42c59c..7c1114eedd 100644 --- a/examples/scripts/dpo.py +++ b/examples/scripts/dpo.py @@ -120,7 +120,7 @@ ref_model, args=training_args, train_dataset=dataset[script_args.dataset_train_split], - eval_dataset=dataset[script_args.dataset_test_split], + eval_dataset=dataset[script_args.dataset_test_split] if training_args.eval_strategy != "no" else None, processing_class=tokenizer, peft_config=peft_config, ) diff --git a/examples/scripts/dpo_online.py b/examples/scripts/dpo_online.py index 5c2c47d56c..33dea12ff2 100644 --- a/examples/scripts/dpo_online.py +++ b/examples/scripts/dpo_online.py @@ -121,7 +121,7 @@ judge=judge, args=training_args, train_dataset=dataset[script_args.dataset_train_split], - eval_dataset=dataset[script_args.dataset_test_split], + eval_dataset=dataset[script_args.dataset_test_split] if training_args.eval_strategy != "no" else None, processing_class=tokenizer, peft_config=get_peft_config(model_config), ) diff --git a/examples/scripts/dpo_vlm.py b/examples/scripts/dpo_vlm.py index 08f5687afe..0781edd9e3 100644 --- a/examples/scripts/dpo_vlm.py +++ b/examples/scripts/dpo_vlm.py @@ -113,7 +113,7 @@ ref_model, args=training_args, train_dataset=dataset[script_args.dataset_train_split], - eval_dataset=dataset[script_args.dataset_test_split], + eval_dataset=dataset[script_args.dataset_test_split] if training_args.eval_strategy != "no" else None, processing_class=processor, peft_config=peft_config, ) diff --git a/examples/scripts/gkd.py b/examples/scripts/gkd.py index 7c37d811c5..1ceaf5b085 100644 --- a/examples/scripts/gkd.py +++ b/examples/scripts/gkd.py @@ -121,7 +121,7 @@ teacher_model=training_args.teacher_model_name_or_path, args=training_args, train_dataset=dataset[script_args.dataset_train_split], - eval_dataset=dataset[script_args.dataset_test_split], + eval_dataset=dataset[script_args.dataset_test_split] if training_args.eval_strategy != "no" else None, processing_class=tokenizer, peft_config=get_peft_config(model_config), ) diff --git a/examples/scripts/kto.py b/examples/scripts/kto.py index 50dbcd5f36..56205ce57e 100644 --- a/examples/scripts/kto.py +++ b/examples/scripts/kto.py @@ -99,7 +99,7 @@ ref_model, args=training_args, train_dataset=dataset[script_args.dataset_train_split], - eval_dataset=dataset[script_args.dataset_test_split], + eval_dataset=dataset[script_args.dataset_test_split] if training_args.eval_strategy != "no" else None, processing_class=tokenizer, peft_config=get_peft_config(model_args), ) diff --git a/examples/scripts/nash_md.py b/examples/scripts/nash_md.py index ec731d0384..c492faf76f 100644 --- a/examples/scripts/nash_md.py +++ b/examples/scripts/nash_md.py @@ -129,7 +129,7 @@ judge=judge, args=training_args, train_dataset=dataset[script_args.dataset_train_split], - eval_dataset=dataset[script_args.dataset_test_split], + eval_dataset=dataset[script_args.dataset_test_split] if training_args.eval_strategy != "no" else None, processing_class=tokenizer, ) generation_config = GenerationConfig( diff --git a/examples/scripts/orpo.py b/examples/scripts/orpo.py index 163655e1e3..ac3f598f88 100644 --- a/examples/scripts/orpo.py +++ b/examples/scripts/orpo.py @@ -91,7 +91,7 @@ model, args=training_args, train_dataset=dataset[script_args.dataset_train_split], - eval_dataset=dataset[script_args.dataset_test_split], + eval_dataset=dataset[script_args.dataset_test_split] if training_args.eval_strategy != "no" else None, processing_class=tokenizer, peft_config=get_peft_config(model_config), ) diff --git a/examples/scripts/ppo/ppo_tldr.py b/examples/scripts/ppo/ppo_tldr.py index 45f813f765..fd20d6693d 100644 --- a/examples/scripts/ppo/ppo_tldr.py +++ b/examples/scripts/ppo/ppo_tldr.py @@ -95,7 +95,7 @@ ################ dataset = load_dataset(script_args.dataset_name) train_dataset = dataset[script_args.dataset_train_split] - eval_dataset = dataset[script_args.dataset_test_split] + eval_dataset = dataset[script_args.dataset_test_split] if training_args.eval_strategy != "no" else None def prepare_dataset(dataset, tokenizer): """pre-tokenize the dataset before training; only collate during training""" @@ -118,10 +118,12 @@ def tokenize(element): # see: https://github.com/huggingface/trl/pull/1255 with PartialState().local_main_process_first(): train_dataset = prepare_dataset(train_dataset, tokenizer) - eval_dataset = prepare_dataset(eval_dataset, tokenizer) + if eval_dataset is not None: + eval_dataset = prepare_dataset(eval_dataset, tokenizer) # filtering train_dataset = train_dataset.filter(lambda x: x["lengths"] <= 512, num_proc=training_args.dataset_num_proc) - eval_dataset = eval_dataset.filter(lambda x: x["lengths"] <= 512, num_proc=training_args.dataset_num_proc) + if eval_dataset is not None: + eval_dataset = eval_dataset.filter(lambda x: x["lengths"] <= 512, num_proc=training_args.dataset_num_proc) assert train_dataset[0]["input_ids"][-1] != tokenizer.eos_token_id, "The last token should not be an EOS token" ################ diff --git a/examples/scripts/reward_modeling.py b/examples/scripts/reward_modeling.py index 57027bc10c..40924a3ad3 100644 --- a/examples/scripts/reward_modeling.py +++ b/examples/scripts/reward_modeling.py @@ -115,7 +115,7 @@ processing_class=tokenizer, args=training_args, train_dataset=dataset[script_args.dataset_train_split], - eval_dataset=dataset[script_args.dataset_test_split], + eval_dataset=dataset[script_args.dataset_test_split] if training_args.eval_strategy != "no" else None, peft_config=get_peft_config(model_config), ) trainer.train() diff --git a/examples/scripts/rloo/rloo_tldr.py b/examples/scripts/rloo/rloo_tldr.py index 2e8312272c..36f759208a 100644 --- a/examples/scripts/rloo/rloo_tldr.py +++ b/examples/scripts/rloo/rloo_tldr.py @@ -94,7 +94,7 @@ ################ dataset = load_dataset(script_args.dataset_name) train_dataset = dataset[script_args.dataset_train_split] - eval_dataset = dataset[script_args.dataset_test_split] + eval_dataset = dataset[script_args.dataset_test_split] if training_args.eval_strategy != "no" else None def prepare_dataset(dataset, tokenizer): """pre-tokenize the dataset before training; only collate during training""" diff --git a/examples/scripts/sft.py b/examples/scripts/sft.py index b6c789b3d2..422fa89a6f 100644 --- a/examples/scripts/sft.py +++ b/examples/scripts/sft.py @@ -98,7 +98,7 @@ model=model_config.model_name_or_path, args=training_args, train_dataset=dataset[script_args.dataset_train_split], - eval_dataset=dataset[script_args.dataset_test_split], + eval_dataset=dataset[script_args.dataset_test_split] if training_args.eval_strategy != "no" else None, processing_class=tokenizer, peft_config=get_peft_config(model_config), ) diff --git a/examples/scripts/sft_vlm.py b/examples/scripts/sft_vlm.py index 361bcc0e50..49654bc408 100644 --- a/examples/scripts/sft_vlm.py +++ b/examples/scripts/sft_vlm.py @@ -118,7 +118,7 @@ def collate_fn(examples): args=training_args, data_collator=collate_fn, train_dataset=dataset[script_args.dataset_train_split], - eval_dataset=dataset[script_args.dataset_test_split], + eval_dataset=dataset[script_args.dataset_test_split] if training_args.eval_strategy != "no" else None, processing_class=processor.tokenizer, peft_config=get_peft_config(model_config), ) diff --git a/examples/scripts/xpo.py b/examples/scripts/xpo.py index 5f32c161b4..8a07e96b3d 100644 --- a/examples/scripts/xpo.py +++ b/examples/scripts/xpo.py @@ -114,7 +114,7 @@ judge=judge, args=training_args, train_dataset=dataset[script_args.dataset_train_split], - eval_dataset=dataset[script_args.dataset_test_split], + eval_dataset=dataset[script_args.dataset_test_split] if training_args.eval_strategy != "no" else None, processing_class=tokenizer, ) generation_config = GenerationConfig(