Can not send dataset to GPU

Hello,

I am a newbies for ML. I started training MNIST dataset. I can send my model to GPU by using this code.

network.to(device) # Returned… true

When I sent the dataset to GPU by this testing code.

for batch_idx, (data, target) in enumerate(train_loader):
data.to(device)
target.to(device)
if batch_idx == 100:
print(data.device)
print(type(data))
pass

#Returned … cpu
#Returned … <class ‘torch.Tensor’>

Question: Why does “data.to(device)” still be on CPU?
Note: I use RTX30xx

The to() operation is not applied inplace on tensors (unlike on modules as it’s recursively applied on all submodules, parameters, and buffers internally), so you need to reassign the tensor:

x = x.to(...)
1 Like

Thank you very much , I got it :slight_smile: solved