def squash_dims(tensor, dims):
    """
    Squashes dimension, given in dims into one, which equals to product of given.

    Args:
        tensor (Tensor): input tensor
        dims: dimensions over which tensor should be squashed

    """
    assert len(dims) >= 2, "Expected two or more dims to be squashed"

    size = tensor.size()

    squashed_dim = size[dims[0]]
    for i in range(1, len(dims)):
        assert dims[i] == dims[i - 1] + 1, "Squashed dims should be consecutive"
        squashed_dim *= size[dims[i]]

    result_dims = size[:dims[0]] + (squashed_dim,) + size[dims[-1] + 1:]
    return tensor.contiguous().view(*result_dims)