def compute_l2_dist(x1, x2):
    """compute an (m, n) L2 distance matrix from (m, d) and (n, d) matrices"""
    return torch.cdist(x1.unsqueeze(0), x2.unsqueeze(0), p=2).squeeze(0).pow(2)
compute an (m, n) L2 distance matrix from (m, d) and (n, d) matrices
fairseq/tasks/text_to_speech.py