Also, if you want a detailed control on how the data generate and be consumed by processes, consider using custom dataloader Writing Custom Datasets, DataLoaders and Transforms — PyTorch Tutorials 1.9.1+cu102 documentation