I had problems when the code run into the epoch as mentioned below:
def train_test_one_split(cv, train_index, test_index):
x_train, y_train = X[train_index], Y[train_index]
x_test, y_test = X[test_index], Y[test_index]
x_train = torch.from_numpy(x_train).long()
y_train = torch.from_numpy(y_train).long()
dataset_train = TensorDataset(x_train, y_train)


#train_loader = DataLoader(dataset_train, batch_size=hidden, shuffle=True, num_workers=4, pin_memory=True)
train_loader = DataLoader(
    dataset_train, batch_size=batch_size, shuffle=True, num_workers=4, pin_memory=False,drop_last=False)

x_test = torch.from_numpy(x_test).long()
y_test = torch.from_numpy(y_test).long()
try:
    if use_cuda:
        x_test = x_test.cuda()
        y_test = y_test.cuda()
except Exception as ex:
    print(ex)
#model = CNN(kernel_sizes, num_filters, embedding_dim, pretrained_embeddings)
model = LSTMClassifier(batch_size, output_size, hidden_size,
                       vocab_size, embedding_length, pretrained_embeddings)
if cv == 0:
    print("\n{}\n".format(str(model)))

if use_cuda:
    model = model.cuda()

parameters = filter(lambda p: p.requires_grad, model.parameters())
optimizer = torch.optim.Adam(parameters, lr=0.0002)

loss_fn = nn.CrossEntropyLoss()

for epoch in range(10):
    tic = time.time()
    model.train()
    for i, (inputs, labels) in enumerate(train_loader):
        batch_size = inputs.shape[0]
        inputs, labels = Variable(inputs), Variable(labels)                    
        if use_cuda:
            inputs, labels = inputs.cuda(), labels.cuda()
            if((inputs.shape[0],inputs.shape[1])!= (batch_size, sentence_len)):
                #(inputs.shape[0], inputs.shape[1]) = (batch_size, sentence_len)
                print('validation - Input shape issue', inputs.shape)
                continue
            
        

        preds = model(inputs)

        if use_cuda:
            preds = preds.cuda()
        try:
            loss = loss_fn(preds, labels)

            optimizer.zero_grad()
            loss.backward()
            optimizer.step()
        except RuntimeError:
            continue

        # this does not improve the performance (even worse) (it was used in Kim's original paper)
        if 0:
            constrained_norm = 1  # 3 original parameter
            if model.fc.weight.norm().data[0] > constrained_norm:
                model.fc.weight.data = model.fc.weight.data * \
                    constrained_norm / model.fc.weight.data.norm()

    model.eval()
    eval_acc, sentence_vector = evaluate(model, x_test, y_test)
    #print('[epoch: {:d}] train_loss: {:.3f}   acc: {:.3f}   ({:.1f}s)'.format(epoch, loss.data[0], eval_acc, time.time()-tic) )
    print('[epoch: {:d}] train_loss: {:.3f}   acc: {:.3f}   ({:.1f}s)'.format(
        epoch, loss.item(), eval_acc, time.time()-tic))  # pytorch 0.4 and later
return eval_acc, sentence_vector