data icon indicating copy to clipboard operation
data copied to clipboard

DataLoader2 should reset when a new iterator is created?

Open NivekT opened this issue 2 years ago • 0 comments

When a new iterator is created, DataLoader2 currently resumes from when it was left off rather than resetting and starting from the beginning again (see code snippet below). This is divergent from the behavior of the original DataLoader. Users likely expect the latter behavior and we should properly reset the state of DataLoader2 when a new iterator is created.

from torchdata.dataloader2 import DataLoader2
from torchdata.datapipes.iter import IterableWrapper


dl = DataLoader2(IterableWrapper(range(10)))

for i in iter(dl):
    print(i)
    if i == 4:
        print('--------------')
        break

for i in iter(dl):
    print(i)

cc: @VitalyFedyunin

NivekT avatar Jun 24 '22 18:06 NivekT