#5454·datasets

Save and resume the state of a DataLoader

Author: lhoestqCreated Jan 23, 2023Updated Sep 17, 2026
Labelsenhancementgeneric discussion

It would be nice when using datasets with a PyTorch DataLoader to be able to resume a training from a DataLoader state (e.g. to resume a training that crashed)

What I have in mind (but lmk if you have other ideas or comments):

For map-style datasets, this requires to have a PyTorch Sampler state that can be saved and reloaded per node and worker.

For iterable datasets, this requires to save the state of the dataset iterator, which includes:

  • the current shard idx and row position in the current shard
  • the epoch number
  • the rng state
  • the shuffle buffer

Right now you can already resume the data loading of an iterable dataset by using IterableDataset.skip but it takes a lot of time because it re-iterates on all the past data until it reaches the resuming point.

cc @stas00 @sgugger