{"record":{"id":"423125772347fb99","repo":"sgl-project/sglang","slug":"mxfp8-fused-decode-prologue-requires-interleaved-k","errorCode":null,"errorMessage":"MXFP8 fused decode prologue requires interleaved K/V scale buffers with shape {sf_shape}, got {tuple(sfk.shape)} and {tuple(sfv.shape)}.","messagePattern":"MXFP8 fused decode prologue requires interleaved K/V scale buffers with shape (.+?), got (.+?) and (.+?)\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/kernels/ops/attention/inkling_attn_prologue.py","lineNumber":330,"sourceCode":"    page_size: int = 128,\n    log_scaling_tau: torch.Tensor | None = None,\n) -> tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor | None]:\n    \"\"\"Decode {k/v decode-conv + conv-cache shift-update (+track) + qk-norm\n    (+ KV store)} in one kernel. Returns fresh (q_normed, k_normed, v_conv).\n    The k/v conv caches are shift-updated in place (fused_decode_update\n    semantics). With ``do_store`` the KV rows are scattered into k_buf/v_buf at\n    ``loc``; MXFP8 mode also quantizes Q and writes interleaved K/V scales.\"\"\"\n    t = qkvr.shape[0]\n    if mxfp8_quant:\n        if dq % 128 != 0 or dkv % 128 != 0:\n            raise ValueError(\n                \"MXFP8 fused decode prologue requires head_dim-aligned Q/K/V.\"\n            )\n        if sfk is None or sfv is None:\n            raise ValueError(\"MXFP8 fused decode prologue requires K/V scale buffers.\")\n        sf_shape = (k_buf.shape[0] // page_size, dkv // 128, 32, page_size // 32, 4)\n        if sfk.shape != sf_shape or sfv.shape != sf_shape:\n            raise ValueError(\n                \"MXFP8 fused decode prologue requires interleaved K/V scale buffers \"\n                f\"with shape {sf_shape}, got {tuple(sfk.shape)} and {tuple(sfv.shape)}.\"\n            )\n        if not sfk.is_contiguous() or not sfv.is_contiguous():\n            raise ValueError(\n                \"MXFP8 fused decode prologue requires contiguous interleaved SFK/SFV.\"\n            )\n        q_out = torch.empty(t, dq, dtype=torch.float8_e4m3fn, device=qkvr.device)\n        sfq_u8 = torch.empty(\n            (t, dq // 128, 128 // 32), dtype=torch.uint8, device=qkvr.device\n        )\n        sfk_u8 = sfk.view(torch.uint8)\n        sfv_u8 = sfv.view(torch.uint8)\n    else:\n        q_out = torch.empty(t, dq, dtype=qkvr.dtype, device=qkvr.device)\n        sfq_u8 = torch.empty(0, dtype=torch.uint8, device=qkvr.device)\n        sfk_u8 = torch.empty(0, dtype=torch.uint8, device=qkvr.device)\n        sfv_u8 = torch.empty(0, dtype=torch.uint8, device=qkvr.device)","sourceCodeStart":312,"sourceCodeEnd":348,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/kernels/ops/attention/inkling_attn_prologue.py#L312-L348","documentation":"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.","triggerScenarios":"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.","commonSituations":"Changing --page-size or resizing the KV cache between allocation and decode; per-layer dkv differences sharing one scale allocation; version layout changes.","solutions":["Reallocate sfk/sfv to exactly (k_buf.shape[0]//page_size, dkv//128, 32, page_size//32, 4)","Validate shapes against k_buf/page_size at pool-get time","Derive the shape programmatically instead of hardcoding"],"exampleFix":"# before\nsfk = torch.empty(num_pages, dkv//128, 32, 4, dtype=torch.uint8, device='cuda')\n# after\nsfk = torch.empty(k_buf.shape[0]//page_size, dkv//128, 32, page_size//32, 4, dtype=torch.uint8, device=k_buf.device)","handlingStrategy":"validation","validationCode":"expected = (k_buf.shape[0] // page_size, dkv // 128, 32, page_size // 32, 4)\nif mxfp8_quant:\\n    assert sfk.shape == expected and sfv.shape == expected, (sfk.shape, sfv.shape, expected)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Single source of truth for the scale shape formula shared by allocation and call sites","Re-derive shape after any cache resize"],"tags":["mxfp8","scale-buffers","tensor-shape","decode","inkling"],"backgroundTag":"tensor-shape-mismatch","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}