def devectorize(current_tensor, pad, target_size, cluster_dim, vector_ch_axis=0) -> _torch.Tensor:
    """
    Function to devectorize by tracing back the vectorize operation in the method above.

    vector_ch_axis 0
    target_size [x_1, x_2, ..., x_N]
    tensor with shape [x_1*x_2* ... *x_N/cluster_dim, cluster_dim] --> [x_N, x_2, x_3, ..., x_(N-1), x_1] --> [x_1, x_2, x_3, ..., x_N]

    vector_ch_axis 1
    target_size [x_1, x_2, ..., x_N]
    tensor with shape [x_1*x_2* ... *x_N/cluster_dim, cluster_dim] --> [x_1, x_N, x_3, ..., x_(N-1), x_2] --> [x_1, x_2, x_3, ..., x_N]
    """
    if pad is not None:
        current_tensor = _torch.cat([current_tensor.flatten(), pad])

    if cluster_dim > 1:
        if vector_ch_axis == 0:
            current_tensor = current_tensor.reshape(
                target_size[-1:] + target_size[1:-1] + target_size[0:1]
            ).transpose(0, -1)
        else:
            current_tensor = current_tensor.reshape(
                target_size[0:1] + target_size[-1:] + target_size[2:-1] + target_size[1:2]
            ).transpose(1, -1)

        return current_tensor

    return current_tensor.reshape(target_size)

    Function to devectorize by tracing back the vectorize operation in the method above.

    vector_ch_axis 0
    target_size [x_1, x_2, ..., x_N]
    tensor with shape [x_1*x_2* ... *x_N/cluster_dim, cluster_dim] --> [x_N, x_2, x_3, ..., x_(N-1), x_1] --> [x_1, x_2, x_3, ..., x_N]

    vector_ch_axis 1
    target_size [x_1, x_2, ..., x_N]
    tensor with shape [x_1*x_2* ... *x_N/cluster_dim, cluster_dim] --> [x_1, x_N, x_3, ..., x_(N-1), x_2] --> [x_1, x_2, x_3, ..., x_N]
    
coremltools/optimize/torch/palettization/_utils.py