Skip to content

num_proc=os.cpu_count() when counting unused tokens #104

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

IsaacBreen
Copy link

This just sets num_proc=os.cpu_count() when counting unused tokens. Tested on a 64-core machine. Runs approximately 64 times faster.

This should be the default for all those HF map functions imho.

IsaacBreen and others added 4 commits March 21, 2025 21:16
…n-counting-unused-tokens

`num_proc=os.cpu_count()` when counting unused tokens
@IsaacBreen
Copy link
Author

unslothai/unsloth#1125

@@ -416,7 +417,7 @@ def mapping(examples):
counter = np.fromiter(itertools.chain.from_iterable(input_ids), dtype = np.int32)
np.add.at(final_counts, counter, 1)
pass
train_dataset.map(mapping, batched = True, desc = "Counting untrained tokens")
train_dataset.map(mapping, batched = True, desc = "Counting untrained tokens", num_proc = os.cpu_count())
Copy link
Contributor

Choose a reason for hiding this comment

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

This will break IterableDataset supports as they do not support the num_proc argument.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants