StreamingDataset provides checkpointing in case your model training fails partway through a run. Use StreamingDataset.state_dict() to capture the current number of samples consumed from each split in a Python dictionary, save it alongside your model weights, and load_state_dict() to restore the last saved position — see Resuming for the load side.
This page assumes the rank, world_size, num_splits and shuffle_seed
terminology from Distributed Training.
A stored StreamingDataset state reflects only round-robin cycles that have been completed across all splits; samples completed partway through a cycle at the time of saving can be replayed. To ensure efficient saving, make sure global_batch_size is a multiple of num_splits, as in the example below.
Checkpointing with Multiple DataLoader Workers
Python’s built-intorch.utils.data.DataLoader produces a safe checkpoint when num_workers = 0. With num_workers > 0, calling state_dict() often raises RuntimeError. In this case, use StreamingDataLoader for multi-worker prefetch and exact resumability. It carries a state snapshot
alongside every internal batch and commits it to the parent StreamingDataset only when that batch is returned to the
trainer. The trainer receives the same collated batch it would receive from a standard DataLoader.
StreamingDataLoader accepts the same arguments as torch.utils.data.DataLoader, with a few restrictions:
datasetmust be aStreamingDataset(subclasses that override__iter__are not supported).in_order = Trueis required so that consumer-committed checkpoints stay deterministic.persistent_workers = Trueis not supported, because prefetched worker copies cannot be restored from parent-committed state.drop_last = Trueis not supported, because incomplete tails discarded by worker replicas cannot be checkpointed topology-independently.
state_dict() at a complete logical step boundary where every split assigned to the
rank has the same consumed-sample count. Calling it mid-step raises RuntimeError asking you to consume more batches
first.
Next steps
Resuming
Load a saved checkpoint back, on the same or a different topology.
Distributed Training
The rank, world size and split terminology checkpointing builds on.