sgl-project/sglang · error · ValueError

shot_durations must match shot_prompts length

Error message

shot_durations must match shot_prompts length

What it means

When shot_durations is provided to expand_causal_block_prompts it must have exactly one duration per shot prompt; mismatched lengths are rejected because block allocation depends on per-shot durations.

Source

Thrown at python/sglang/multimodal_gen/runtime/pipelines_core/stages/causal_denoising.py:68

CAUSAL_SCENE_CUT_MASK_KEY = "causal_scene_cut_mask"
CAUSAL_SHOT_INDICES_KEY = "causal_shot_indices"
CausalKVCache = CausalSelfAttentionKVCache | QVGPackedCausalKVCache


def expand_causal_block_prompts(
    shot_prompts: list[str],
    *,
    num_blocks: int,
    shot_durations: list[int] | None = None,
    chunks_per_shot: int = 0,
    scene_cut_prefix: str = "",
) -> tuple[list[str], list[bool], list[int]]:
    if not shot_prompts:
        raise ValueError("shot_prompts must be non-empty")
    if num_blocks <= 0:
        raise ValueError("num_blocks must be positive")
    if shot_durations is not None and len(shot_durations) != len(shot_prompts):
        raise ValueError("shot_durations must match shot_prompts length")

    if shot_durations is not None:
        durations = shot_durations[: len(shot_prompts)]
    elif chunks_per_shot > 0:
        durations = [chunks_per_shot] * len(shot_prompts)
    else:
        base, extra = divmod(num_blocks, len(shot_prompts))
        durations = [base + (1 if i < extra else 0) for i in range(len(shot_prompts))]

    clamped: list[int] = []
    remaining = num_blocks
    for duration in durations:
        if remaining <= 0:
            break
        take = min(int(duration), remaining)
        clamped.append(take)
        remaining -= take
    if remaining > 0 and clamped:

View on GitHub (pinned to 0132848349)

Solutions

  1. Make len(shot_durations) == len(shot_prompts)
  2. Drop shot_durations and use chunks_per_shot for uniform durations

Example fix

# before
expand_causal_block_prompts(['a','b','c'], 8, shot_durations=[4])
# after
expand_causal_block_prompts(['a','b','c'], 8, shot_durations=[4,4,4])
Defensive patterns

Strategy: validation

Validate before calling

assert shot_durations is None or len(shot_durations) == len(shot_prompts)

Prevention

When it happens

Trigger: expand_causal_block_prompts(prompts, num_blocks=n, shot_durations=[4]) with 3 prompts.

Common situations: Prompt list and duration list built from different sources (prompts from request, durations from config); adding a prompt without updating durations; trailing empty shot filtered from one list but not the other.

Related errors


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