RuntimeError: log_vml_cpu not implemented for 'Long'

viralpandey: <p>Hello,<br>
I am working on the Dsprites Dataset and have created a Causal Variational Auto Encoder. I am trying to answer counterfactual queries like “given this image of a heart with this orientation, position, and scale, what would it have looked like if it were a square?”</p>
<p>While building the Structural Causal Model and conditioning on it I am getting the runtime error of l <code>og_vml_cpu not implemented for 'Long'</code>  while running the Inference. This looks like some GPU to CPU issue of Pyro or Pytorch but I am not sure. Here is the error:</p>
<pre><code class="lang-auto">---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
&lt;ipython-input-35-a6f1c970e088&gt; in &lt;module&gt;()
     13 #posterior = MCMC(kernel, num_samples=1000, warmup_steps=50)
     14 
---&gt; 15 posterior = pyro.infer.Importance(conditioned_model, num_samples = 1).run(vae, mu, sigma)
     16 #posterior.run(vae, mu, sigma)
     17 

3 frames
/usr/local/lib/python3.6/dist-packages/pyro/infer/abstract_infer.py in run(self, *args, **kwargs)
    222         self._reset()
    223         with poutine.block():
--&gt; 224             for i, vals in enumerate(self._traces(*args, **kwargs)):
    225                 if len(vals) == 2:
    226                     chain_id = 0

/usr/local/lib/python3.6/dist-packages/pyro/infer/importance.py in _traces(self, *args, **kwargs)
     48             model_trace = poutine.trace(
     49                 poutine.replay(self.model, trace=guide_trace)).get_trace(*args, **kwargs)
---&gt; 50             log_weight = model_trace.log_prob_sum() - guide_trace.log_prob_sum()
     51             yield (model_trace, log_weight)
     52 

/usr/local/lib/python3.6/dist-packages/pyro/poutine/trace_struct.py in log_prob_sum(self, site_filter)
    189                 else:
    190                     try:
--&gt; 191                         log_p = site["fn"].log_prob(site["value"], *site["args"], **site["kwargs"])
    192                     except ValueError:
    193                         _, exc_value, traceback = sys.exc_info()

/usr/local/lib/python3.6/dist-packages/pyro/distributions/delta.py in log_prob(self, x)
     58     def log_prob(self, x):
     59         v = self.v.expand(self.shape())
---&gt; 60         log_prob = (x == v).type(x.dtype).log()
     61         log_prob = sum_rightmost(log_prob, self.event_dim)
     62         return log_prob + self.log_density

RuntimeError: log_vml_cpu not implemented for 'Long' 
</code></pre>
<p>Here is the code of my SCM:</p>
<pre><code class="lang-auto">from pyro.infer.importance import Importance
from pyro.infer.mcmc import MCMC
from pyro.infer.mcmc.nuts import HMC


intervened_model = pyro.do(SCM, data={"Y_shape": torch.tensor(1)})
conditioned_model = pyro.condition(intervened_model, data={
                                       "X": recon_x1, 
                                       "Y_shape": torch.tensor(0),
                                       "Z":z1})

#kernel = HMC(conditioned_model, step_size=0.8, num_steps=4)
#posterior = MCMC(kernel, num_samples=1000, warmup_steps=50)

posterior = pyro.infer.Importance(conditioned_model, num_samples = 1).run(vae, mu, sigma)
#posterior.run(vae, mu, sigma)

marginal = posterior.EmpiricalMarginal(posterior, )

print(type(posterior))
print(posterior)

result = []
for i in range(10):
  trace = posterior()
  x = trace.nodes['Nx']['value']
  y = trace.nodes['Ny']['value']
  z = trace.nodes['Nz']['value']
  con_obj = pyro.condition(intervened_model, data = {"Nx": x,"Ny": y, "Nz": z})
#   result.append(con_obj()[2])
  
# recon_x2,y2,z2 = con_obj(vae, mu, sigma)
# print(y2)
# recon_check(recon_x1.reshape(-1, 64, 64)[0], recon_x2.reshape(-1, 64, 64)[0])
</code></pre>
<p>Please let me know how to debug this or what the issue is. Highly appreciated</p>

ptrblck: <p>Could you post the <code>type()</code> of the data you are passing, i.e. <code>recon_x1</code>, <code>vae</code>, <code>mu</code>, etc.?<br>
It seems the internal cast to <code>x.dtype</code> is creating the error, but I’m not sure, which input value corresponds to <code>x</code>.</p>

viralpandey: <p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/2X/3/3ae28f82c3500f2304fca486de12589f81688577.png" data-download-href="https://discuss.pytorch.org/uploads/default/3ae28f82c3500f2304fca486de12589f81688577" title="08%20PM"><img src="https://discuss.pytorch.org/uploads/default/optimized/2X/3/3ae28f82c3500f2304fca486de12589f81688577_2_330x500.png" alt="08%20PM" data-base62-sha1="8oV61hT0yfJ0QV0ZggMVX5yrwkT" width="330" height="500" srcset="https://discuss.pytorch.org/uploads/default/optimized/2X/3/3ae28f82c3500f2304fca486de12589f81688577_2_330x500.png, https://discuss.pytorch.org/uploads/default/original/2X/3/3ae28f82c3500f2304fca486de12589f81688577.png 1.5x, https://discuss.pytorch.org/uploads/default/original/2X/3/3ae28f82c3500f2304fca486de12589f81688577.png 2x" data-dominant-color="F1F1F2"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">08%20PM</span><span class="informations">428×648 22.8 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>

ptrblck: <p>Thanks! Could you post the <code>recon_x1.type()</code> etc.?<br>
This yields more information as the built-in Python <code>type</code> method.</p>
<p>PS: It’s better to post code snippets than images. <img src="https://discuss.pytorch.org/images/emoji/apple/wink.png?v=9" title=":wink:" class="emoji" alt=":wink:"></p>

viralpandey: <p>Hey, I think I have resolved that particular error for now. Thank you for your support, much appreciated!</p>

viralpandey: <p>The issue was in  <code>dist.Delta(Nx &lt; p.cpu())</code>. <a class="mention" href="/u/neerajprad">@neerajprad</a> helped on the pyro forum with this. <a href="https://forum.pyro.ai/t/runtimeerror-log-vml-cpu-not-implemented-for-long/1206/7?u=viralpandey" rel="nofollow noopener">https://forum.pyro.ai/t/runtimeerror-log-vml-cpu-not-implemented-for-long/1206/7?u=viralpandey</a></p>