This works for me.
import torch
import numpy as np
import torch.utils.data as data

class model(torch.nn.Module):
    def __init__(self, D_in, H):
        super(model,self).__init__()
        self.transfer = torch.nn.Sigmoid()
        self.lin1 = torch.nn.Linear(D_in, H)
        self.lin2 = torch.nn.Linear(H, 1)
        
    def forward(self, x1, x2):
        x1 = self.lin1(x1)
        x1 = self.transfer(x1)
        x1 = self.lin2(x1)
        print(x1)
        
        x2 = self.lin1(x2)
        x2 = self.transfer(x2)
        x2 = self.lin2(x2)
        print(x2)
        
        matrix = torch.Tensor([[1e0, 0, 0], [0, 4e0, 0e0], [0, 0e0, 2e0]])
        matrix = matrix.view(3,3,1)
        matrix[0,1] += x1.squeeze(0)
        matrix[1,0] += x1.squeeze(0)
        matrix[0,2] += x2.squeeze(0)
        matrix[2,0] += x2.squeeze(0)

        eigval, eigvec = torch.symeig(matrix.squeeze(),eigenvectors=True)
        mineigval = torch.min(eigval) # Get the lowest eigenvalue of the matrix, just the real part.
        return mineigval


m = model(5,3)
d = torch.rand(1,5, requires_grad=True)
o = m(d, d+1)
o.backward()
print(d.grad)