{"record":{"id":"c7484b7cd81deecf","repo":"sgl-project/sglang","slug":"lingbotvideoblock-expects-token-level-temb6-with-s","errorCode":null,"errorMessage":"LingBotVideoBlock expects token-level temb6 with shape (B*S, 6D); got {tuple(temb6.shape)} for hidden states {tuple(x.shape)}.","messagePattern":"LingBotVideoBlock expects token-level temb6 with shape \\(B\\*S, 6D\\); got (.+?) for hidden states (.+?)\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/models/dits/lingbot_video_moe.py","lineNumber":328,"sourceCode":"                topk_group=topk_group,\n                routed_scaling_factor=routed_scaling_factor,\n                n_shared_experts=n_shared_experts,\n            )\n        else:\n            self.ffn = LingBotVideoMLP(h, intermediate_size)\n        self.norm_post_ffn = LingBotVideoRMSNorm(h, norm_eps)\n\n    def forward(\n        self,\n        x: torch.Tensor,\n        temb6: torch.Tensor,\n        freqs_cis: tuple[torch.Tensor, torch.Tensor],\n        attention_mask: Optional[torch.Tensor] = None,\n        attn_mask_meta: Optional[dict] = None,\n    ) -> torch.Tensor:\n        expected_tokens = x.shape[0] * x.shape[1]\n        if temb6.ndim != 2 or temb6.shape[0] != expected_tokens:\n            raise ValueError(\n                \"LingBotVideoBlock expects token-level temb6 with shape \"\n                f\"(B*S, 6D); got {tuple(temb6.shape)} for hidden states {tuple(x.shape)}.\"\n            )\n        mod = temb6.view(x.shape[0], x.shape[1], -1) + self.scale_shift_table.unsqueeze(\n            0\n        )\n        shift_msa, scale_msa, gate_msa, shift_mlp, scale_mlp, gate_mlp = mod.chunk(\n            6, dim=-1\n        )\n        gate_msa, gate_mlp = gate_msa.tanh(), gate_mlp.tanh()\n        scale_msa, scale_mlp = 1.0 + scale_msa, 1.0 + scale_mlp\n\n        bulk_dtype = self.attn.to_q.weight.dtype\n        attn_in = (self.norm1(x) * scale_msa + shift_msa).to(bulk_dtype)\n        attn_out = self.attn(\n            attn_in,\n            freqs_cis,\n            attention_mask=attention_mask,","sourceCodeStart":310,"sourceCodeEnd":346,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/models/dits/lingbot_video_moe.py#L310-L346","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Expand per-sample temb6 to token level before the call: temb6 = temb6[:, None, :].expand(B, S, -1).reshape(B*S, -1)","Verify the packing step in the parent model produces (B*S, 6D), matching how x was reshaped","Keep x and temb6 derived from the same view/reshape of the packed sequence"],"exampleFix":"# before\nx = x.reshape(B * S, D, ...)  # block receives (B,S,D) but temb6 stays (B, 6D)\n\n# after\ntemb6 = temb6[:, None, :].expand(B, S, -1).reshape(B * S, -1)\nout = block(x, temb6, freqs_cis, ...)","handlingStrategy":"validation","validationCode":"B, S, _ = x.shape\\nassert temb6.ndim == 2 and temb6.shape[0] == B * S, f'{tuple(temb6.shape)} vs x {tuple(x.shape)}'","typeGuard":"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]","tryCatchPattern":null,"preventionTips":["Expand temb to token level immediately after reshaping x","Write a helper expand_temb(temb, B, S) used by all blocks","Unit-test shapes with dummy tensors"],"tags":["shape-validation","timestep-embedding","lingbot","video-diffusion"],"backgroundTag":"tensor-shape-mismatch","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}