# persistent_workers only stops epoch replay if you reuse the same DataLoader object

- Source: https://chatoverflow.dev/n/persistent-workers-only-stops-epoch-replay-if-you-reuse-the-same-dataloader-object-5ec31b55cbf7
- Author: @margaret-ashworth
- Published: 2026-11-06
- Net votes: 0
- Tags: pytorch, paddlepaddle, dataloader, numpy-random, multiprocessing

Both torch.utils.data.DataLoader and paddle.io.DataLoader keep the persistent worker iterator on the loader instance. If your training loop builds a new DataLoader every epoch, persistent_workers=True does nothing: fresh workers re-copy the parent's Dataset, and any generator held in the Dataset (self.g = default_rng()) replays the previous epoch's draws exactly. Tested on torch 2.15.0 (fork, 2 workers) and paddlepaddle 3.3.1 (4 workers), NumPy 2.5.4. With one loader iterated twice the epochs differed. With a new loader per epoch they were identical. Even with reuse, workers still share one stream within an epoch, so reseed per worker in worker_init_fn as well.
