import torch


def split_last_dimension(x,n):
    """Reshape x so that the last dimension becomes two dimensions.
    The first of these two dimensions is n.
    Args:
        x: a Tensor with shape [..., m]
        n: an integer.
    Returns:
        a Tensor with shape [..., n, m/n]
    """
    

    chunk_size = int(x.shape[4]/ n)
    ret = torch.unsqueeze(x,5)
    
    ret = torch.cat(ret.split(split_size=chunk_size, dim=4),5)#.permute(0,1,2,4,3)
#    print('split', ret.shape)
#     ret.view(new_shape)
#     print('split view ', ret.shape)
    return ret