-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Data loader refactor #2707
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
Merged
Merged
Data loader refactor #2707
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
0cbafb8
data loading refactor (wip)
djsaunde cf4f561
updates
djsaunde f81e023
progress
djsaunde cfa7c3f
pytest
djsaunde 2ec912a
pytest fix
djsaunde 718b519
lint
djsaunde b744d02
zero_first -> filelock, more simplifications
djsaunde ac920a5
small simplification
djsaunde 42c6b8c
import change
djsaunde 234cae4
nit
djsaunde ec4783d
lint
djsaunde 69f83a5
simplify dedup
djsaunde 250126e
couldnt resist
djsaunde 8b4e7d0
review comments WIP
djsaunde cf4fa7f
continued wip
djsaunde e697ca3
minor changes
djsaunde fd5ed2b
fix; remove contrived test
djsaunde 06c6baf
further refactor
djsaunde f96e641
set default seed in pydantic config
djsaunde 3d7d9d2
lint
djsaunde 0f4243f
continued simplication
djsaunde 29a8e27
lint
djsaunde 8598ca3
renaming and nits
djsaunde e74fc59
filelock tests
djsaunde 403551c
fix
djsaunde bbcc108
fix
djsaunde b7e01ab
lint
djsaunde eeaa5ee
remove nullable arg
djsaunde c1b7eb1
remove unnecessary code
djsaunde 8505f17
moving dataset save fn to shared module
djsaunde aa34452
remove debug print
djsaunde 148490a
matching var naming
djsaunde 669579a
fn name change
djsaunde d523857
coderabbit comments
djsaunde aa0c3ef
naming nit
djsaunde 9b1b33d
fix test
djsaunde File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
""" | ||
Various shared constants | ||
""" | ||
"""Various shared constants""" | ||
|
||
DEFAULT_DATASET_PREPARED_PATH = "last_run_prepared" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
"""Module containing Dataset functionality""" | ||
|
||
import os | ||
from typing import List, Optional, Union | ||
|
||
import torch | ||
from datasets import Dataset, IterableDataset | ||
|
@@ -20,21 +19,21 @@ | |
|
||
|
||
class TokenizedPromptDataset(Dataset): | ||
""" | ||
djsaunde marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Dataset that returns tokenized prompts from a stream of text files. | ||
Args: | ||
prompt_tokenizer (PromptTokenizingStrategy): The prompt tokenizing method for processing the data. | ||
dataset (dataset.Dataset): Dataset with text files. | ||
process_count (int): Number of processes to use for tokenizing. | ||
keep_in_memory (bool): Whether to keep the tokenized dataset in memory. | ||
"""Dataset that returns tokenized prompts from a stream of text files. | ||
|
||
Args: | ||
prompt_tokenizer: The prompt tokenizing method for processing the data. | ||
dataset: Dataset with text files. | ||
process_count: Number of processes to use for tokenizing. | ||
keep_in_memory: Whether to keep the tokenized dataset in memory. | ||
""" | ||
|
||
def __init__( # pylint: disable=super-init-not-called | ||
self, | ||
prompt_tokenizer: PromptTokenizingStrategy, | ||
dataset: Dataset, | ||
process_count: Optional[int] = None, | ||
keep_in_memory: Optional[bool] = False, | ||
process_count: int | None = None, | ||
keep_in_memory: bool | None = False, | ||
**kwargs, | ||
): | ||
self.prompt_tokenizer = prompt_tokenizer | ||
|
@@ -76,14 +75,14 @@ def process(self, dataset): | |
|
||
def wrap_dataset_for_tokenized_prompt( | ||
prompt_tokenizer: PromptTokenizingStrategy, | ||
dataset: Union[Dataset, IterableDataset], | ||
dataset: Dataset | IterableDataset, | ||
**kwargs, | ||
): | ||
if isinstance(dataset, IterableDataset): | ||
map_kwargs = {} | ||
if prompt_tokenizer.supports_batched: | ||
map_kwargs["batched"] = True | ||
features = dataset.features.keys() | ||
features = list(dataset.features.keys()) | ||
return dataset.map( | ||
prompt_tokenizer.tokenize_prompt, | ||
remove_columns=features, | ||
|
@@ -94,12 +93,13 @@ def wrap_dataset_for_tokenized_prompt( | |
|
||
# TODO this isn't the best since it can't interleave datasets | ||
class ConstantLengthDataset(IterableDataset): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know that we actually use this anywhere and is a good candidate for pruning |
||
""" | ||
Iterable dataset that returns constant length chunks of tokens from stream of text files. | ||
Args: | ||
tokenizer (Tokenizer): The processor used for processing the data. | ||
dataset (dataset.Dataset): Dataset with text files. | ||
seq_length (int): Length of token sequences to return. | ||
"""Iterable dataset that returns constant length chunks of tokens from stream of | ||
text files. | ||
|
||
Args: | ||
tokenizer: The processor used for processing the data. | ||
dataset: Dataset with text files. | ||
seq_length: Length of token sequences to return. | ||
""" | ||
|
||
def __init__( # pylint: disable=super-init-not-called | ||
|
@@ -110,7 +110,7 @@ def __init__( # pylint: disable=super-init-not-called | |
): | ||
self.tokenizer = tokenizer | ||
self.concat_token_id = tokenizer.eos_token_id | ||
self.datasets: List[IterableDataset] = datasets | ||
self.datasets: list[IterableDataset] = datasets | ||
self.seq_length = seq_length | ||
|
||
vocab_size = len(tokenizer.get_vocab()) | ||
|
@@ -174,7 +174,10 @@ def __iter__(self): | |
} | ||
else: | ||
LOG.warning( | ||
f"dropping batch due to tensor size mismatch input_ids: {input_ids.size()}, labels: {labels.size()}, attention_mask: {attention_mask.size()}" | ||
"Dropping batch due to tensor size mismatch " | ||
f"input_ids: {input_ids.size()}, " | ||
f"labels: {labels.size()}, " | ||
f"attention_mask: {attention_mask.size()}" | ||
) | ||
buffer = { | ||
"input_ids": [], | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,21 @@ | ||
""" | ||
Data processing modules | ||
""" | ||
"""Init for `axolotl.utils.data` module.""" | ||
|
||
from axolotl.utils.data.pretraining import ( # noqa: F401 | ||
from axolotl.utils.data.pretraining import ( | ||
encode_pretraining, | ||
wrap_pretraining_dataset, | ||
) | ||
from axolotl.utils.data.rl import load_prepare_preference_datasets # noqa: F401 | ||
from axolotl.utils.data.sft import ( # noqa: F401 | ||
from axolotl.utils.data.rl import prepare_preference_datasets | ||
from axolotl.utils.data.sft import ( | ||
get_dataset_wrapper, | ||
load_prepare_datasets, | ||
load_tokenized_prepared_datasets, | ||
prepare_dataset, | ||
prepare_datasets, | ||
) | ||
from axolotl.utils.data.utils import md5 # noqa: F401 | ||
from axolotl.utils.data.utils import md5 | ||
|
||
__all__ = [ | ||
"encode_pretraining", | ||
"wrap_pretraining_dataset", | ||
"prepare_preference_datasets", | ||
"get_dataset_wrapper", | ||
"prepare_datasets", | ||
"md5", | ||
] |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.