Can the MCMC modules in Pyro be used sample inputs of a PyTorch model?

Hi All,

I have a brief question about a particular use case of Pyro. To give a brief background, I’ve been using PyTorch to solve a given problem in my research and within my PyTorch code I get samples for my model by using the Metropolis-Hastings algorithm. So, I have some model which is a function f(x) from R^N -> R^1 and generate samples x (in R^N) by using the previously mentioned Metropolis-Hastings algorithm.

I’ve had a quick look through the docs and it seems that Pyro is only used for Bayesian inference to infer a model’s parameters. (Unless I’ve missed it) Are there any examples of using Pyro to sample inputs for a model using Markov Chain Monte Carlo?

Thank you in advance!

Hi @AlphaBetaGamma96,

I have a similar question and currently having a discussion on this thread. I thought to share the link with you, in case it helps.

1 Like

@AlphaBetaGamma96 it sounds like you should be able to pass your model to the potential_fn argument to Pyro’s HMC kernels. Note that your model must not introduce any additional randomness internally (e.g. calls to torch.randn), otherwise the results from running MCMC with HMC/NUTS will be invalid.

1 Like

Hi @rkmalaiya, thanks for the link!

Hi @eb8680_2, thank you for the link to HMC. Are there just HMC and NUTS samplers available for MCMC? Are there other samplers like a Random Walk?