I don’t think that there is an exact equivalent. But here is a workaround:
PS: this example is the same exposed in the link you provided.
import torch
x = torch.Tensor([
                  [[1, 0, 0, 0],
                   [0, 2, 0, 0],
                   [0, 0, 3, 0],
                   [0, 0, 0, 4]],
                  [[5, 0, 0, 0],
                   [0, 6, 0, 0],
                   [0, 0, 7, 0],
                   [0, 0, 0, 8]]
		         ])
y = torch.stack(tuple(t.diag() for t in torch.unbind(x,0)))