| 15 | |
| 16 | |
| 17 | class RepeatingLoader: |
| 18 | |
| 19 | def __init__(self, loader): |
| 20 | """Wraps an iterator to allow for infinite iteration. This is especially useful |
| 21 | for DataLoader types that we wish to automatically restart upon completion. |
| 22 | |
| 23 | Args: |
| 24 | loader (iterator): The data loader to repeat. |
| 25 | """ |
| 26 | self.loader = loader |
| 27 | self.data_iter = iter(self.loader) |
| 28 | |
| 29 | def __iter__(self): |
| 30 | return self |
| 31 | |
| 32 | def __next__(self): |
| 33 | try: |
| 34 | batch = next(self.data_iter) |
| 35 | except StopIteration: |
| 36 | self.data_iter = iter(self.loader) |
| 37 | batch = next(self.data_iter) |
| 38 | return batch |
| 39 | |
| 40 | |
| 41 | class DeepSpeedDataLoader(object): |
no outgoing calls