Solved by Divyanshu_Mishra in post #8 
              
              
                I changed the type of y2 from LongTensor to FloatTensor, the error was gone and also the training speed seems to have improved.