Hi, I am trying to execute a dataset of approx (400k) records with the help of GPU. While training the model, lot of time is consumed in loading the data inside the for loop. How do I load the full data to cuda directly from the dataloader to improve the speed of execution.
model = Net().cuda()
optimizer = optim.Adam(model.parameters(), lr=0.001)

loss_func = nn.NLLLoss()

epochs = 3
loss_list = []
correct = 0
model.train()

for epoch in range(epochs):
    total_loss = []
    
    for i, (X_tr, Y_tr) in enumerate(train_ldr):
        
  # get the inputs; data is a list of [inputs, labels]
      X_tr = X_tr.unsqueeze(0).cuda()
     
      Y_tr = Y_tr.type(torch.LongTensor).cuda()
      
      optimizer.zero_grad()

        # Forward pass
      output = model(X_tr).cuda()
      
      pred = output.argmax(dim=1, keepdim=True)
      correct += pred.eq(Y_tr.view_as(pred)).sum().item()
      loss = loss_func(output, Y_tr).cuda()
        # Backward pass
      loss.backward()
        # Optimize the weights
      optimizer.step()
        
      total_loss.append(loss.item())
#      print(correct, Y_tr, pred)

      loss_list.append(sum(total_loss)/len(total_loss))
    print('Training [{:.0f}%]\tLoss: {:.4f}'.format(
        100. * (epoch + 1) / epochs, loss_list[-1]))