sgl-project/sglang · error · ImportError

The 'flashkda' KDA prefill backend requires the flash_kda mo

Error message

The 'flashkda' KDA prefill backend requires the flash_kda module, which is not installed. Install it from source:\n    pip install git+https://github.com/MoonshotAI/FlashKDA.git

What it means

The optional flash_kda CUTLASS module (MoonshotAI FlashKDA) is not installed; the 'flashkda' KDA prefill backend lazily imports it on first use and raises ImportError with install instructions.

Source

Thrown at python/sglang/srt/layers/attention/linear/kernels/kda_flashkda.py:22

from sglang.srt.layers.attention.linear.kernels.kernel_backend import (
    LinearAttnKernelBase,
)

# FlashKDA chunk size. Sequences shorter than this fall back to Triton.
_FLASHKDA_CHUNK_SIZE = 64

# FlashKDA's max sequence length, Batches whose longest sequence exceeds this
# fall back to Triton for the whole batch.
_FLASHKDA_MAX_SEQ_LEN = 2048


def _load_flash_kda():
    """Import the optional ``flash_kda`` CUTLASS module."""
    try:
        import flash_kda
    except ImportError as e:
        raise ImportError(
            "The 'flashkda' KDA prefill backend requires the flash_kda module, "
            "which is not installed. Install it from source:\n"
            "    pip install git+https://github.com/MoonshotAI/FlashKDA.git"
        ) from e
    return flash_kda


def _triton_fallback(
    q,
    k,
    v,
    g,
    beta,
    ssm_states,
    cache_indices,
    query_start_loc,
    A_log=None,
    dt_bias=None,

View on GitHub (pinned to 0132848349)

Solutions

  1. pip install git+https://github.com/MoonshotAI/FlashKDA.git
  2. Fall back to triton or cutedsl prefill backend if you cannot build the CUTLASS extension
  3. Ensure CUDA toolchain matches the build requirements of FlashKDA

Example fix

# before
# flash_kda missing
# after
pip install git+https://github.com/MoonshotAI/FlashKDA.git
Defensive patterns

Strategy: try-catch

Validate before calling

try:
    import flash_kda  # noqa
    flashkda_ok = True
except ImportError:
    flashkda_ok = False
if not flashkda_ok:
    linear_attn_prefill_backend = 'triton'

Type guard

null

Try / catch

try:
    _load_flash_kda()
except ImportError as e:
    logger.warning('flashkda unavailable (%s); using triton prefill', e)
    use_flashkda = False

Prevention

When it happens

Trigger: Selecting the flashkda KDA prefill backend without having installed the flash_kda package (it is not part of standard sglang dependencies).

Common situations: Fresh environment or Docker image that omits the source-only flash_kda dependency; new deployment enabling --linear-attn-backend flashkda.

Related errors


AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28). Data as JSON: /api/errors/6a055a35febf711e. Report an issue: GitHub.