sgl-project/sglang · error · ValueError

T must be > 0, got {T}.

Error message

T must be > 0, got {T}.

What it means

The chunking helper requires T > 0, i.e. at least one latent frame. T=0 or negative means the latent has zero (or invalid) temporal extent and chunk boundaries are undefined.

Source

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

    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

    if strategy in ("first_plus_one", "first_chunk_plus_one"):

View on GitHub (pinned to 0132848349)

Solutions

  1. Ensure the latent has at least patch_size_t frames (pad or reject too-short clips)
  2. Fix upstream slicing so T_raw >= patch_size_t before dividing
  3. Pass the true latent frame count T, not a pixel frame count of 0

Example fix

# before
T = frames.shape[2] // p_t  # 0 when only 1 frame and p_t=2
# after
assert frames.shape[2] >= p_t, 'need at least p_t frames'
T = frames.shape[2] // p_t
Defensive patterns

Strategy: validation

Validate before calling

assert T_raw >= p_t, f'video too short: {T_raw} < {p_t}'

Prevention

When it happens

Trigger: Calling with T = T_raw // patch_size_t when T_raw < patch_size_t (floordiv to 0), or with a video tensor whose temporal dim is 0.

Common situations: A single-frame clip fed to a model with temporal patch size 2; off-by-one slicing of video frames producing empty tensors; misparsed num_frames=0.

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/60c02c871fc3c928. Report an issue: GitHub.