How to get an inverse autoregressive flow? #72
-
DescriptionIn the documentation, the VAE example uses an autoregressive prior rather than an autoregressive posterior conditioned on the input, which is great but a bit unusual. I wanted to try out autoregressive posteriors (e.g., IAF) but couldn't figure out how to do it in zuko. ImplementationPaper: Improving Variational Inference with Inverse Autoregressive Flow by Kingma et al. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
|
Hi @zhihanyang2022 👋 An IAF is the same as a MAF, but with reversed transformations, such that sampling is fast and log-prob is slow. In Zuko, you can transform any flow to an inverse flow with the following pattern: maf = zuko.flows.MAF(features=2, transforms=3, hidden_features=(64, 64)) # or NSF, NAF, ...
iaf = zuko.flows.Flow(flow.transform.inv, flow.base)We use this pattern in the "train from energy" tutorial. https://zuko.readthedocs.io/stable/tutorials/reverse_kl.html Please note that to optimize through the sampling, you need to call |
Beta Was this translation helpful? Give feedback.
-
|
Thanks! Also, for MAF, is mixture of Gaussians (MoG) output distribution available in Zuko? If not, do you see Zuko supporting this feature in the near future? I'm also happy to contribute but might need some pointers to get started. |
Beta Was this translation helpful? Give feedback.
Hi @zhihanyang2022 👋
An IAF is the same as a MAF, but with reversed transformations, such that sampling is fast and log-prob is slow. In Zuko, you can transform any flow to an inverse flow with the following pattern:
We use this pattern in the "train from energy" tutorial.
https://zuko.readthedocs.io/stable/tutorials/reverse_kl.html
Please note that to optimize through the sampling, you need to call
rsample(orrsample_and_log_prob) instead ofsample.