Skip to content
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

Fix overflow in nanosets with big datasets #182

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jquesnelle
Copy link
Contributor

When a nanoset is particularly big (>4 GB), the calculation of offset (the actual location within the memmap) can overflow. The issue is with the line

offset = dataset_sample * self.sequence_length * (np.iinfo(self.token_dtype).bits / 8)

Here, dataset_sample is a numpy "uint", and the calculation of offset can overflow since numpy's "uint" type is 32 bits. The solution is to promote everything to native Python int first, which has automatic overflow.

input_ids_tokens = np.frombuffer(
self.dataset_buffer, dtype=self.token_dtype, count=(self.sequence_length + 1), offset=int(offset)
self.dataset_buffer, dtype=self.token_dtype, count=(self.sequence_length + 1), offset=offset
Copy link
Member

Choose a reason for hiding this comment

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

Nice find! Can you add a small unittest for this in tests/nanoset/test_build_nanoset_dataloader.py? thanks!

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