sgl-project/sglang · error · ValueError

chunk_size must be > 0, got {chunk_size}.

Error message

chunk_size must be > 0, got {chunk_size}.

What it means

_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.

Source

Thrown at python/sglang/multimodal_gen/runtime/models/dits/sana_wm_components.py:358

def _apply_block_diagonal(
    feats: torch.Tensor,
    func_size_pairs: List[Tuple[Callable[[torch.Tensor], torch.Tensor], int]],
) -> torch.Tensor:
    funcs, block_sizes = zip(*func_size_pairs)
    assert feats.shape[-1] == sum(block_sizes), (feats.shape, block_sizes)
    x_blocks = torch.split(feats, list(block_sizes), dim=-1)
    return torch.cat([f(b) for f, b in zip(funcs, x_blocks)], dim=-1)


def _sana_wm_chunk_index_from_chunk_size(
    T: int,
    chunk_size: int,
    strategy: str = "uniform",
) -> list[int]:
    """Return temporal chunk start indices."""
    if chunk_size <= 0:
        raise ValueError(f"chunk_size must be > 0, got {chunk_size}.")
    if T <= 0:
        raise ValueError(f"T must be > 0, got {T}.")

    strategy = "uniform" if strategy is None else str(strategy).lower()

    if strategy in ("uniform", "default"):
        indices = list(range(0, T, chunk_size))
        if len(indices) > 1 and (T - indices[-1]) < chunk_size:
            indices.pop()
        return indices

    if strategy in ("first_frame", "first_frame_alone", "first_frame_only"):
        if T <= 1:
            return [0]
        indices = [0] + list(range(1, T, chunk_size))
        if len(indices) > 2 and (T - indices[-1]) < chunk_size:
            indices.pop()
        return indices

View on GitHub (pinned to 0132848349)

Solutions

  1. Set a positive integer chunk_size (typically the latent temporal chunk length, e.g. 8–32)
  2. If chunking is not wanted, pass explicit chunk_index=[0, T] instead of chunk_size
  3. Trace where chunk_size comes from and guard defaults (chunk_size or default)

Example fix

# before
idx = _sana_wm_normalize_chunk_index(T, chunk_size=0)
# after
idx = _sana_wm_normalize_chunk_index(T, chunk_size=16)
Defensive patterns

Strategy: validation

Validate before calling

if chunk_size is not None:
    assert isinstance(chunk_size, int) and chunk_size >= 1, chunk_size

Type guard

def valid_chunk_size(cs) -> bool: return isinstance(cs, int) and cs > 0

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28). Data as JSON: /api/errors/ba71475b0b585ef4. Report an issue: GitHub.