sgl-project/sglang · error · ValueError

LingBotVideoBlock expects token-level temb6 with shape (B*S,

Error message

LingBotVideoBlock expects token-level temb6 with shape (B*S, 6D); got {tuple(temb6.shape)} for hidden states {tuple(x.shape)}.

What it means

LingBotVideoBlock applies per-token modulation from temb6, so it must have exactly one row per token: shape (B*S, 6*D) where x is (B, S, D). Any other row count or a 3D temb6 fails immediately because the subsequent view(x.shape[0], x.shape[1], -1) would be invalid.

Source

Thrown at python/sglang/multimodal_gen/runtime/models/dits/lingbot_video_moe.py:328

                topk_group=topk_group,
                routed_scaling_factor=routed_scaling_factor,
                n_shared_experts=n_shared_experts,
            )
        else:
            self.ffn = LingBotVideoMLP(h, intermediate_size)
        self.norm_post_ffn = LingBotVideoRMSNorm(h, norm_eps)

    def forward(
        self,
        x: torch.Tensor,
        temb6: torch.Tensor,
        freqs_cis: tuple[torch.Tensor, torch.Tensor],
        attention_mask: Optional[torch.Tensor] = None,
        attn_mask_meta: Optional[dict] = None,
    ) -> torch.Tensor:
        expected_tokens = x.shape[0] * x.shape[1]
        if temb6.ndim != 2 or temb6.shape[0] != expected_tokens:
            raise ValueError(
                "LingBotVideoBlock expects token-level temb6 with shape "
                f"(B*S, 6D); got {tuple(temb6.shape)} for hidden states {tuple(x.shape)}."
            )
        mod = temb6.view(x.shape[0], x.shape[1], -1) + self.scale_shift_table.unsqueeze(
            0
        )
        shift_msa, scale_msa, gate_msa, shift_mlp, scale_mlp, gate_mlp = mod.chunk(
            6, dim=-1
        )
        gate_msa, gate_mlp = gate_msa.tanh(), gate_mlp.tanh()
        scale_msa, scale_mlp = 1.0 + scale_msa, 1.0 + scale_mlp

        bulk_dtype = self.attn.to_q.weight.dtype
        attn_in = (self.norm1(x) * scale_msa + shift_msa).to(bulk_dtype)
        attn_out = self.attn(
            attn_in,
            freqs_cis,
            attention_mask=attention_mask,

View on GitHub (pinned to 0132848349)

Solutions

  1. Expand per-sample temb6 to token level before the call: temb6 = temb6[:, None, :].expand(B, S, -1).reshape(B*S, -1)
  2. Verify the packing step in the parent model produces (B*S, 6D), matching how x was reshaped
  3. Keep x and temb6 derived from the same view/reshape of the packed sequence

Example fix

# before
x = x.reshape(B * S, D, ...)  # block receives (B,S,D) but temb6 stays (B, 6D)

# after
temb6 = temb6[:, None, :].expand(B, S, -1).reshape(B * S, -1)
out = block(x, temb6, freqs_cis, ...)
Defensive patterns

Strategy: validation

Validate before calling

B, S, _ = x.shape\nassert temb6.ndim == 2 and temb6.shape[0] == B * S, f'{tuple(temb6.shape)} vs x {tuple(x.shape)}'

Type guard

def is_token_level_temb(temb6: torch.Tensor, x: torch.Tensor) -> bool:\n    return temb6.ndim == 2 and temb6.shape[0] == x.shape[0] * x.shape[1]

Prevention

When it happens

Trigger: Calling the block's forward with temb6 whose shape[0] != x.shape[0]*x.shape[1] (e.g. per-sequence temb of shape (B, 6D)) or with ndim != 2.

Common situations: Refactoring the caller to pass sequence-level embeddings instead of expanded per-token ones; forgetting to repeat_interleave timestep embeddings across the S dimension after packing (B,S) frames.

Related errors


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