{"record":{"id":"13a01c7bec1b1391","repo":"sgl-project/sglang","slug":"ltx2-split-rope-shape-mismatch-x-tuple-x-shape","errorCode":null,"errorMessage":"LTX2 split RoPE shape mismatch: x={tuple(x.shape)}, cos={tuple(cos.shape)}, sin={tuple(sin.shape)}","messagePattern":"LTX2 split RoPE shape mismatch: x=(.+?), cos=(.+?), sin=(.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/kernels/ops/diffusion/rope/ltx2_rotary_triton.py","lineNumber":73,"sourceCode":"    )\n\n    tl.store(out_ptr + x_base + offsets[None, :], out_first, mask=mask)\n    tl.store(out_ptr + x_base + half_dim + offsets[None, :], out_second, mask=mask)\n\n\ndef apply_ltx2_split_rotary_emb(\n    x: torch.Tensor, cos: torch.Tensor, sin: torch.Tensor\n) -> torch.Tensor:\n    batch, seq_len, inner_dim = x.shape\n    cos_batch, num_heads, cos_seq_len, half_dim = cos.shape\n    head_dim = half_dim * 2\n    if (\n        cos_batch != batch\n        or cos_seq_len != seq_len\n        or inner_dim != num_heads * head_dim\n        or sin.shape != cos.shape\n    ):\n        raise ValueError(\n            \"LTX2 split RoPE shape mismatch: \"\n            f\"x={tuple(x.shape)}, cos={tuple(cos.shape)}, sin={tuple(sin.shape)}\"\n        )\n\n    out = torch.empty_like(x)\n    block_half = triton.next_power_of_2(half_dim)\n    block_heads = min(16, triton.next_power_of_2(num_heads))\n    num_warps = min(8, max(1, block_heads))\n    grid = (batch * seq_len, triton.cdiv(num_heads, block_heads))\n    _ltx2_split_rotary_kernel[grid](\n        out,\n        x,\n        cos,\n        sin,\n        seq_len,\n        num_heads,\n        head_dim,\n        half_dim,","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/kernels/ops/diffusion/rope/ltx2_rotary_triton.py#L55-L91","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Reshape cos/sin to [batch, seq_len, inner_dim//2].","Ensure inner_dim == num_heads * head_dim of the caller's attention config.","Use sin with identical shape as cos (no separate freq tensor)."],"exampleFix":"// before\ncos = table[None]  # [1, S, D/2], x is [B, S, D]\n// after\ncos = table[None].expand(batch, seq_len, inner_dim // 2).contiguous()\nsin = cos.clone()","handlingStrategy":"validation","validationCode":"B, S, D = x.shape\nassert cos.shape == (B, S, D // 2) and sin.shape == cos.shape","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Expand broadcast tables to full batch before calling.","Keep inner_dim aligned with num_heads*head_dim."],"tags":["rope","ltx","shape-validation"],"backgroundTag":"rope-frequency-table-shape-mismatch","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}