{"record":{"id":"328055f1941961fd","repo":"sgl-project/sglang","slug":"sana-wm-denoising-expects-5d-latents-shaped-b-c","errorCode":null,"errorMessage":"SANA-WM denoising expects 5D latents shaped (B, C, T, H, W), got {tuple(batch.latents.shape)}.","messagePattern":"SANA-WM denoising expects 5D latents shaped \\(B, C, T, H, W\\), got (.+?)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/pipelines_core/stages/model_specific_stages/sana_wm/base.py","lineNumber":828,"sourceCode":"    def _combine_cfg_parallel_noise(\n        noise_pred: torch.Tensor,\n        guidance_scale: float,\n        cfg_rank: int,\n    ) -> torch.Tensor:\n        if cfg_rank == 0:\n            partial = guidance_scale * noise_pred\n        elif cfg_rank == 1:\n            partial = (1.0 - guidance_scale) * noise_pred\n        else:\n            partial = torch.zeros_like(noise_pred)\n        return cfg_model_parallel_all_reduce(partial)\n\n    @torch.no_grad()\n    def forward(self, batch: Req, server_args: ServerArgs) -> Req:\n        if batch.latents is None:\n            raise ValueError(\"SANA-WM denoising requires initialized latents.\")\n        if batch.latents.ndim != 5:\n            raise ValueError(\n                \"SANA-WM denoising expects 5D latents shaped (B, C, T, H, W), \"\n                f\"got {tuple(batch.latents.shape)}.\"\n            )\n\n        device = get_local_torch_device()\n        target_dtype = PRECISION_TO_TYPE.get(\n            getattr(server_args.pipeline_config, \"dit_precision\", \"bf16\"),\n            torch.bfloat16,\n        )\n        scheduler = getattr(\n            batch, \"scheduler\", None\n        ) or get_or_create_request_scheduler(batch, self.scheduler)\n        self._move_scheduler_tensors_to_device(scheduler, device)\n        timesteps = batch.timesteps\n        if timesteps is None:\n            raise ValueError(\"SANA-WM denoising requires prepared timesteps.\")\n        timesteps = timesteps.to(device=device)\n","sourceCodeStart":810,"sourceCodeEnd":846,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/pipelines_core/stages/model_specific_stages/sana_wm/base.py#L810-L846","documentation":"Raised by the SANA-WM denoising forward when batch.latents.ndim != 5. The video denoiser expects latents shaped (B, C, T, H, W).","triggerScenarios":"Latents of shape (C,T,H,W) (missing batch dim), (B,C,H,W) (image latents, missing time), or (B,T,H,W) passed into the denoising stage.","commonSituations":"Image-pipeline latents reused for the video pipeline; a stage dropped or never added the batch dimension; conditioning latents prepared as 4D.","solutions":["Add the batch dim: latents = latents.unsqueeze(0) if 4D","Verify the latent-init stage produces 5D output (B,C,T,H,W)","For image-only conditioning, expand T=1 rather than dropping the axis"],"exampleFix":"# before\nlatents = latents  # (C,T,H,W)\n# after\nlatents = latents.unsqueeze(0)  # (1,C,T,H,W)","handlingStrategy":"type-guard","validationCode":"assert batch.latents is not None and batch.latents.ndim == 5","typeGuard":"def latents_5d(batch) -> bool:\n    l = getattr(batch, 'latents', None)\n    return l is not None and l.ndim == 5","tryCatchPattern":null,"preventionTips":["Unsqueeze batch dim in custom latent-prep code","Unit-test latent shapes from every producing stage"],"tags":["latents","shape-validation","sana-wm"],"backgroundTag":"tensor-shape-mismatch","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}