Solved by mishooax in post #3 
              
              
                Hmm… I think this does it: 
    tmp_b = - 1.0 / (2 * m * (m - 1)) * torch.mean(
        torch.sum(
          torch.pow(
              torch.cdist(
                  y_pred_.reshape(bs, -1, m).permute(0,2,1), y_pred_.reshape(bs, -1, m).permute(0,2,1), p=2
              ), beta
          ), axis=(1,2)…