def smart_transpose(a: tf.Tensor, perm=List[int]) -> tf.Tensor:
    """Extension of tf.transpose.
    Parameter perm may be shorter list than rank on input tensor a.
    This case all dimensions that are beyond the list perm remain unchanged.

    For example:
        smart_transpose(tf.zeros(shape=[2, 3, 4, 5, 6]), [2, 1, 0]).shape
        # -> [4, 3, 2, 5, 6]

    Args:
        a:      tf.Tensor of any rank shape and type
        perm:   list of integers like for tf.transpose but in may be shorter than the shape of a.

    Returns:    tf.Tensor of the same type and rank as th input tensor a.
    """
    if len(perm) > len(a.shape):
        raise ValueError(f"Tensor with shape '{a.shape}' cannot be reshaped to '{perm}'")

    perm_rest = list(range(len(perm), len(a.shape)))

    return tf.transpose(a=a, perm=perm + perm_rest)
Extension of tf.transpose.
    Parameter perm may be shorter list than rank on input tensor a.
    This case all dimensions that are beyond the list perm remain unchanged.

    For example:
        smart_transpose(tf.zeros(shape=[2, 3, 4, 5, 6]), [2, 1, 0]).shape
        # -> [4, 3, 2, 5, 6]

    Args:
        a:      tf.Tensor of any rank shape and type
        perm:   list of integers like for tf.transpose but in may be shorter than the shape of a.

    Returns:    tf.Tensor of the same type and rank as th input tensor a.
    
tensorflow_asr/losses/impl/ctc_tpu.py