Using pymc3 NUTS sampler for an "external model" having its derivatives with respect to its parameters

You can not use @th.compile.ops.as_op, as it is just a small wrapper. In this case you have to create a new theano.Op with a gradient method inside. Have a look at the above post, and also the theano doc: http://deeplearning.net/software/theano/extending/extending_theano.html