Solved by Isaac_Kargar in post #6 
              
              
                I just changed your input tensor liek this: Input = torch.LongTensor([[1,2,3,4,5],[6,5,5,4,6]]).to(device) and it works. 
here is the complete code: 
import torch
import numpy as np
import torch.nn as nn

device = 'cuda:0'

batch_size =20
input_length=20
output_size=vocab_size = 10000
num_layers=2
h…