sgl-project/sglang · error · ValueError

LTX2 split RoPE shape mismatch: x={tuple(x.shape)}, cos={tup

Error message

LTX2 split RoPE shape mismatch: x={tuple(x.shape)}, cos={tuple(cos.shape)}, sin={tuple(sin.shape)}

What it means

apply_ltx2_split_rotary_emb requires cos/sin of shape [batch, seq_len, inner_dim/2] matching x's [batch, seq_len, num_heads*head_dim] layout; sin must exactly match cos. A mismatch means the RoPE table doesn't align with the token layout.

Source

Thrown at python/sglang/kernels/ops/diffusion/rope/ltx2_rotary_triton.py:73

    )

    tl.store(out_ptr + x_base + offsets[None, :], out_first, mask=mask)
    tl.store(out_ptr + x_base + half_dim + offsets[None, :], out_second, mask=mask)


def apply_ltx2_split_rotary_emb(
    x: torch.Tensor, cos: torch.Tensor, sin: torch.Tensor
) -> torch.Tensor:
    batch, seq_len, inner_dim = x.shape
    cos_batch, num_heads, cos_seq_len, half_dim = cos.shape
    head_dim = half_dim * 2
    if (
        cos_batch != batch
        or cos_seq_len != seq_len
        or inner_dim != num_heads * head_dim
        or sin.shape != cos.shape
    ):
        raise ValueError(
            "LTX2 split RoPE shape mismatch: "
            f"x={tuple(x.shape)}, cos={tuple(cos.shape)}, sin={tuple(sin.shape)}"
        )

    out = torch.empty_like(x)
    block_half = triton.next_power_of_2(half_dim)
    block_heads = min(16, triton.next_power_of_2(num_heads))
    num_warps = min(8, max(1, block_heads))
    grid = (batch * seq_len, triton.cdiv(num_heads, block_heads))
    _ltx2_split_rotary_kernel[grid](
        out,
        x,
        cos,
        sin,
        seq_len,
        num_heads,
        head_dim,
        half_dim,

View on GitHub (pinned to 0132848349)

Solutions

  1. Reshape cos/sin to [batch, seq_len, inner_dim//2].
  2. Ensure inner_dim == num_heads * head_dim of the caller's attention config.
  3. Use sin with identical shape as cos (no separate freq tensor).

Example fix

// before
cos = table[None]  # [1, S, D/2], x is [B, S, D]
// after
cos = table[None].expand(batch, seq_len, inner_dim // 2).contiguous()
sin = cos.clone()
Defensive patterns

Strategy: validation

Validate before calling

B, S, D = x.shape
assert cos.shape == (B, S, D // 2) and sin.shape == cos.shape

Prevention

When it happens

Trigger: Calling apply_ltx2_split_rotary_emb (or apply_split_rotary_emb dispatching to it) with tables whose batch/seq dims differ from x, or inner_dim not divisible into the expected head structure.

Common situations: Passing a [1, S, D/2] broadcast table when x has batch > 1, or reusing a full-dim RoPE table ([S, D]) with the split kernel.

Related errors


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