Skip to content

vllm.models.deepseek_v41.amd.akr_config

Which DeepSeek-V4.1-Flash routes run amd_kernels (kernel_config.amd_kernels).

A route is on when amd_kernels imports on ROCm gfx950, the route is not in disabled_routes and its prerequisite routes are on. Per call, serves(route, m) also needs m inside the route's row range (GATES), where m is the static (captured, padded) token count of the call, so a captured shape takes one branch. A collective route (fused_ep8) passes dp_rows(m), the DP-group maximum, so that every rank takes the same branch. The amd_kernels op entries stay the authority on shapes: each call also asks the entry, and a declined call runs the stock kernel.

Functions:

  • dp_rows –

    The DP-group maximum token count of this step (m outside a forward

  • fail –

    Take route out for the rest of the process. Only called at load time,

  • indexer_bound –

    Longest row of an indexer layer in compressed entries.

  • indexer_rows_ok –

    Candidate consumers always run the kernel; dense layers with a long bound

  • on –

    Whether route is on in this process (any row count).

  • quant_activation –

    MXFP8 codes and row-major E8M0 scales as the activation stock linears take.

  • routes –

    The routes on in this process, read from the current vLLM config at the

  • serves –

    Whether route is on and m rows are inside its row range.

  • takes_mxfp8_codes –

    Whether a stock linear reads row-major MXFP8 codes and E8M0 scales as

dp_rows(m)

The DP-group maximum token count of this step (m outside a forward context or without DP).

Source code in vllm/models/deepseek_v41/amd/akr_config.py
def dp_rows(m: int) -> int:
    """The DP-group maximum token count of this step (`m` outside a forward
    context or without DP)."""
    from vllm.forward_context import get_forward_context, is_forward_context_available

    if is_forward_context_available():
        dp_metadata = get_forward_context().dp_metadata
        if dp_metadata is not None:
            return max(m, int(dp_metadata.num_tokens_across_dp_cpu.max()))
    return m

fail(route, reason)

Take route out for the rest of the process. Only called at load time, before CUDA graph capture fixes the branches.

Source code in vllm/models/deepseek_v41/amd/akr_config.py
def fail(route: str, reason: str) -> None:
    """Take `route` out for the rest of the process. Only called at load time,
    before CUDA graph capture fixes the branches."""
    if route not in _failed:
        _failed[route] = reason
        logger.warning("amd_kernels route %s disabled: %s", route, reason)

indexer_bound(max_model_len, compress_ratio, override=0)

Longest row of an indexer layer in compressed entries.

Source code in vllm/models/deepseek_v41/amd/akr_config.py
def indexer_bound(max_model_len: int, compress_ratio: int, override: int = 0) -> int:
    """Longest row of an indexer layer in compressed entries."""
    return override or -(-max_model_len // max(compress_ratio, 1))

indexer_rows_ok(bound, rows, candidate_consumer)

Candidate consumers always run the kernel; dense layers with a long bound only from INDEXER_LONG_MIN_ROWS decode rows.

Source code in vllm/models/deepseek_v41/amd/akr_config.py
def indexer_rows_ok(bound: int, rows: int, candidate_consumer: bool) -> bool:
    """Candidate consumers always run the kernel; dense layers with a long bound
    only from `INDEXER_LONG_MIN_ROWS` decode rows."""
    return (
        candidate_consumer
        or bound <= INDEXER_SHORT_ENTRIES
        or rows >= INDEXER_LONG_MIN_ROWS
    )

on(route)

Whether route is on in this process (any row count).

Source code in vllm/models/deepseek_v41/amd/akr_config.py
def on(route: str) -> bool:
    """Whether `route` is on in this process (any row count)."""
    return route in routes() and route not in _failed

quant_activation(codes, scale, orig_dtype)

MXFP8 codes and row-major E8M0 scales as the activation stock linears take.

Source code in vllm/models/deepseek_v41/amd/akr_config.py
def quant_activation(codes, scale, orig_dtype):
    """MXFP8 codes and row-major E8M0 scales as the activation stock linears take."""
    from vllm.model_executor.layers.fusion.quant_activation import QuantizedActivation
    from vllm.model_executor.layers.quantization.utils.quant_utils import kMxfp8Dynamic

    return QuantizedActivation(codes, scale, orig_dtype, codes.shape, kMxfp8Dynamic)

routes()

The routes on in this process, read from the current vLLM config at the first call under one (model build) and kept.

Source code in vllm/models/deepseek_v41/amd/akr_config.py
def routes() -> frozenset[str]:
    """The routes on in this process, read from the current vLLM config at the
    first call under one (model build) and kept."""
    global _routes
    if _routes is not None:
        return _routes
    from vllm.config import get_current_vllm_config_or_none

    cfg = get_current_vllm_config_or_none()
    akr = None if cfg is None else cfg.kernel_config.amd_kernels
    result = resolve_routes(
        akr is None or akr.enabled,
        set(() if akr is None else akr.disabled_routes),
        _available(),
    )
    if cfg is not None:
        _routes = result
        logger.info(
            "amd_kernels routes: %s",
            ", ".join(r for r in ROUTES if r in result) or "none",
        )
    return result

serves(route, m)

Whether route is on and m rows are inside its row range.

Source code in vllm/models/deepseek_v41/amd/akr_config.py
def serves(route: str, m: int) -> bool:
    """Whether `route` is on and `m` rows are inside its row range."""
    return on(route) and GATES[route](m)

takes_mxfp8_codes(linear)

Whether a stock linear reads row-major MXFP8 codes and E8M0 scales as they are (FlashInfer kernels use the same key with swizzled scales).

Source code in vllm/models/deepseek_v41/amd/akr_config.py
def takes_mxfp8_codes(linear) -> bool:
    """Whether a stock linear reads row-major MXFP8 codes and E8M0 scales as
    they are (FlashInfer kernels use the same key with swizzled scales)."""
    from vllm.model_executor.kernels.linear.mxfp8.aiter_flydsl import (
        AiterFlyDSLMxfp8LinearKernel,
    )
    from vllm.model_executor.kernels.linear.mxfp8.rocm_native import (
        RocmDotScaledMxfp8LinearKernel,
    )
    from vllm.model_executor.layers.fusion.quant_activation import get_input_quant_key
    from vllm.model_executor.layers.quantization.utils.quant_utils import kMxfp8Dynamic

    kernel = getattr(linear.quant_method, "kernel", None)
    supports = getattr(kernel, "supports_quantized_input", None)
    return (
        get_input_quant_key(linear) == kMxfp8Dynamic
        and isinstance(
            kernel, (RocmDotScaledMxfp8LinearKernel, AiterFlyDSLMxfp8LinearKernel)
        )
        and (supports is None or bool(supports(linear)))
    )