{"record":{"id":"881aabae459e2ada","repo":"sgl-project/sglang","slug":"chunk-size-should-be-a-int-or-a-tuple-of-length-2","errorCode":null,"errorMessage":"chunk_size should be a int, or a tuple of length 2 or 3, now it is: {len(chunk_size)}","messagePattern":"chunk_size should be a int, or a tuple of length 2 or 3, now it is: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/csrc/attn/vmoba_attn/vmoba/vmoba.py","lineNumber":920,"sourceCode":"            ), f\"patch_resolution {patch_resolution} should be divisible by 3d chunk_size {chunk_size}\"\n            nct, nch, ncw = (\n                patch_resolution[0] // chunk_size[0],\n                patch_resolution[1] // chunk_size[1],\n                patch_resolution[2] // chunk_size[2],\n            )\n            x = rearrange(\n                x,\n                \"b (nct ct nch ch ncw cw) n d -> b (nct nch ncw ct ch cw) n d\",\n                nct=nct,\n                nch=nch,\n                ncw=ncw,\n                ct=chunk_size[0],\n                ch=chunk_size[1],\n                cw=chunk_size[2],\n            )\n            moba_chunk_size = chunk_size[0] * chunk_size[1] * chunk_size[2]\n        else:\n            raise ValueError(\n                f\"chunk_size should be a int, or a tuple of length 2 or 3, now it is: {len(chunk_size)}\"\n            )\n\n    return x, moba_chunk_size\n\n\ndef process_moba_output(\n    x,\n    patch_resolution,\n    chunk_size,\n):\n    if isinstance(chunk_size, float) or isinstance(chunk_size, int):\n        pass\n    elif len(chunk_size) == 2:\n        x = rearrange(\n            x,\n            \"b (nch ncw t ch cw) n d -> b (t nch ch ncw cw) n d\",\n            nch=patch_resolution[1] // chunk_size[0],","sourceCodeStart":902,"sourceCodeEnd":938,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/csrc/attn/vmoba_attn/vmoba/vmoba.py#L902-L938","documentation":"process_moba_input accepts chunk_size as an int or a tuple of length 2 or 3; it unpacks tuples into (ct, ch, cw) components to compute moba_chunk_size. Any other tuple length (or a non-int sequence of different length) raises ValueError.","triggerScenarios":"Calling process_moba_input(x, chunk_size=(a,) or (a, b, c, d) or a list of unexpected length).","commonSituations":"Passing a 4D or 1D chunk tuple from a config meant for another attention implementation; passing a list instead of int/tuple; off-by-one when building chunk_size programmatically.","solutions":["Pass chunk_size as an int or a tuple of length 2 or 3, e.g. (t, h) or (t, h, w)","If chunking only one dimension, pass a plain int","Validate len(chunk_size) in {2, 3} before calling"],"exampleFix":"# before\nx, cs = process_moba_input(x, chunk_size=(2, 8, 8, 4))\n# after\nx, cs = process_moba_input(x, chunk_size=(2, 8, 8))","handlingStrategy":"type-guard","validationCode":"assert isinstance(chunk_size, int) or (isinstance(chunk_size, (tuple, list)) and len(chunk_size) in (2, 3)), \\\n    f\"chunk_size must be int or tuple/list of length 2-3, got {chunk_size!r}\"","typeGuard":"def is_valid_chunk_size(cs) -> bool:\n    if isinstance(cs, int):\n        return True\n    return isinstance(cs, (tuple, list)) and len(cs) in (2, 3) and all(isinstance(c, int) for c in cs)","tryCatchPattern":"try:\n    x, moba_chunk_size = process_moba_input(x, chunk_size)\nexcept ValueError:\n    chunk_size = int(chunk_size[0]) if isinstance(chunk_size, (tuple, list)) else chunk_size\n    x, moba_chunk_size = process_moba_input(x, chunk_size)","preventionTips":["Normalize chunk_size to int or 2/3-tuple at config load","Type-annotate config fields (int | tuple[int, int] | tuple[int, int, int])","Assert shapes before the attention call in debug builds"],"tags":["validation","value-error","chunk-size","moba","shape"],"backgroundTag":"invalid-argument-shape","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}