sgl-project/sglang · error · ValueError
Expected x.shape[-1] to be even for split rotary, got {last}
Error message
Expected x.shape[-1] to be even for split rotary, got {last}. What it means
ValueError from apply_split_rotary_emb: the 'split' rotary embedding variant requires the last dimension of x to be even so it can be reshaped into (2, r). An odd last dim means head_dim is odd, which is incompatible with split rotary.
Source
Thrown at python/sglang/multimodal_gen/runtime/models/adapter/ltx_2_connector.py:46
def apply_split_rotary_emb(
x: torch.Tensor, freqs: Tuple[torch.Tensor, torch.Tensor]
) -> torch.Tensor:
cos, sin = freqs
x_dtype = x.dtype
needs_reshape = False
if x.ndim != 4 and cos.ndim == 4:
# cos is (#b, h, t, r) -> reshape x to (b, h, t, dim_per_head)
# The cos/sin batch dim may only be broadcastable, so take batch size from x
b = x.shape[0]
_, h, t, _ = cos.shape
x = x.reshape(b, t, h, -1).transpose(1, 2)
needs_reshape = True
# Split last dim (2*r) into (d=2, r)
last = x.shape[-1]
if last % 2 != 0:
raise ValueError(
f"Expected x.shape[-1] to be even for split rotary, got {last}."
)
r = last // 2
# (..., 2, r)
split_x = x.reshape(*x.shape[:-1], 2, r)
first_x = split_x[..., :1, :] # (..., 1, r)
second_x = split_x[..., 1:, :] # (..., 1, r)
cos_u = cos.unsqueeze(-2) # broadcast to (..., 1, r) against (..., 2, r)
sin_u = sin.unsqueeze(-2)
out = split_x * cos_u
first_out = out[..., :1, :]
second_out = out[..., 1:, :]
first_out.addcmul_(-sin_u, second_x)
second_out.addcmul_(sin_u, first_x)View on GitHub (pinned to 0132848349)
Solutions
- Use an even head_dim in the model config
- Switch rope_type to 'interleaved' if the checkpoint supports it
- Check upstream reshapes: ensure x is (b, h, t, head_dim) with even head_dim before this call
Example fix
// before attn = LTXConnector(..., dim_head=57, rope_type="split") // after attn = LTXConnector(..., dim_head=64, rope_type="split")
Defensive patterns
Strategy: validation
Validate before calling
assert head_dim % 2 == 0, f"split rope needs even head_dim, got {head_dim}" Prevention
- Validate head_dim even when configuring rope_type='split'
- Fall back to 'interleaved' for odd head dims
When it happens
Trigger: Calling the LTX-2 connector attention forward with rope_type='split' and a head_dim (x.shape[-1]) that is odd, e.g. head_dim=57 after projection.
Common situations: Loading an LTX-2 checkpoint with unusual head dims; manual model configs where dim_head is odd; accidental transpose/reshape upstream leaving an odd trailing dim.
Related errors
- head_dim must be a multiple of 8, got {head_dim}.
- rope_pool_fused expects q/k/v to be 3-D
- rope_pool_fused expects positions/slots to be 1-D
- rope_pool_fused expects pool tensors to be 3-D
- q shape must be [num_tokens, num_qo_heads, head_dim], got {q
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/10398a9c16e89d74.
Report an issue: GitHub.