sgl-project/sglang · error · ValueError

timestep must have shape [B, S, 9 * D]

Error message

timestep must have shape [B, S, 9 * D]

What it means

ltx2_ada_values9 computes the nine LTX2 AdaLN modulation values from a [B, S, 9*D] timestep embedding. The first validation requires a rank-3 tensor; anything else (e.g. 2D or 4D) is rejected with this ValueError.

Source

Thrown at python/sglang/kernels/ops/diffusion/modulate/ltx2_ada_values_triton.py:143

    ).to(tl.bfloat16)

    tl.store(out0_ptr + base, (table0 + temb0).to(tl.bfloat16), mask=mask)
    tl.store(out1_ptr + base, (table1 + temb1).to(tl.bfloat16), mask=mask)
    tl.store(out2_ptr + base, (table2 + temb2).to(tl.bfloat16), mask=mask)
    tl.store(out3_ptr + base, (table3 + temb3).to(tl.bfloat16), mask=mask)
    tl.store(out4_ptr + base, (table4 + temb4).to(tl.bfloat16), mask=mask)
    tl.store(out5_ptr + base, (table5 + temb5).to(tl.bfloat16), mask=mask)
    tl.store(out6_ptr + base, (table6 + temb6).to(tl.bfloat16), mask=mask)
    tl.store(out7_ptr + base, (table7 + temb7).to(tl.bfloat16), mask=mask)
    tl.store(out8_ptr + base, (table8 + temb8).to(tl.bfloat16), mask=mask)


def ltx2_ada_values9(
    scale_shift_table: torch.Tensor,
    timestep: torch.Tensor,
) -> tuple[torch.Tensor, ...]:
    if timestep.ndim != 3:
        raise ValueError("timestep must have shape [B, S, 9 * D]")
    if not timestep.is_cuda or timestep.dtype != torch.bfloat16:
        raise ValueError("timestep must be a CUDA bfloat16 tensor")
    if not timestep.is_contiguous():
        raise ValueError("timestep must be contiguous")
    if scale_shift_table.ndim != 2 or scale_shift_table.shape[0] != 9:
        raise ValueError("scale_shift_table must have shape [9, D]")
    if (
        not scale_shift_table.is_cuda
        or scale_shift_table.dtype not in (torch.bfloat16, torch.float32)
        or scale_shift_table.stride(-1) != 1
    ):
        raise ValueError(
            "scale_shift_table must be CUDA, bf16/fp32, last-dim contiguous"
        )

    total_params = int(scale_shift_table.shape[0])
    hidden = int(scale_shift_table.shape[1])
    if hidden <= 0 or timestep.shape[-1] != total_params * hidden:

View on GitHub (pinned to 0132848349)

Solutions

  1. Reshape to 3D: timestep = timestep.view(B, S, 9*D) or timestep[:, None, :] when S=1
  2. Verify you're passing the sinusoidal-timestep projection output, not raw scalar timesteps
  3. Add an assert timestep.ndim == 3 before calling

Example fix

# before
vals = ltx2_ada_values9(table, emb_2d)  # [B, 9*D]
# after
emb = emb_2d[:, None, :].expand(B, S, 9*D).contiguous()
vals = ltx2_ada_values9(table, emb)
Defensive patterns

Strategy: validation

Validate before calling

assert timestep.ndim == 3, timestep.shape

Type guard

def is_3d(t: torch.Tensor) -> bool:
    return t.dim() == 3

Prevention

When it happens

Trigger: Passing timestep as 2D [B, 9*D] (single token, no sequence dim) or 4D [B, S, 1, 9*D]; shapes that were not expanded to include the sequence dimension before the call.

Common situations: Text-to-video pipelines where a global embedding is broadcast over S tokens — forgetting timestep[:, None, :] expansion; feeding raw scheduler timesteps instead of the projected embedding tensor.

Related errors


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