Get error when running NUTS on GPU (cuda)

Hi,

I’m new to Pyro, and am trying to use Pyro.MCMC to inversely quantify the uncertainty of parameters of a physical model.

I’m trying to running NUTS on GPU(cuda), I’m pretty sure I added cuda to all tensors, including pyro.sample and pyro.param, but still encountered the following error.

RuntimeError: Function AddBackward0 returned an invalid gradient at index 1 - expected type torch.cuda.FloatTensor but got torch.FloatTensor

I appreciate your help and comments on my problem. Thanks in advance!

you are missing a conversion to cuda somewhere. it would be easier to diagnose if you posted your code, but some common places people have missed include:

  • converting data to CUDA
  • using torch.set_default_tensor or specifying device for all new tensors
  • calling cuda on all nn modules
  • specifying device when using pyro.plate (it defaults to your default tensor type)
1 Like

Thanks much @jpchen for your help! I realized that I didn’t specify pyro.plate as cuda… now the problem is solved! Thanks!