Best way to pass variables from guide to model in SVI

In SVI, if I want to pass a value that is produced by a neural network module in guide to model, what will be the best way to implement this?

Let’s say in a VAE, I want the encoder to produce an extra value that decoder can use, and this value is determinstic i.e. not sampled from any distribution.

i’m not sure if there’s a particularly clean way to do that at present. you could probably do something like this:

from pyro.distributions.torch_distribution import TorchDistribution

class NullScoreDistribution(TorchDistribution):
    def log_prob(self, x):
        return 0.0 

def model():
    my_value = pyro.sample("my_deterministic_value", NullScoreDistribution())

def guide():
    my_value = ... compute something ...
    pyro.sample("my_deterministic_value", dist.Delta(my_value))

:+1: As @martinjankowiak suggested, the idiomatic way to pass variables from guide to model is by sampling from a Delta distribution. I use this pattern often.

thanks I will give it a try