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
Open
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions unsloth_zoo/loss_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,9 @@ def _unsloth_get_batch_samples(self, epoch_iterator, num_batches, device = None,
pass

# Get num_items_in_batch
if has_kwargs and len(batch_samples) > 0 and "labels" in batch_samples[0]:
if has_kwargs and len(batch_samples) > 0 and batch_samples[0].get("labels") is not None:
try:
if not "attention_mask" in batch_samples[0]: is_vlm = False
if batch_samples[0].get("attention_mask") is None: is_vlm = False
if not is_vlm:
num_items_in_batch = sum(
[(x["labels"][..., 1:] != -100)\
Expand Down
3 changes: 2 additions & 1 deletion unsloth_zoo/tokenizer_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import itertools
import datasets
import re
import os

__all__ = [
"mean_of_trained_tokens",
Expand Down Expand Up @@ -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.


# Get sum of all items
sum_embedding = torch.sum(embedding_matrix, dtype = torch.float32, axis = 0)
Expand Down