To speed up the data loading, you could preload the complete dataset assuming that you won’t apply any on-the-fly data augmentation. Since the DataLoader can already use multiprocessing to load and process the data in the background while the model is training, I don’t see any way to speed it up using while or a map besides trying to remove potential bottlenecks in the data loading itself.