pin_memory will used page-locked memory to speed up the transfer between the device and host. You could also use to(non_blocking=True) to transfer the data asynchronously.


Your MakeDataset transfers each sample separately in __getitem__, which might be slower than transferring the complete batch to the device in the training loop. If you have enough memory on the device, you should push the complete data in __init__ to the device.