-
Notifications
You must be signed in to change notification settings - Fork 107
Fix 'standardize_data_formats' when using iterable datasets #126
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -405,10 +405,10 @@ def standardize_data_formats( | |
if "conversations" not in column_names: | ||
return dataset | ||
|
||
convos = dataset[:10]["conversations"] | ||
examples = itertools.islice(dataset, 10) | ||
uniques = collections.defaultdict(list) | ||
for convo in convos: | ||
for message in convo: | ||
for example in examples: | ||
for message in example["conversations"]: | ||
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. The main reason why I did "conversations" outside is to make it somewhat faster, but I guess since its 10 examples, no big deal |
||
for key, value in message.items(): | ||
if type(value) is not str: | ||
raise RuntimeError("Unsloth: Cannot standardize non text datasets!") | ||
|
@@ -464,15 +464,23 @@ def _standardize_dataset(examples): | |
return { "conversations" : all_convos, } | ||
pass | ||
|
||
from multiprocessing import cpu_count | ||
num_proc = cpu_count() | ||
|
||
return dataset.map( | ||
_standardize_dataset, | ||
batched = True, | ||
desc = "Unsloth: Standardizing formats", | ||
num_proc = num_proc, | ||
) | ||
if isinstance(dataset, IterableDataset): | ||
return dataset.map( | ||
_standardize_dataset, | ||
batched = True, | ||
batch_size = dataset._ex_iterable.batch_size, | ||
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. Interesting on 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. The reason I did this is to pass the batch_size, if you are using a iterable dataset, you might have a resource restrained system and by default it would use a batch size of 1000, but this way it will keep the same batch size it had before the |
||
desc = "Unsloth: Standardizing formats" | ||
) | ||
else: | ||
from multiprocessing import cpu_count | ||
num_proc = cpu_count() | ||
|
||
return dataset.map( | ||
_standardize_dataset, | ||
batched = True, | ||
desc = "Unsloth: Standardizing formats", | ||
num_proc = num_proc, | ||
) | ||
pass | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this specifically for iterable datasets? Ie
itertools.islice
works for iterable datasets whilstdataset[:10]
does not?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exactly, you can't use an index or in this case
[:10]
on iterators