code: def glow(
      name,
      x,
      max_x_mask,
      max_self_attn_bias,
      inverse,
      init,
      dtype=tf.float32,
      split_zs=None,
      temp=1.0,
      **kwargs,
  ):
      """Multi-scale glow model. Flow + (n_levels-1)*(Split + Squeeze + Flow).
  
      Note the original glow's ordering is Squeeze + Flow + Split.
  
      Args:
        name: variable scope.
        x: 3-D Tensor, shape=[B, L, C]. The length dimension is padded to the
          closest multiple of factor**n_levels.
        max_x_mask : 2-D Tensor, shape=[B, L]. Binary mask indicating padding.
        max_self_attn_bias : 4-D Tensor, shape=[B, 1, 1, L].
        inverse: forward or inverse pass.
        init: init.
        dtype: dtype.
        split_zs: intermediate latents modelled as a standard normal.
        temp: Only used in inverse. Temperature for sampling.
        **kwargs: additional arguments. Contains hparams, disable_dropout,
          encoder_output and encoder_decoder_attention_bias.
  
      Returns:
        x: if forward, data transformed to the base distribution.
          if inverse, base transformed to the data (latent) distribution.
        logabsdets: log absolute determinant Jacobian. [B]
        log_ps: log probability in the base distribution. [B]
        split_zs: all intermediate latents (only used to check invertibility.)
      """
      assert x.shape.rank == 3
      hparams = kwargs["hparams"]
      factor = hparams.factor
      if hparams.depths:
          depths = [
              int(depth_str) for depth_str in hparams.depths.split("/")
          ]
      else:
          depths = []
      split_plans = hparams.split_plans.split("/")
      n_levels = len(depths)
      logabsdets = tf.constant(0.0, dtype=dtype)
      log_ps = tf.constant(0.0, dtype=dtype)
      with tf.variable_scope(
          name, use_resource=True, reuse=tf.AUTO_REUSE
      ):
          if not inverse:  # z -> e (density estimation)
              x_mask, self_attn_bias = max_x_mask, max_self_attn_bias
              split_zs = []
              for level in range(n_levels):
                  if level > 0:
                      x, z, log_p_z = split(
                          "{}_split".format(level),
                          x,
                          x_mask,
                          inverse,
                          dtype,
                      )
                      log_ps += log_p_z
                      split_zs.append(z)
  
                      x = squeeze(
                          "{}_squeeze".format(level), x, factor, inverse
                      )
                      x_mask = max_x_mask[:, :: factor**level]
                      self_attn_bias = max_self_attn_bias[
                          ..., :: factor**level
                      ]
  
                  prior = level < n_levels - 1
                  x, logabsdet = flow_level(
                      "{}_level".format(level),
                      x,
                      x_mask,
                      depths[level],
                      split_plans[level],
                      prior,
                      inverse,
                      init,
                      dtype,
                      decoder_self_attention_bias=self_attn_bias,
                      **kwargs,
                  )
                  logabsdets += logabsdet  # (B)
  
              log_p_base = gops.standard_normal_density(x, x_mask)
              log_ps += log_p_base
              return x, logabsdets, log_ps, split_zs
  
          else:  # e -> z (sampling)
              x_mask = max_x_mask[:, :: factor ** (n_levels - 1)]
              log_p_base = gops.standard_normal_density(x, x_mask)
              log_ps += log_p_base
              if split_zs is None:
                  split_zs = [None] * (n_levels - 1)
  
              for level in reversed(range(n_levels)):
                  x_mask = max_x_mask[:, :: factor**level]
                  self_attn_bias = max_self_attn_bias[
                      ..., :: factor**level
                  ]
                  prior = level < n_levels - 1
                  x, logabsdet = flow_level(
                      "{}_level".format(level),
                      x,
                      x_mask,
                      depths[level],
                      split_plans[level],
                      prior,
                      inverse,
                      init,
                      dtype,
                      decoder_self_attention_bias=self_attn_bias,
                      **kwargs,
                  )
                  logabsdets += logabsdet
  
                  if level > 0:
                      x = squeeze(
                          "{}_squeeze".format(level), x, factor, inverse
                      )
                      x_mask = max_x_mask[:, :: factor ** (level - 1)]
                      x, _, log_p_z = split(
                          "{}_split".format(level),
                          x,
                          x_mask,
                          inverse,
                          temp=temp,
                          dtype=dtype,
                          z=split_zs[level - 1],
                      )
                      log_ps += log_p_z
  
              return x, logabsdets, log_ps, None
  
file_path: tensor2tensor/tensor2tensor/layers/transformer_glow_layers.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import functools
  import numpy
  import scipy
  from tensor2tensor.layers import common_layers
  import tensor2tensor.layers.transformer_glow_layers_ops
  import tensorflow.compat.v1
label_desc: Use image node_id 10 for calling a global function with example usage: glow(name, x, max_x_mask, max__attn_bias, inverse, init, dtype, split_zs, temp) and returns: x,  logabsdets,  log_ps,  split_zs, x,  logabsdets,  log_ps,  None