Ok so I did check and reordered the code as below:
model = VGG16
dataset = CIFAR10

def main():
    model = create_model()
    train_loader = torch.utils.data.DataLoader(...CIFAR10...)
     if torch.cuda.device_count() > 1:
         model = torch.nn.parallel.DataParallel(model)
     optimizer = torch.optim.SGD(model.parameters(), lr=0.05, weight_decay=5e-4, momentum=0.9)
     model.to(device)
     train()
     test()