How to get samples from custom guide after training


When using AutoGuides, the method sample_posterior is really convenient to get samples after inference.
Is there an easy way to do the same for custom guides?

I was looking for something like the following.

def model(data): ...
def guide(data): ...

svi = SVI(model, guide, optimizer, loss=Trace_ELBO())
svi_result =, 20000, data)
sample_posterior(guide, rng_key, svi_result.params, sample_shape=(100,))

Is that already possible?

@gbdrt You can use Predictive like

predictive = Predictive(guide, params=svi_result.params, num_samples=100)
samples = predictive(rng_key, data)

Thanks a lot!
I did tried Get multiple posterior samples using guide, but I was missing the params argument.