def squeeze(name, x, factor, inverse):
  """Temporal squeezing of x to increase the number of channels."""
  with tf.variable_scope(name, reuse=tf.AUTO_REUSE):
    if factor == 1:
      return x
    batch_size, length, n_channels = common_layers.shape_list(x)
    if not inverse:
      x = tf.reshape(x, [batch_size, length//factor, factor, n_channels])
      # transposing groups neighbouring elements together.
      x = tf.transpose(x, [0, 1, 3, 2])
      x = tf.reshape(x, [batch_size, length//factor, n_channels*factor])
    else:
      x = tf.reshape(x, (batch_size, length, n_channels//factor, factor))
      x = tf.transpose(x, [0, 1, 3, 2])
      x = tf.reshape(x, (batch_size, length*factor, n_channels//factor))
    return x
Temporal squeezing of x to increase the number of channels.
tensor2tensor/layers/transformer_glow_layers.py