def sum_right_most(x, ndim):
    """Sum along the right most `ndim` dimensions of `x`,

    Parameters
    ----------
    x : Tensor
        Input tensor.
    ndim : Int
        Number of dimensions to be summed.

    Returns
    -------
    Tensor
    """
    if ndim == 0:
        return x
    axes = list(range(-ndim, 0))
    return x.sum(axes)