{"record":{"id":"b4f3afba47314526","repo":"sgl-project/sglang","slug":"mxfp8-fused-decode-prologue-requires-contiguous-in","errorCode":null,"errorMessage":"MXFP8 fused decode prologue requires contiguous interleaved SFK/SFV.","messagePattern":"MXFP8 fused decode prologue requires contiguous interleaved SFK/SFV\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/kernels/ops/attention/inkling_attn_prologue.py","lineNumber":335,"sourceCode":"    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)\n    k_out = torch.empty(t, dkv, dtype=qkvr.dtype, device=qkvr.device)\n    v_out = torch.empty(t, dkv, dtype=qkvr.dtype, device=qkvr.device)\n    if activation == \"swish\":\n        activation = \"silu\"\n    use_silu = activation in (\"silu\", \"swish\")","sourceCodeStart":317,"sourceCodeEnd":353,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/kernels/ops/attention/inkling_attn_prologue.py#L317-L353","documentation":"In the decode path, sfk and sfv must be contiguous tensors because the fused kernel writes the interleaved scale layout with dense-stride indexing. The check not sfk.is_contiguous() or not sfv.is_contiguous() runs after shape validation and before the fp8 output allocation; strided views would cause scales to be written at wrong memory offsets, corrupting the MXFP8 cache.","triggerScenarios":"Passing strided or sliced sfk/sfv views into inkling_attn_prologue_decode — e.g. buffers carved out of a stacked multi-layer scale pool with narrow/slice, or after a transpose-based layout fix.","commonSituations":"View-based per-layer scale buffers over one big allocation; buffers returned from a cache that stores transposed layouts internally.","solutions":["Call .contiguous() on sfk/sfv before the decode call","Store per-layer scale buffers as dense standalone tensors","Add an is_contiguous() assert in the pool accessor"],"exampleFix":"# before\nsfk, sfv = layer_view_of_pool  # non-contiguous\n# after\nsfk, sfv = layer_view_of_pool.contiguous()","handlingStrategy":"validation","validationCode":"if mxfp8_quant:\\n    sfk = sfk.contiguous(); sfv = sfv.contiguous()","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Dense per-layer allocations over view-based slicing","Pool getters should guarantee contiguity"],"tags":["mxfp8","scale-buffers","contiguity","decode","inkling"],"backgroundTag":"non-contiguous-tensor","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}