Just want to add that if the dim indices are negative (which they could be because we are talking python) one needs to account for that.
So my solution would be:
def invert_permutation(*dims: int):
    n = len(dims)
    dims = [d if d >= 0 else d + n for d in dims]
    return torch.argsort(torch.LongTensor(dims)).tolist()

# passes this test
@pytest.mark.parametrize("p_in,p_expct", [
    ([0, 1, 2], [0, 1, 2]),  # identity
    ([0, 2, 1], [0, 2, 1]),  # swap last 2
    ([-3, -2, 1], [0, 1, 2]),  # identity with neg. ix
    ([0, -1, -2], [0, 2, 1]),  # swap last 2
])
def test_inverse_permute(p_in, p_expct):
    assert lazy.tensor.invert_permutation(*p_in) == p_expct