Skip to content

vllm.models.hy_v4_flash.nvidia.indexpool_prepare

Read committed carry before retaining new speculative IndexPool keys.

Functions:

  • prepare_groups –

    Gather the groups to pool and the per-query scoring metadata.

prepare_groups(keys, positions, tail, table, pool_table, starts, lengths, tokens, ratio)

Gather the groups to pool and the per-query scoring metadata.

Raw group keys come back in FP32 for the key projections, and pool_table rows are gathered per query so paged MQA scoring can read them directly.

Source code in vllm/models/hy_v4_flash/nvidia/indexpool_prepare.py
def prepare_groups(
    keys, positions, tail, table, pool_table, starts, lengths, tokens, ratio
):
    """Gather the groups to pool and the per-query scoring metadata.

    Raw group keys come back in FP32 for the key projections, and
    `pool_table` rows are gathered per query so paged MQA scoring can read
    them directly.
    """
    batch, device = lengths.numel(), keys.device
    slots = (tokens + batch * (ratio - 1)) // ratio
    prefix = torch.empty(batch, dtype=torch.int32, device=device)
    raw = torch.empty((slots, ratio, 128), dtype=torch.float32, device=device)
    coordinates = torch.empty((3, slots), dtype=torch.int64, device=device)
    requests = torch.empty(slots, dtype=torch.int32, device=device)
    groups = torch.empty(slots, dtype=torch.int64, device=device)
    group_live = torch.empty(slots, dtype=torch.bool, device=device)
    owner = torch.empty(tokens, dtype=torch.int32, device=device)
    logical = torch.empty(tokens, dtype=torch.int64, device=device)
    upper = torch.empty(tokens, dtype=torch.int32, device=device)
    score_lengths = torch.empty((tokens, 1), dtype=torch.int32, device=device)
    token_table = torch.empty(
        (tokens, pool_table.shape[1]), dtype=pool_table.dtype, device=device
    )
    token_live = torch.empty(tokens, dtype=torch.bool, device=device)
    if batch:
        _group_prefix[(1,)](
            starts, lengths, prefix, batch, ratio, triton.next_power_of_2(batch)
        )
    if slots:
        _gather_groups[(slots,)](
            keys,
            positions,
            tail,
            table,
            starts,
            lengths,
            prefix,
            raw,
            coordinates,
            requests,
            groups,
            group_live,
            batch,
            tokens,
            slots,
            ratio,
            tail.shape[1],
            keys.stride(0),
            keys.stride(1),
            positions.stride(0) if positions.ndim == 2 else 0,
            positions.stride(-1),
            positions.ndim == 2,
            tail.stride(0),
            tail.stride(1),
            table.stride(0),
        )
    if tokens:
        assert pool_table.stride(1) == 1
        _query_metadata[(triton.cdiv(tokens, 64),)](
            starts,
            lengths,
            pool_table,
            owner,
            logical,
            upper,
            score_lengths,
            token_table,
            token_live,
            batch,
            tokens,
            pool_table.stride(0),
            pool_table.shape[1],
            (batch + 1).bit_length(),
            ratio,
            64,
            64,
        )
    group_positions = coordinates if positions.ndim == 2 else coordinates[0]
    return (
        raw,
        group_positions,
        requests,
        groups,
        group_live,
        owner,
        logical,
        upper,
        score_lengths,
        token_table,
        token_live,
    )