Skip to content

vllm.models.deepseek_v41.amd.akr_indexer

Route indexer: the decode rows of DeepSeek-V4.1's MXFP4 top-512 indexer on amd_kernels.

One entry scores the paged MXFP4 keys, selects the top 512 and writes the sparse attention's ragged slot lists itself, which this layer then publishes as its _topk_ragged_cache (the stock packer is skipped). The dense layers score the whole context (the candidate source also writes its candidate blocks); the candidate consumers score only the source's candidates. Prefill rows of the same step stay on the stock op (skip_decode).

A layer stays stock when its longest row, max_model_len / compress_ratio compressed entries (or indexer_max_ctx), exceeds the kernel's limit. Per step: no uniform decode length, sharded decode rows or a row count outside the gate run the stock op.

Functions:

  • dispatch –

    Run this step's decode rows on the kernel where it serves. Returns

_is_valid_i32(swa_metadata, rows)

One int32 copy of the step's valid-token mask, shared by the layers.

Source code in vllm/models/deepseek_v41/amd/akr_indexer.py
def _is_valid_i32(swa_metadata, rows: int) -> torch.Tensor:
    """One int32 copy of the step's valid-token mask, shared by the layers."""
    held = get_forward_context().additional_kwargs
    key = f"akr_is_valid_i32_{rows}"
    valid = held.get(key)
    if valid is None:
        valid = swa_metadata.is_valid_token[:rows].to(torch.int32)
        held[key] = valid
    return valid

dispatch(layer, index_q, index_q_scale, index_weights)

Run this step's decode rows on the kernel where it serves. Returns whether the stock indexer op still has rows to do.

Source code in vllm/models/deepseek_v41/amd/akr_indexer.py
def dispatch(layer, index_q, index_q_scale, index_weights) -> bool:
    """Run this step's decode rows on the kernel where it serves. Returns
    whether the stock indexer op still has rows to do."""
    st = layer.akr.indexer
    if st is None:
        return True
    op = layer.indexer.indexer_op
    op.skip_decode = False
    if index_q_scale is None or not _run_decode(
        layer, st, index_q, index_q_scale, index_weights
    ):
        return True
    op.skip_decode = True
    md: Any = get_forward_context().attn_metadata
    return md[layer.indexer.k_cache.prefix].prefill is not None