The recommanded approach is create a custom Theano Ops with its gradient. You can see a example here: https://docs.pymc.io/Advanced_usage_of_Theano_in_PyMC3.html#writing-custom-theano-ops and a more in complex example here: https://docs.pymc.io/notebooks/blackbox_external_likelihood.html
2 Likes