torch.trace torch.trace(input) → Tensor Returns the sum of the elements of the diagonal of the input 2-D matrix. Example: >>> x = torch.