Thank you for your help. As far as I understand I will not be able to solve this in such form as I have to provide it with forward and backward function (what means, I have to perform all operations the external tool is doing so the pytorch will be able to compute the gradient). The problem is that I do not know what exactly the external tool does.