sgl-project/sglang · error · ValueError

MXFP8 fused decode prologue requires interleaved K/V scale b

Error message

MXFP8 fused decode prologue requires interleaved K/V scale buffers with shape {sf_shape}, got {tuple(sfk.shape)} and {tuple(sfv.shape)}.

What it means

The decode prologue enforces the exact interleaved MXFP8 scale-buffer layout: sf_shape = (k_buf.shape[0]//page_size, dkv//128, 32, page_size//32, 4). Both sfk.shape and sfv.shape are compared against it and the message prints expected vs actual tuples. A mismatch means the scale buffers were sized under different assumptions (page_size, dkv, or cache capacity) than the current call.

Source

Thrown at python/sglang/kernels/ops/attention/inkling_attn_prologue.py:330

    page_size: int = 128,
    log_scaling_tau: torch.Tensor | None = None,
) -> tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor | None]:
    """Decode {k/v decode-conv + conv-cache shift-update (+track) + qk-norm
    (+ KV store)} in one kernel. Returns fresh (q_normed, k_normed, v_conv).
    The k/v conv caches are shift-updated in place (fused_decode_update
    semantics). With ``do_store`` the KV rows are scattered into k_buf/v_buf at
    ``loc``; MXFP8 mode also quantizes Q and writes interleaved K/V scales."""
    t = qkvr.shape[0]
    if mxfp8_quant:
        if dq % 128 != 0 or dkv % 128 != 0:
            raise ValueError(
                "MXFP8 fused decode prologue requires head_dim-aligned Q/K/V."
            )
        if sfk is None or sfv is None:
            raise ValueError("MXFP8 fused decode prologue requires K/V scale buffers.")
        sf_shape = (k_buf.shape[0] // page_size, dkv // 128, 32, page_size // 32, 4)
        if sfk.shape != sf_shape or sfv.shape != sf_shape:
            raise ValueError(
                "MXFP8 fused decode prologue requires interleaved K/V scale buffers "
                f"with shape {sf_shape}, got {tuple(sfk.shape)} and {tuple(sfv.shape)}."
            )
        if not sfk.is_contiguous() or not sfv.is_contiguous():
            raise ValueError(
                "MXFP8 fused decode prologue requires contiguous interleaved SFK/SFV."
            )
        q_out = torch.empty(t, dq, dtype=torch.float8_e4m3fn, device=qkvr.device)
        sfq_u8 = torch.empty(
            (t, dq // 128, 128 // 32), dtype=torch.uint8, device=qkvr.device
        )
        sfk_u8 = sfk.view(torch.uint8)
        sfv_u8 = sfv.view(torch.uint8)
    else:
        q_out = torch.empty(t, dq, dtype=qkvr.dtype, device=qkvr.device)
        sfq_u8 = torch.empty(0, dtype=torch.uint8, device=qkvr.device)
        sfk_u8 = torch.empty(0, dtype=torch.uint8, device=qkvr.device)
        sfv_u8 = torch.empty(0, dtype=torch.uint8, device=qkvr.device)

View on GitHub (pinned to 0132848349)

Solutions

  1. Reallocate sfk/sfv to exactly (k_buf.shape[0]//page_size, dkv//128, 32, page_size//32, 4)
  2. Validate shapes against k_buf/page_size at pool-get time
  3. Derive the shape programmatically instead of hardcoding

Example fix

# before
sfk = torch.empty(num_pages, dkv//128, 32, 4, dtype=torch.uint8, device='cuda')
# after
sfk = torch.empty(k_buf.shape[0]//page_size, dkv//128, 32, page_size//32, 4, dtype=torch.uint8, device=k_buf.device)
Defensive patterns

Strategy: validation

Validate before calling

expected = (k_buf.shape[0] // page_size, dkv // 128, 32, page_size // 32, 4)
if mxfp8_quant:\n    assert sfk.shape == expected and sfv.shape == expected, (sfk.shape, sfv.shape, expected)

Prevention

When it happens

Trigger: Calling inkling_attn_prologue_decode with mxfp8_quant=True where sfk/sfv shapes differ from the formula — e.g. buffers allocated for a different page_size or dkv, or a cache resized after allocation.

Common situations: Changing --page-size or resizing the KV cache between allocation and decode; per-layer dkv differences sharing one scale allocation; version layout changes.

Related errors


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