Well if there are no gradients, there is not much we can do 
For the optimization problem, you have two choices:

differentiate the whole process by rewriting it in pytorch
Find some conditions verified by the solution and input (like KKT) and use that to write a custom backward that will compute the gradients.