def METHOD_NAME(self, output, label, weight=None):
    # euclidian distance
    # diff = vecs1 - vecs2
    # dist_sq = torch.sum(torch.pow(diff, 2), 1)
    # dist_l2 = torch.sqrt(dist_sq)
    # p1 = torch.nn.PairwiseDistance(p=1)(vecs1, vecs2)
    # dist_l2 = torch.nn.PairwiseDistance(p=2)(vecs1, vecs2)
    dist_l2 = output
    dist_sq = torch.pow(dist_l2, 2)
    if label.is_cuda:
        label_ = label.type(torch.FloatTensor).cuda(label.get_device())
    else:
        label_ = label.type(torch.FloatTensor)
    loss2x_genuine = (1 - label_) * torch.pow(
        torch.clamp(self.margin - dist_l2, min=0.0), 2
    )
    loss2x_imposter = label_ * dist_sq
    if weight is not None:
        loss2x_imposter = loss2x_imposter * weight[0]
        loss2x_genuine = loss2x_genuine * weight[1]
    loss2x = loss2x_genuine + loss2x_imposter
    ave_loss = torch.sum(loss2x) / 2.0 / label.size()[0]
    loss = ave_loss
    return loss