In the code below I’m moving all the data to the GPU.
# Data Loader for easy mini-batch return in training
train_loader = Data.DataLoader(dataset=train_data, batch_size=BATCH_SIZE, shuffle=True, pin_memory=True)

# Move data to GPU
batch_x = []
batch_y = []
for x, y in train_loader:
    batch_x.append(Variable(x.view(-1, 28 * 28)).to(device))
    batch_y.append(Variable(x.view(-1, 28 * 28)).to(device))

gpu_data = zip(batch_x, batch_y)

Probably there is a way I can accomplish it without looping through the batches. Can someone point it out?