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

Enforce passing item_loader when customizing underlying storage format #296

Merged
merged 6 commits into from
Aug 5, 2024

Conversation

tchaton
Copy link
Collaborator

@tchaton tchaton commented Aug 1, 2024

Before submitting
  • Was this discussed/agreed via a Github issue? (no need for typos and docs improvements)
  • Did you read the contributor guideline, Pull Request section?
  • Did you make sure to update the docs?
  • Did you write any new necessary tests?

What does this PR do?

Until now, we had a hack where 1D tensor would be handled differentely and stored as contiguous array. I have seen several users complaining about this magic and unexpected behaviour.

WARNING: This PR is a breaking change for LLM using the TokensLoader. Now, we would need to pass the item_loader to the optimize or Cache directly to inform the underlying storage needs to be handled differently.

If no item_loader is passed during the optimization, this default to the Pytree handler.

For LLM tokens, here is the breaking API change.

Before

from litdata.streaming.item_loader import TokensLoader

optimize(...)

dataset = StreamingDataset(item_loader=TokensLoader(...))

Now

from litdata.streaming.item_loader import TokensLoader

optimize(..., item_loader=TokensLoader())

dataset = StreamingDataset(item_loader=TokensLoader(...))

Fixes #294

PR review

Anyone in the community is free to review the PR once the tests have passed.
If we didn't discuss your PR in GitHub issues there's a high chance it will not be merged.

Did you have fun?

Make sure you had fun coding 🙃

@tchaton tchaton requested a review from awaelchli as a code owner August 1, 2024 19:54
Copy link
Contributor

@lantiga lantiga left a comment

Choose a reason for hiding this comment

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

Much cleaner and more robust. IMO the change is not confusing, one just has to use item loader on both sides.
What happens when I (erroneously) omit it?

@tchaton
Copy link
Collaborator Author

tchaton commented Aug 2, 2024

What happens when I (erroneously) omit it?

It would break and tell you the wrong item loader has been provided. Ok, waiting on @awaelchli review and ideas ;)

src/litdata/processing/functions.py Outdated Show resolved Hide resolved
@tchaton tchaton merged commit 518a1c3 into main Aug 5, 2024
26 checks passed
@tchaton tchaton deleted the prevent_hack branch August 5, 2024 08:31
@AugustDev
Copy link

TokensLoader accepts block_size. What if each of my sample is a dictionary where some of the fields are token sequences. Should block_size be length of the longest sequence?

@tchaton
Copy link
Collaborator Author

tchaton commented Aug 13, 2024

Hey @AugustDev. TokensLoader doesn't work on dictionary. It needs a 1D tensor.

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.

StreamingDataset cannot load one-element, one-dimensional tensors
4 participants