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

Simple change to enable mapping functions for ft constructor #1468

Merged
merged 2 commits into from
Aug 20, 2024
Merged
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
7 changes: 5 additions & 2 deletions llmfoundry/data/finetuning/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,7 @@ def build_from_hf(
split: str,
safe_load: bool = False,
max_seq_len: int = 2048,
mapping_fn: Callable = tokenize_formatted_example,
preprocessing_fn: Optional[Callable[[dict[str, Any]], Example]] = None,
tokenizer: Optional[PreTrainedTokenizerBase] = None,
target_prompts: str = DEFAULT_TARGET_PROMPTS,
Expand All @@ -824,6 +825,8 @@ def build_from_hf(
max_seq_len (int): The maximum length of sequences
in the batch. See :class:`Seq2SeqFinetuningCollator` docstring
for details.
mapping_fn (Callable): The mapping function to use for mapping the data
examples.
preprocessing_fn (Callable, optional): The preprocessing function to use for
formatting the data examples.
tokenizer (PreTrainedTokenizerBase): The tokenizer to be used for tokenizing
Expand Down Expand Up @@ -930,11 +933,11 @@ def build_from_hf(

def dataset_mapper(example: dict):
if preprocessing_fn is not None:
return tokenize_formatted_example(
return mapping_fn(
preprocessing_fn(example),
tokenizer,
)
return tokenize_formatted_example(example, tokenizer)
return mapping_fn(example, tokenizer)

detected_cpu_count = os.cpu_count() or 1
detected_cpus_with_margin = detected_cpu_count - 8
Expand Down
Loading