sgl-project/sglang · error · ValueError
chunk_size should be a int, or a tuple of length 2 or 3, now
Error message
chunk_size should be a int, or a tuple of length 2 or 3, now it is: {len(chunk_size)} What it means
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.
Source
Thrown at python/sglang/multimodal_gen/csrc/attn/vmoba_attn/vmoba/vmoba.py:920
), f"patch_resolution {patch_resolution} should be divisible by 3d chunk_size {chunk_size}"
nct, nch, ncw = (
patch_resolution[0] // chunk_size[0],
patch_resolution[1] // chunk_size[1],
patch_resolution[2] // chunk_size[2],
)
x = rearrange(
x,
"b (nct ct nch ch ncw cw) n d -> b (nct nch ncw ct ch cw) n d",
nct=nct,
nch=nch,
ncw=ncw,
ct=chunk_size[0],
ch=chunk_size[1],
cw=chunk_size[2],
)
moba_chunk_size = chunk_size[0] * chunk_size[1] * chunk_size[2]
else:
raise ValueError(
f"chunk_size should be a int, or a tuple of length 2 or 3, now it is: {len(chunk_size)}"
)
return x, moba_chunk_size
def process_moba_output(
x,
patch_resolution,
chunk_size,
):
if isinstance(chunk_size, float) or isinstance(chunk_size, int):
pass
elif len(chunk_size) == 2:
x = rearrange(
x,
"b (nch ncw t ch cw) n d -> b (t nch ch ncw cw) n d",
nch=patch_resolution[1] // chunk_size[0],View on GitHub (pinned to 0132848349)
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
Example fix
# before x, cs = process_moba_input(x, chunk_size=(2, 8, 8, 4)) # after x, cs = process_moba_input(x, chunk_size=(2, 8, 8))
Defensive patterns
Strategy: type-guard
Validate before calling
assert isinstance(chunk_size, int) or (isinstance(chunk_size, (tuple, list)) and len(chunk_size) in (2, 3)), \
f"chunk_size must be int or tuple/list of length 2-3, got {chunk_size!r}" Type guard
def is_valid_chunk_size(cs) -> bool:
if isinstance(cs, int):
return True
return isinstance(cs, (tuple, list)) and len(cs) in (2, 3) and all(isinstance(c, int) for c in cs) Try / catch
try:
x, moba_chunk_size = process_moba_input(x, chunk_size)
except ValueError:
chunk_size = int(chunk_size[0]) if isinstance(chunk_size, (tuple, list)) else chunk_size
x, moba_chunk_size = process_moba_input(x, chunk_size) Prevention
- 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
When it happens
Trigger: Calling process_moba_input(x, chunk_size=(a,) or (a, b, c, d) or a list of unexpected length).
Common situations: 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.
Related errors
- Invalid threshold_type for topk: {threshold_type}. Choose 'q
- Invalid threshold_type: {threshold_type}. Choose 'query_head
- Invalid select_mode: {select_mode}. Choose 'topk' or 'thresh
- Validate failed: unsupported tensor shape: {t.shape}.
- Validate failed: S({S}) must be divisible by F({F}).
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/881aabae459e2ada.
Report an issue: GitHub.