grsilva:

def inv_var(y1, y2):
       y_hat = torch.sum( (y_1/y_1.var() ), ( y_2/y_2.var()) ) /  torch.sum( (1 /y_1.var() ), ( 1/y_2.var())  )
return y_hat



That fixed the problem thank you! I have gradients now, but they are very small so onto the next problem haha.
Thank you for your help