I'm experimenting with running neural network on GPU using pytorch, and my data have some unusual shape so I use Dataset and DataLoader to generate data batch. My code runs fine on CPU but I'm a little confused on when is the right timing to put the data on GPU:
- My data size is small enough to be put all together on GPU, should I put all data on GPU before fitting, so that all DataLoader and Dataset operations only take place on GPU in order to get optimal execution speed?
- Another possibility is to leave all data on CPU which could be useful when the data size become larger. In that case, should I call
batch.to("cuda")for each batch generated from DataLoader? - Should I also put the model on GPU first before training? It is a small enough model to be put on GPU.
- My raw data are numpy array, hence I have the freedom to write Dataset that returns numpy array in
__getitem()___method, or convert the numpy array to pytorch tensor and write Dataset that returns pytorch tensor. Is one method preferred over the other?