Hi Jason!
I haven’t read your code, nor can I speak about QPFunction.
However:



 Jason_Hu1:

  loss = Variable(loss_func(predictions, solutions), requires_grad=True)



Here you create a new Variable that is no longer connected to
the computation graph.  (Note that Variable is deprecated, and
in current versions of pytorch is just a Tensor).  Creating it with
requires_grad = True doesn’t fix this problem.
Consider:
>>> torch.__version__
'1.7.1'
>>> loss_func = torch.nn.MSELoss()
>>> pred = torch.randn (3, requires_grad = True)
>>> targ = torch.randn (3)
>>> loss1 = torch.autograd.Variable (loss_func (pred, targ), requires_grad = True)
>>> loss1.backward()
>>> pred.grad
>>> loss2 = loss_func (pred, targ)
>>> loss2.backward()
>>> pred.grad
tensor([-0.4108,  0.5605, -0.4539])

Best.
K. Frank