Skip to content

vllm.models.deepseek_v41.nvidia.specialized_decode.logits.lm_head

Low-batch LM head: FlashInfer's CuTe DSL mm_bf16 (split-K) for up to LM_HEAD_MAX_ROWS rows.

SpecializedDecodeLogitsProcessor projects through it, so a model that shares the head module but not the processor keeps the default GEMM. The runner computes logits outside the CUDA graph, and the GEMM has no cross-rank state, so the gate is the row count alone.

Functions:

_heads(model)

The LM heads of model that the GEMM takes.

Source code in vllm/models/deepseek_v41/nvidia/specialized_decode/logits/lm_head.py
def _heads(model: nn.Module) -> list[ParallelLMHead]:
    """The LM heads of ``model`` that the GEMM takes."""
    heads = []
    for head in model.modules():
        if not isinstance(head, ParallelLMHead):
            continue
        if low_batch_lm_head_applies(head, _zeros(head, 1)):
            heads.append(head)
        else:
            logger.warning_once(
                "The LM head keeps its default GEMM: it is not an unquantized "
                "BF16 head, or FlashInfer CuTe DSL mm_bf16 is unavailable."
            )
    return heads

autotune_low_batch_lm_head(model)

Tune each power-of-two row bucket inside FlashInfer's autotune context.

Source code in vllm/models/deepseek_v41/nvidia/specialized_decode/logits/lm_head.py
def autotune_low_batch_lm_head(model: nn.Module) -> None:
    """Tune each power-of-two row bucket inside FlashInfer's autotune context."""
    pdl = current_platform.is_arch_support_pdl()
    for head in _heads(model):
        for rows in (1 << i for i in range(LM_HEAD_MAX_ROWS.bit_length())):
            low_batch_lm_head(head, _zeros(head, rows), pdl)

low_batch_lm_head_applies(lm_head, x)

Whether low_batch_lm_head takes x: an unquantized BF16 head and 1 to LM_HEAD_MAX_ROWS rows.

Source code in vllm/models/deepseek_v41/nvidia/specialized_decode/logits/lm_head.py
def low_batch_lm_head_applies(lm_head: nn.Module, x: torch.Tensor) -> bool:
    """Whether ``low_batch_lm_head`` takes ``x``: an unquantized BF16 head
    and 1 to ``LM_HEAD_MAX_ROWS`` rows."""
    return (
        isinstance(lm_head, ParallelLMHead)
        and type(lm_head.quant_method) is UnquantizedEmbeddingMethod
        and x.dim() == 2
        and 0 < x.shape[0] <= LM_HEAD_MAX_ROWS
        and is_flashinfer_cutedsl_bf16_gemm_supported()
        and _can_use_flashinfer_cutedsl_bf16(x, lm_head.weight, None)
    )

warmup_low_batch_lm_head(model)

Compile the selected kernel for every row count (CuTe DSL compiles per M).

Source code in vllm/models/deepseek_v41/nvidia/specialized_decode/logits/lm_head.py
def warmup_low_batch_lm_head(model: nn.Module) -> None:
    """Compile the selected kernel for every row count (CuTe DSL compiles per
    M)."""
    pdl = current_platform.is_arch_support_pdl()
    for head in _heads(model):
        for rows in range(1, LM_HEAD_MAX_ROWS + 1):
            low_batch_lm_head(head, _zeros(head, rows), pdl)