{"record":{"id":"1a50f59ff25fbe8c","repo":"sgl-project/sglang","slug":"mixed-qkv-must-be-contiguous-in-the-last-dim-1a50f5","errorCode":null,"errorMessage":"`mixed_qkv` must be contiguous in the last dim.","messagePattern":"`mixed_qkv` must be contiguous in the last dim\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/kernels/ops/attention/fla/fused_recurrent_linear_replayssm.py","lineNumber":480,"sourceCode":"        ``dt_bias``=[HV], ``g_cache``=[num_slots, HV, L].\n      * ``is_kda=True`` (KDA): per-K-channel gate.  ``a``=[B, HV, K],\n        ``dt_bias``=[HV, K], ``g_cache``=[num_slots, HV, L, K].\n    ``A_log`` is [HV] (per-head scalar) for both.\n\n    Same call surface as the packed decode plus the three ring caches\n    (``d_cache`` / ``k_cache`` / ``g_cache``) and the per-decode-row\n    ``write_pos`` cursor.  ``initial_state`` is both the checkpoint read (h0)\n    and the (flush-only) checkpoint write (ht), in place.\n\n    Allocates nothing persistent: the caller owns the ring tensors and is\n    responsible for advancing / resetting ``write_pos`` (e.g. ``(write_pos+1) %\n    L`` after each step).  This is a STANDALONE kernel; the memory-pool / cache\n    integration is a later phase.\n    \"\"\"\n    if mixed_qkv.ndim != 2:\n        raise ValueError(f\"`mixed_qkv` must be 2D (got ndim={mixed_qkv.ndim}).\")\n    if mixed_qkv.stride(-1) != 1:\n        raise ValueError(\"`mixed_qkv` must be contiguous in the last dim.\")\n    if b.ndim != 2:\n        raise ValueError(f\"`b` must be 2D (got b.ndim={b.ndim}).\")\n    if A_log.ndim != 1:\n        raise ValueError(\"`A_log` must be a 1D tensor.\")\n    if initial_state.ndim != 4:\n        raise ValueError(f\"`initial_state` must be 4D (got ndim={initial_state.ndim}).\")\n    if not out.is_contiguous():\n        raise ValueError(\"`out` must be contiguous.\")\n    if write_pos.ndim != 1 or write_pos.dtype != torch.int32:\n        raise ValueError(\"`write_pos` must be a 1D int32 tensor.\")\n    if force_flush is not None and (\n        force_flush.ndim != 1 or force_flush.dtype != torch.int32\n    ):\n        raise ValueError(\"`force_flush` must be a 1D int32 tensor or None.\")\n\n    B = mixed_qkv.shape[0]\n    num_state_slots, HV, V, K = initial_state.shape\n    qkv_dim = mixed_qkv.shape[1]","sourceCodeStart":462,"sourceCodeEnd":498,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/kernels/ops/attention/fla/fused_recurrent_linear_replayssm.py#L462-L498","documentation":"The replaySSM decode kernel requires mixed_qkv to be contiguous in its last dimension (stride(-1) == 1) so the Triton kernel can coalesced-load each token's packed row. Non-unit last stride (e.g. from a transposed or sliced view) is rejected.","triggerScenarios":"Passing mixed_qkv produced by a transpose, narrow/slice of a larger buffer, or expand that leaves last-dim stride != 1.","commonSituations":"Slicing qkv out of a fused projection tensor with padding; using tensors from a ring buffer with non-standard strides in CUDA-graph replay tests.","solutions":["Call .contiguous() on mixed_qkv before the kernel (or ensure the projection writes a contiguous tensor)","If slicing a packed buffer, copy the slice into a fresh contiguous tensor","Verify with mixed_qkv.stride(-1) == 1 in debug builds"],"exampleFix":"// before\nqkv = buf[:, :, :D]  # non-unit stride\nfused_recurrent_linear_replayssm_decode(qkv, ...)\n// after\nqkv = buf[:, :, :D].contiguous()\nfused_recurrent_linear_replayssm_decode(qkv, ...)","handlingStrategy":"validation","validationCode":"if mixed_qkv.stride(-1) != 1:\n    mixed_qkv = mixed_qkv.contiguous()","typeGuard":"def last_dim_contiguous(t: torch.Tensor) -> bool:\n    return t.stride(-1) == 1","tryCatchPattern":null,"preventionTips":["Avoid sliced views of padded projection buffers on the kernel path","Call .contiguous() after any slice/transpose in decode helpers"],"tags":["pytorch","contiguity","triton","replayssm"],"backgroundTag":"non-contiguous-tensor","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}