def lambda_mrr_loss(y_pred, y_true, eps=1e-10, padded_value_indicator=-1, reduction="mean"):
    """
    y_pred: FloatTensor [bz, topk]
    y_true: FloatTensor [bz, topk]
    """
    device = y_pred.device
    y_pred = y_pred.clone()
    y_true = y_true.clone()
    clamp_val = 1e8 if y_pred.dtype==torch.float32 else 1e4

    padded_mask = y_true == padded_value_indicator
    y_pred[padded_mask] = float("-inf")
    y_true[padded_mask] = float("-inf")
    #assert torch.sum(padded_mask) == 0

    # Here we sort the true and predicted relevancy scores.
    y_pred_sorted, indices_pred = y_pred.sort(descending=True, dim=-1)

    # After sorting, we can mask out the pairs of indices (i, j) containing index of a padded element.
    true_sorted_by_preds = torch.gather(y_true, dim=1, index=indices_pred)
    true_diffs = true_sorted_by_preds[:, :, None] - true_sorted_by_preds[:, None, :]
    padded_pairs_mask = torch.isfinite(true_diffs)
    padded_pairs_mask = padded_pairs_mask & (true_diffs > 0)

    # Here we clamp the -infs to get correct gains and ideal DCGs (maxDCGs)
    true_sorted_by_preds.clamp_(min=0.)

    # Here we find the gains, discounts and ideal DCGs per slate.
    inv_pos_idxs = 1. / torch.arange(1, y_pred.shape[1] + 1).to(device)
    weights = torch.abs(inv_pos_idxs.view(1,-1,1) - inv_pos_idxs.view(1,1,-1)) # [1, topk, topk]

    # We are clamping the array entries to maintain correct backprop (log(0) and division by 0)
    scores_diffs = (y_pred_sorted[:, :, None] - y_pred_sorted[:, None, :]).clamp(min=-50, max=50)
    # logger.info('scores_diffs:{}'.format(scores_diffs))
    # logger.info('torch.exp(-scores_diffs):{}'.format(torch.exp(-scores_diffs)))
    scores_diffs.masked_fill_(torch.isnan(scores_diffs), 0.)
    scores_diffs_exp = torch.exp(-scores_diffs)
    # scores_diffs_exp = scores_diffs_exp.clamp(min=-clamp_val, max=clamp_val)
    # logger.info('torch.max(scores_diffs):{}'.format(torch.max(scores_diffs)))
    # logger.info('torch.max(scores_diffs_exp):{}'.format(torch.max(scores_diffs_exp)))
    # logger.info('scores_diffs size:{}'.format(scores_diffs.size()))
    losses = torch.log(1. + scores_diffs_exp) * weights #[bz, topk, topk]
    # logger.info('weights:{}'.format(weights))

    if reduction == "sum":
        loss = torch.sum(losses[padded_pairs_mask])
    elif reduction == "mean":
        loss = torch.mean(losses[padded_pairs_mask])
    else:
        raise ValueError("Reduction method can be either sum or mean")

    # logger.info('loss:{}'.format(loss))

    return loss

    y_pred: FloatTensor [bz, topk]
    y_true: FloatTensor [bz, topk]
    
se2/DPR/dpr/models/biencoder.py