Thank you very much for your reply and hint. I could find the problem.
I don’t know the reasons, it seems the problems is due to LongTensor type which must be changed to FloatTensor. In this regard, all lines must be FloatTensor type. So I changed my forward function in cust_loss class as follow and it worked.
   def forward(self, input, target):
        predicted_labels = torch.max(input, 1)[1].float()
        minus = predicted_labels - target.float()
        self.cust_distance = torch.sum(minus*minus).type(torch.FloatTensor)/predicted_labels.size()[0]
        return self.cust_distance