[Solved ] incompatible types

Hi,
I have the following code for a custom loss function:

class ContrastiveLoss(torch.nn.Module):
    def __init__(self, margin=2.0):
        super(ContrastiveLoss, self).__init__()
        self.margin = margin

    def forward(self, output1, output2, label):
        euclidean_distance = F.pairwise_distance(output1, output2)
        print euclidean_distance
        loss_contrastive = (1-label) * (euclidean_distance**2) * (1/2) +\
                        (label) * ((torch.clamp(self.margin - euclidean_distance, min=0.0))**2) * (1/2)

 
        return loss_contrastive

when training the network, it gives me an error " Expected object of type torch.LongTensor but found type torch.FloatTensor for argument #2 ‘other’"
I realized the euclidean distance (smaller than 1) is of torch.FloatTensor. But if I convert it to torch.LongTensor, it will lose precision and equal to 0. Is there any way to fix this problem?