Skip to content

Commit

Permalink
Simple change to enable mapping functions for ft constructor (#1468)
Browse files Browse the repository at this point in the history
  • Loading branch information
gupta-abhay authored Aug 20, 2024
1 parent bc66a8b commit d3a9ac9
Showing 1 changed file with 5 additions and 2 deletions.
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

0 comments on commit d3a9ac9

Please sign in to comment.