Enum_discrete breaks SVI


#1

Hi,

When using enum_discrete = True to reduce variance in my SVI, Pyro complains that some internal tensors are not in the same location (GPU/CPU), whereas turning it off makes it work fine:

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-31-93fd337a0d5c> in <module>()
----> 1 train()

<ipython-input-30-98110a9a9720> in train()
     33 
     34             # Train and score
---> 35             train_loss += svi.step(input_batch, target_batch)
     36 
     37         # Store history

/home/reinier/anaconda2/lib/python2.7/site-packages/pyro/infer/svi.pyc in step(self, *args, **kwargs)
     96         """
     97         # get loss and compute gradients
---> 98         loss = self.loss_and_grads(self.model, self.guide, *args, **kwargs)
     99 
    100         # get active params

/home/reinier/anaconda2/lib/python2.7/site-packages/pyro/infer/elbo.pyc in loss_and_grads(self, model, guide, *args, **kwargs)
     63         :rtype: float
     64         """
---> 65         return self.which_elbo.loss_and_grads(model, guide, *args, **kwargs)

/home/reinier/anaconda2/lib/python2.7/site-packages/pyro/infer/trace_elbo.pyc in loss_and_grads(self, model, guide, *args, **kwargs)
    149                         guide_site = guide_trace.nodes[name]
    150                         lp_lq = model_site[log_pdf] - guide_site[log_pdf]
--> 151                         elbo_particle += lp_lq
    152                         if guide_site["fn"].reparameterized:
    153                             surrogate_elbo_particle += lp_lq

RuntimeError: Expected object of type Variable[torch.FloatTensor] but found type Variable[torch.cuda.FloatTensor] for argument #1 'other'

Is this a bug?

-Reinier


#2

Yes that’s a bug, could you file an issue? How easy is it to reproduce the error?