{"record":{"id":"0bbd19f56e0f0fe7","repo":"sgl-project/sglang","slug":"unexpected-swizzle-shift-want-s-3-for-m-4","errorCode":null,"errorMessage":"Unexpected swizzle shift – want S==3 for M==4","messagePattern":"Unexpected swizzle shift – want S==3 for M==4","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/kernels/ops/attention/flash_attn/cute/mma_sm100_desc.py","lineNumber":206,"sourceCode":"    SWIZZLE_NONE = 0  # (a.k.a. “INTERLEAVE” in older docs)\n    SWIZZLE_128B_BASE32B = 1\n    SWIZZLE_128B = 2\n    SWIZZLE_64B = 4\n    SWIZZLE_32B = 6\n    # values 3,5,7 are reserved / illegal for UMMA\n\n\n# ---------------------------------------------------------------------------\n#  Helpers – figure out the SWIZZLE_* family from the tensor layout\n# ---------------------------------------------------------------------------\n\n\ndef _layout_type(swizzle: cute.Swizzle) -> LayoutType:\n    B, M, S = swizzle.num_bits, swizzle.num_base, swizzle.num_shift\n\n    if M == 4:  # Swizzle<*,4,3>\n        if S != 3:\n            raise ValueError(\"Unexpected swizzle shift – want S==3 for M==4\")\n        return {\n            0: LayoutType.SWIZZLE_NONE,\n            1: LayoutType.SWIZZLE_32B,\n            2: LayoutType.SWIZZLE_64B,\n            3: LayoutType.SWIZZLE_128B,\n        }[\n            B\n        ]  # KeyError ⇒ invalid B→ raise\n    if M == 5:  # Swizzle<2,5,2> (the only legal triple for M==5)\n        if (B, S) != (2, 2):\n            raise ValueError(\"Only Swizzle<2,5,2> supported for 128B_BASE32B\")\n        return LayoutType.SWIZZLE_128B_BASE32B\n\n    # Any other (M,B,S) triple is not a UMMA-legal shared-memory layout\n    raise ValueError(\"Unsupported swizzle triple for UMMA smem descriptor\")\n\n\ndef make_smem_desc_base(","sourceCodeStart":188,"sourceCodeEnd":224,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/kernels/ops/attention/flash_attn/cute/mma_sm100_desc.py#L188-L224","documentation":"_layout_type maps a cute.Swizzle< B, M, S > triple to a UMMA shared-memory layout type. For M==4 the shift field S must be 3 (Swizzle<*,4,3> is the only legal family); other shifts raise this ValueError.","triggerScenarios":"Calling make_smem_desc_base with a swizzle whose num_base is 4 but num_shift != 3, e.g. Swizzle<3,4,2> constructed manually or from a copied layout that was mutated.","commonSituations":"Hand-constructing swizzled shared-memory layouts instead of using the canonical atoms; modifying an existing atom's shift field while tuning.","solutions":["Use the canonical swizzle atoms produced by cute (e.g. via make_cute_layout / standard tile atoms) rather than building Swizzle objects by hand.","Set num_shift=3 whenever num_base==4.","Prefer smem_desc_base_from_tensor over manual layout+swizzle plumbing."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"assert swizzle.num_base != 4 or swizzle.num_shift == 3","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never hand-edit swizzle fields; copy atoms from cute's canonical constructors.","Centralize swizzle constants instead of re-deriving them per site."],"tags":["cutlass","sm100","swizzle","shared-memory"],"backgroundTag":"invalid-swizzle-layout","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}