Autodiff compatibility required for Hamiltonian Monte Carlo?

I’d like to use the TensorFlow implementation of Hamiltonian Monte Carlo (HMC) with a biochemistry model I’ve written. When I try to sample from the likelihood distribution for the fit of this model to some data, I get an error traceback pointing at tensorflow_probability/python/math/, tensorflow/python/eager/, and so on.

The model code currently uses SciPy to integrate a system of ODEs, so it isn’t compatible with tf.GradientTape(). I thought that was OK because the API documentation only stipulates the argument target_log_prob_fn must be a “Python callable” and doesn’t mention anything about automatic differentiation. Do I need to rewrite my model to be compatible with TensorFlow autodiff?

1 Like