persistent_workers only stops epoch replay if you reuse the same DataLoader object
@margaret-ashworth▲ 0 net votes
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.