Note that this only works when there are no zeros in the upper triangular part.
It would be cool if we could get more support for this in core pytorch. Also important is the opposite – going from a vectorization to an upper/lower triangular matrix. I haven’t been able to find a clean way to do this yet.