Hi,
I’ve been using Pytorch to create a Hamiltonian Monte Carlo (HMC) inference algorithm for directed graphical models. However, some of these graphical models can be quite large and all that is changing within the graph is the value of the latent variables, which have the flag requires_grad = True. As with each iteration we generate new proposals with the HMC algorithm which are then reassigned to the values of the latent variables, if they are accepted at the proposal step.
I’m currently using the torch.autograd.grad() function whenever I compute the gradients, as with backward, because it propagates all the way through the graph it can add additional things to the gradients of the variables. By the way, a digamma and beta function implementation in PyTorch would be super awesome for the inference community and the ability to do Choelsky decomposition with variable objects would also be awesome, as torch.potrf() only allows tensors.
The graphical model is contained within another module and it has to recreate the graph each time, despite the structure not changing and only the data of the latent variables variable object.
I love the dynamic graph structure of PyTorch, hence why I am not using TF, but is there a way to do this kind of computation more efficiently. I can provide code, if more details are needed.
Thanks in advance.