I want to implement VGG16 net model on MNIST. For this reason I resize 28x28 images into 224x224 but this time I need run it on a GPU. I followed the tutorials, however couldn’t run my code on gpu. I am not sure how to send mini batches to gpu device. Here is my code.
dev = torch.device(
    "cuda") if torch.cuda.is_available() else torch.device("cpu")
loss_func = F.cross_entropy
bs = 64  # batch size
l_r = 0.001  # learning rate
epochs=1

model=VGG16Conv()
model.to(dev)
opt=optim.SGD(model.parameters(), lr=l_r)

train_ds = TensorDataset(x_train_, y_train)
train_dl = DataLoader(train_ds, batch_size=bs, shuffle=True)
valid_ds = TensorDataset(x_valid_, y_valid)
valid_dl = DataLoader(valid_ds, batch_size=bs * 2)

for epoch in range(epochs):
    print('EPOCH ', epoch)
    for xb, yb in train_dl:
        for sub in range(1,4):
            loss=loss_func(model.feedforward(xb, sub),yb)
            loss.backward()
            self.plot_grad_flow()
            opt.step()
            opt.zero_grad()
    print('VALIDATION STARTS')
    valid=[]
    with torch.no_grad():   
        valid_loss = sum(loss_func(model.feedforward(xb), yb) for xb, yb in valid_dl)
        #accuracy(model.feedforward(xb), yb)
        valid.append(sum(accuracy(model.feedforward(xb), yb) for xb, yb in valid_dl))
    print('validation loss: ', valid_loss / len(valid_dl))
    print('validation accuracy: ', sum(valid) / len(y_valid))