Hello,
I wanted to perform gradient operation of a 3-by-3 tensor with respect to another 3-by-3 tensor, which outputs a 3-by-3-by-3-by-3 tensor, see the following example code:
X = torch.tensor([[1,3,5],[3,1,7],[5,7,1]],dtype=torch.double)
X.requires_grad_(True)
def computeY(input):return torch.pow(input, 2)
dYdX = torch.autograd.functional.jacobian(computeY, X)
This does exactly what the Jacobian operation does, however, it does not seem to take into consideration that X
is symmetric.
If X
is a general matrix without symmetry information, then for example, dY[1,2]/dX[2,1] = 0. This is exactly what autograd does by default.
If X
is a symmetric matrix such that X[i,j] = X[j,i], then for example, dY[1,2]/dX[2,1] = dY[2,1]/dX[2,1] = dY[1,2]/dX[1,2] = 2X[1,2] = 2X[2,1] = 6. Does anyone know if there’s anyway to provide such symmetry information to autograd?
Many thanks!