class_docstr: Variational Auto Encoder with Inverse Autoregressive Flows
  (:class:`~pythae.models.normalizing_flows.IAF`).
  
  Args:
      model_config(VAE_IAF_Config): The Variational Autoencoder configuration seting the main
          parameters of the model.
  
      encoder (BaseEncoder): An instance of BaseEncoder (inheriting from `torch.nn.Module` which
          plays the role of encoder. This argument allows you to use your own neural networks
          architectures if desired. If None is provided, a simple Multi Layer Preception
          (https://en.wikipedia.org/wiki/Multilayer_perceptron) is used. Default: None.
  
      decoder (BaseDecoder): An instance of BaseDecoder (inheriting from `torch.nn.Module` which
          plays the role of decoder. This argument allows you to use your own neural networks
          architectures if desired. If None is provided, a simple Multi Layer Preception
          (https://en.wikipedia.org/wiki/Multilayer_perceptron) is used. Default: None.
  
  .. note::
      For high dimensional data we advice you to provide you own network architectures. With the
      provided MLP you may end up with a ``MemoryError``.
class_docstr_tok: ["Variational","Auto","Encoder","with","Inverse","Autoregressive","Flows","(",":","class",":","`","~pythae.models.normalizing_flows.IAF","`",")",".","Args",":","model_config","(","VAE_IAF_Config",")",":","The","Variational","Autoencoder","configuration","seting","the","main","parameters","of","the","model",".","encoder","(","BaseEncoder",")",":","An","instance","of","BaseEncoder","(","inheriting","from","`","torch.nn.Module","`","which","plays","the","role","of","encoder",".","This","argument","allows","you","to","use","your","own","neural","networks","architectures","if","desired",".","If","None","is","provided",",","a","simple","Multi","Layer","Preception","(","https",":","\/\/en.wikipedia.org\/wiki\/Multilayer_perceptron",")","is","used",".","Default",":","None",".","decoder","(","BaseDecoder",")",":","An","instance","of","BaseDecoder","(","inheriting","from","`","torch.nn.Module","`","which","plays","the","role","of","decoder",".","This","argument","allows","you","to","use","your","own","neural","networks","architectures","if","desired",".","If","None","is","provided",",","a","simple","Multi","Layer","Preception","(","https",":","\/\/en.wikipedia.org\/wiki\/Multilayer_perceptron",")","is","used",".","Default",":","None",".","..","note",":",":","For","high","dimensional","data","we","advice","you","to","provide","you","own","network","architectures",".","With","the","provided","MLP","you","may","end","up","with","a","``","MemoryError","``","."]
code: def loss_function(
      self, recon_x, x, mu, log_var, z0, zk, log_abs_det_jac
  ):
      if self.model_config.reconstruction_loss == "mse":
          recon_loss = 0.5 * F.mse_loss(
              recon_x.reshape(x.shape[0], -1),
              x.reshape(x.shape[0], -1),
              reduction="none",
          ).sum(dim=-1)
  
      elif self.model_config.reconstruction_loss == "bce":
          recon_loss = F.binary_cross_entropy(
              recon_x.reshape(x.shape[0], -1),
              x.reshape(x.shape[0], -1),
              reduction="none",
          ).sum(dim=-1)
  
      # starting gaussian log-density
      log_prob_z0 = (
          -0.5 * (log_var + torch.pow(z0 - mu, 2) / torch.exp(log_var))
      ).sum(dim=1)
  
      # prior log-density
      log_prob_zk = (-0.5 * torch.pow(zk, 2)).sum(dim=1)
  
      KLD = log_prob_z0 - log_prob_zk - log_abs_det_jac
  
      return (
          (recon_loss + KLD).mean(dim=0),
          recon_loss.mean(dim=0),
          KLD.mean(dim=0),
      )
  
file_path: benchmark_VAE/src/pythae/models/vae_iaf/vae_iaf_model.py
imports: import os
  from typing import Optional
  import numpy
  import torch
  import torch.nn.functional
  from ...data.datasets import BaseDataset
  from ..base.base_utils import ModelOutput
  from ..nn import BaseDecoder, BaseEncoder
  from ..normalizing_flows import IAF, IAFConfig
  from ..vae import VAE
  from .vae_iaf_config import VAE_IAF_Config
label_desc: Use image node_id 3 for calling the VAE_IAF obj's underlying member method code with example usage: obj.loss_function(recon_x, x, mu, log_var, z0, zk, log_abs_det_jac) and returns: unknown,  recon_loss,  KLD