code: def maybe_flatten4d3d(x):
      """Flatten if tensor has 4 dimensions.
  
      Pass through otherwise.
  
      This is useful since additional dimensions are sometimes removed on the TPU,
      see e.g.
        https://github.com/tensorflow/tensor2tensor/tree/master/tensor2tensor/models/transformer.py?l=159&rcl=279807999
  
      Args:
        x: a tensor
  
      Returns:
        A 3D tensor if x is 4D, unmodified x otherwise.
      """
      xshape = common_layers.shape_list(x)
      return common_layers.flatten4d3d(x) if len(xshape) == 4 else x
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import logging
  from tensor2tensor.layers import common_attention
  from tensor2tensor.layers import common_layers
  from tensor2tensor.layers import transformer_layers
  from tensor2tensor.models import transformer
  from tensor2tensor.utils import registry
  from tensor2tensor.utils import t2t_model
  import tensorflow.compat.v1
label_desc: Use image node_id 1 for calling a global function with example usage: maybe_flatten4d3d(x) and returns: unknown