def reduce_sum_over_lc(x, x_mask):
  """Returns sum of x (over L and C) given the actual length and pad.

  Args:
    x: input. (B,L,C)
    x_mask: binary padding mask. (B,L)

  Returns:
    sum of x. (B)
  """

  if x.shape.rank == 3 and x_mask.shape.rank == 2:
    x_mask = x_mask[..., tf.newaxis]
  else:
    tf.logging.info("x: {}, x_mask: {}".format(x.shape.rank, x_mask.shape.rank))
    raise ValueError("Dimension not supported.")

  mean = x * x_mask
  return tf.reduce_sum(mean, axis=[1, 2])  # sum over L, C
Returns sum of x (over L and C) given the actual length and pad.

  Args:
    x: input. (B,L,C)
    x_mask: binary padding mask. (B,L)

  Returns:
    sum of x. (B)
  
tensor2tensor/layers/transformer_glow_layers_ops.py