Pyro: Use poutine.broadcast outside of inference

Created on 13 Jun 2018  路  2Comments  路  Source: pyro-ppl/pyro

I love @poutine.broadcast and I wish I could use it to generate data, e.g.

@poutine.broadcast
def model(size, data=None):
    with pyro.iarange("data", size):
        return pyro.sample("x", dist.Bernoulli(0.5), obs=data)

This broadcasts correctly in the context of SVI, but I cannot run this model to generate data.

>>> model(3)
tensor(1.)

Is it possible to make @poutine.broadcast always take effect, even outside of inference?

question

Most helpful comment

Your snippet gives the desired behavior for me with Pyro dev and Python 3.6:

>>> @poutine.broadcast
... def model(size, data=None):
...     with pyro.iarange("data", size):
...         return pyro.sample("x", dist.Bernoulli(0.5), obs=data)
...
>>> model(3)
tensor([1., 1., 0.])

All 2 comments

Your snippet gives the desired behavior for me with Pyro dev and Python 3.6:

>>> @poutine.broadcast
... def model(size, data=None):
...     with pyro.iarange("data", size):
...         return pyro.sample("x", dist.Bernoulli(0.5), obs=data)
...
>>> model(3)
tensor([1., 1., 0.])

Sorry, you're right.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

martinjankowiak picture martinjankowiak  路  3Comments

fritzo picture fritzo  路  4Comments

neerajprad picture neerajprad  路  4Comments

fritzo picture fritzo  路  5Comments

fritzo picture fritzo  路  4Comments