Skip to content

Cycle option for StreamingDataLoader #524

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
Aceticia opened this issue Mar 24, 2025 · 8 comments
Open

Cycle option for StreamingDataLoader #524

Aceticia opened this issue Mar 24, 2025 · 8 comments
Labels
enhancement New feature or request waiting on author Waiting for user input or feedback.

Comments

@Aceticia
Copy link

🚀 Feature

A function or an argument in StreamingDataLoader to cycle the passed in StreamingDataset.

Motivation

Many training scenarios in CV involve training models with multiple epochs, while wanting to control the exact number of steps being trained, independent of the underlying dataset size. E.g., given a CombinedStreamingDataset of some length, restart its iterations when it is exhausted.

Pitch

I'm not quite sure how this should be done - maybe in iter method of StreamingDataLoader, we can catch the final iteration and restart it?

@Aceticia Aceticia added the enhancement New feature or request label Mar 24, 2025
@tchaton
Copy link
Collaborator

tchaton commented Mar 26, 2025

You could check PyTorch Lightning Cycle Loaders: https://lightning.ai/docs/pytorch/stable/api/lightning.pytorch.utilities.combined_loader.html

Or create your own wrapper that iterates for a given number of steps.

@bhimrazy bhimrazy added the waiting on author Waiting for user input or feedback. label Mar 29, 2025
@bhimrazy
Copy link
Collaborator

Hi @Aceticia, ParallelStreamingDataset #576 has just been merged into litdata. Feel free to give it a try! You can find more details in the README under the sections Parallel Streaming and Cycle Datasets.

@philgzl
Copy link
Contributor

philgzl commented May 26, 2025

As mentioned by @lantiga in #576, the ability to cycle datasets using ParallelStreamingDataset is a nice option as it is, but this should probably be upstreamed to StreamingDataset in the future.

Idk if this issue should stay open so we don't forget.

@deependujha
Copy link
Collaborator

Hi @philgzl, are you suggesting something like:

sd = ld.StreamingDataset("..", cycle=True)

and so when iter raises StopIteration, we don't increase epoch count, and just restart iter?

@philgzl
Copy link
Contributor

philgzl commented May 26, 2025

Mmh I was thinking of a similar solution to what was implemented in ParallelStreamingDataset:

dset = ld.StreamingDataset("..", length=100)

Iterating over the dataset once then yields 100 samples. If the dataset has less than 100 samples, we cycle and shuffle internally. If we iterate over the dataset a second time, we resume from where we left off without re-shuffling, and yield 100 samples again.

This way we can disentangle the epoch length (as in the number of items yielded by iter) from the actual number of samples in the dataset. I believe this is what OP meant.

@philgzl
Copy link
Contributor

philgzl commented May 26, 2025

I realize now maybe what you meant with cycle=True is the same with length=float("inf").

@deependujha
Copy link
Collaborator

thanks for the clarification.

Similar to parallelSD, pass int or "inf". Sounds good to me.

@philgzl
Copy link
Contributor

philgzl commented May 26, 2025

Yes and then I guess this feature should be removed from ParallelStreamingDataset since we would just pass StreamingDataset instances which were already configured to cycle.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request waiting on author Waiting for user input or feedback.
Projects
None yet
Development

No branches or pull requests

5 participants