Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Update] loader.py , evaluate will run separate evaluations on each eval_dataset #5522

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 32 additions & 13 deletions src/llamafactory/data/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,21 +143,21 @@ def _get_merged_dataset(
data_args: "DataArguments",
training_args: "Seq2SeqTrainingArguments",
stage: Literal["pt", "sft", "rm", "ppo", "kto"],
merge: bool = True
) -> Optional[Union["Dataset", "IterableDataset"]]:
r"""
Gets the merged datasets in the standard format.
"""
if dataset_names is None:
return None

datasets = []
datasets = {}
for dataset_attr in get_dataset_list(dataset_names, data_args.dataset_dir):
if (stage == "rm" and dataset_attr.ranking is False) or (stage != "rm" and dataset_attr.ranking is True):
raise ValueError("The dataset is not applicable in the current training stage.")

datasets.append(_load_single_dataset(dataset_attr, model_args, data_args, training_args))

return merge_dataset(datasets, data_args, seed=training_args.seed)
datasets[f'{dataset_attr.dataset_name}_{dataset_attr.subset}'] = _load_single_dataset(dataset_attr, model_args, data_args, training_args)
if merge:
return merge_dataset([data for _, data in datasets.items()], data_args, seed=training_args.seed)
else:
return datasets
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does dict match the return value type Optional[Union["Dataset", "IterableDataset"]]?



def _get_preprocessed_dataset(
Expand Down Expand Up @@ -246,15 +246,21 @@ def get_dataset(
# Load and preprocess dataset
with training_args.main_process_first(desc="load dataset"):
dataset = _get_merged_dataset(data_args.dataset, model_args, data_args, training_args, stage)
eval_dataset = _get_merged_dataset(data_args.eval_dataset, model_args, data_args, training_args, stage)
eval_dataset = _get_merged_dataset(data_args.eval_dataset, model_args, data_args, training_args, stage, merge=data_args.streaming)

with training_args.main_process_first(desc="pre-process dataset"):
dataset = _get_preprocessed_dataset(
dataset, data_args, training_args, stage, template, tokenizer, processor, is_eval=False
)
eval_dataset = _get_preprocessed_dataset(
eval_dataset, data_args, training_args, stage, template, tokenizer, processor, is_eval=True
)
if isinstance(eval_dataset, dict):
for eval_name, eval_data in eval_dataset.items():
eval_dataset[eval_name] = _get_preprocessed_dataset(
eval_data, data_args, training_args, stage, template, tokenizer, processor, is_eval=True
)
else:
eval_dataset = _get_preprocessed_dataset(
eval_dataset, data_args, training_args, stage, template, tokenizer, processor, is_eval=True
)

if data_args.val_size > 1e-6:
dataset_dict = split_dataset(dataset, data_args, seed=training_args.seed)
Expand All @@ -269,7 +275,13 @@ def get_dataset(
if eval_dataset is not None:
if data_args.streaming:
eval_dataset = eval_dataset.shuffle(buffer_size=data_args.buffer_size, seed=training_args.seed)

dataset_dict["validation"] = eval_dataset
else:
if isinstance(eval_dataset, dict):
for eval_name, eval_data in eval_dataset.items():
dataset_dict[f"validation_{eval_name}"] = eval_data
else:
dataset_dict["validation"] = eval_dataset
dataset_dict["validation"] = eval_dataset

dataset_dict = DatasetDict(dataset_dict)
Expand All @@ -285,8 +297,15 @@ def get_dataset(
dataset_module = {}
if "train" in dataset_dict:
dataset_module["train_dataset"] = dataset_dict["train"]

if "validation" in dataset_dict:
dataset_module["eval_dataset"] = dataset_dict["validation"]

eval_datasets_map = {}
for key, value in dataset_dict.items():
if 'validation_' in key:
eval_datasets_map[key] = dataset_dict[key]
if len(eval_datasets_map):
dataset_module["eval_dataset"] = eval_datasets_map

return dataset_module