def _same_shape(tensor_list, start=0, end=-1):
    """Return whether tensors have same (sub-)shapes.

    Args:
        tensor_list ([torch.Tensor]): List of tensors whose shapes are compared.
        start (int, optional): The dimension to start comparing shapes.
        end (int, optional): The dimension until (including) shapes are compared.

    Raises:
        ValueError: If the tensors don't have identical (sub-)shapes.
    """

    def _slice(shape):
        """Get relevant parts of the shape for comparison.

        Args:
            shape (torch.Size): Shape of a ``torch.Tensor``.

        Returns:
            torch.Size: Relevant sub-shape.
        """
        return shape[start:] if end == -1 else shape[start : end + 1]

    unique = {_slice(tensor.shape) for tensor in tensor_list}

    if len(unique) != 1:
        raise ValueError(
            f"Got non-unique shapes comparing dims {start} to including {end}: {unique}"
        )