I don’t think that there’s a api for directly returning the vectorized upper triangular matrix, but you can still achieve that:
>>> a = torch.arange(1, 10).view(3, 3)
>>> a
 1 2 3
 4 5 6
 7 8 9
[torch.FloatTensor of size 3x3]

>>> triu_indices = a.triu().nonzero().transpose()
>>> triu_indices
 0 0 0 1 1 2
 0 1 2 1 2 2
[torch.LongTensor of size 2x6]

>>> vectorized_upper_triangular_matrix = a[triu_indices[0], triiu_indices[1]]
>>> vectorized_upper_triangular_matrix
1
2
3
5
6
9
[torch.FloatTensor of size 6]

Maybe there’s a better way that I’m not aware of.