{"record":{"id":"ba71475b0b585ef4","repo":"sgl-project/sglang","slug":"chunk-size-must-be-0-got-chunk-size","errorCode":null,"errorMessage":"chunk_size must be > 0, got {chunk_size}.","messagePattern":"chunk_size must be > 0, got (.+?)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/models/dits/sana_wm_components.py","lineNumber":358,"sourceCode":"\ndef _apply_block_diagonal(\n    feats: torch.Tensor,\n    func_size_pairs: List[Tuple[Callable[[torch.Tensor], torch.Tensor], int]],\n) -> torch.Tensor:\n    funcs, block_sizes = zip(*func_size_pairs)\n    assert feats.shape[-1] == sum(block_sizes), (feats.shape, block_sizes)\n    x_blocks = torch.split(feats, list(block_sizes), dim=-1)\n    return torch.cat([f(b) for f, b in zip(funcs, x_blocks)], dim=-1)\n\n\ndef _sana_wm_chunk_index_from_chunk_size(\n    T: int,\n    chunk_size: int,\n    strategy: str = \"uniform\",\n) -> list[int]:\n    \"\"\"Return temporal chunk start indices.\"\"\"\n    if chunk_size <= 0:\n        raise ValueError(f\"chunk_size must be > 0, got {chunk_size}.\")\n    if T <= 0:\n        raise ValueError(f\"T must be > 0, got {T}.\")\n\n    strategy = \"uniform\" if strategy is None else str(strategy).lower()\n\n    if strategy in (\"uniform\", \"default\"):\n        indices = list(range(0, T, chunk_size))\n        if len(indices) > 1 and (T - indices[-1]) < chunk_size:\n            indices.pop()\n        return indices\n\n    if strategy in (\"first_frame\", \"first_frame_alone\", \"first_frame_only\"):\n        if T <= 1:\n            return [0]\n        indices = [0] + list(range(1, T, chunk_size))\n        if len(indices) > 2 and (T - indices[-1]) < chunk_size:\n            indices.pop()\n        return indices","sourceCodeStart":340,"sourceCodeEnd":376,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/models/dits/sana_wm_components.py#L340-L376","documentation":"_sana_wm_chunk_index_from_chunk_size computes temporal chunk boundaries and requires chunk_size >= 1. Zero or negative chunk sizes are rejected before any slicing math.","triggerScenarios":"Calling the chunking helper (directly or via _sana_wm_normalize_chunk_index with chunk_index=None) with chunk_size=0 or negative — e.g. from a config where chunk_gdn_chunk_size was unset and defaulted to 0.","commonSituations":"YAML/JSON config with chunk_size: 0 meaning 'disabled'; arithmetic like max(0, x // n) collapsing to 0; CLI flag parsed as int with a missing value.","solutions":["Set a positive integer chunk_size (typically the latent temporal chunk length, e.g. 8–32)","If chunking is not wanted, pass explicit chunk_index=[0, T] instead of chunk_size","Trace where chunk_size comes from and guard defaults (chunk_size or default)"],"exampleFix":"# before\nidx = _sana_wm_normalize_chunk_index(T, chunk_size=0)\n# after\nidx = _sana_wm_normalize_chunk_index(T, chunk_size=16)","handlingStrategy":"validation","validationCode":"if chunk_size is not None:\n    assert isinstance(chunk_size, int) and chunk_size >= 1, chunk_size","typeGuard":"def valid_chunk_size(cs) -> bool: return isinstance(cs, int) and cs > 0","tryCatchPattern":null,"preventionTips":["Validate config ints at load time; never use 0 to mean 'disabled'"],"tags":["sana-wm","chunking","invalid-argument","validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}