{"record":{"id":"0d59f0f7e642af09","repo":"sgl-project/sglang","slug":"sana-wm-refiner-expects-5d-latents-shaped-b-c-t","errorCode":null,"errorMessage":"SANA-WM refiner expects 5D latents shaped (B, C, T, H, W), got {tuple(batch.latents.shape)}.","messagePattern":"SANA-WM refiner 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/refiner.py","lineNumber":713,"sourceCode":"                patch_size=patch_size,\n                patch_size_t=patch_size_t,\n            )\n            log_sana_wm_tensor_stats(\n                f\"refiner.step_{step_idx}.velocity_current\",\n                velocity_5d.to(self.dtype),\n            )\n            log_sana_wm_tensor_stats(f\"refiner.step_{step_idx}.current_latent\", noisy)\n\n        refined = torch.cat([sink, noisy], dim=2)\n        log_sana_wm_tensor_stats(\"refiner.output_latent\", refined)\n        return refined\n\n    @torch.inference_mode()\n    def forward(self, batch: Req, server_args: ServerArgs) -> Req:\n        if batch.latents is None:\n            raise ValueError(\"SANA-WM refiner requires batch.latents from stage 1.\")\n        if batch.latents.ndim != 5:\n            raise ValueError(\n                \"SANA-WM refiner expects 5D latents shaped (B, C, T, H, W), \"\n                f\"got {tuple(batch.latents.shape)}.\"\n            )\n\n        if sana_wm_skip_refiner_enabled(batch):\n            if batch.extra is None:\n                batch.extra = {}\n            batch.extra[\"sana_wm_refiner_applied\"] = False\n            self.log_info(\n                \"SANA-WM LTX-2 refiner skipped by SGLANG_SANA_WM_SKIP_REFINER.\"\n            )\n            return batch\n\n        batch_size = int(batch.latents.shape[0])\n        prompts = self._prompts_for_batch(batch, batch_size)\n        fps = float(getattr(batch, \"fps\", 16) or 16)\n\n        seeds: list[int]","sourceCodeStart":695,"sourceCodeEnd":731,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/pipelines_core/stages/model_specific_stages/sana_wm/refiner.py#L695-L731","documentation":"forward() validates that batch.latents.ndim == 5, i.e. shaped (B, C, T, H, W) as produced by SANA-WM video generation. A 4D image-style latent or any other rank is rejected with the actual shape echoed in the message.","triggerScenarios":"Passing an image-pipeline latent (B, C, H, W) or an unsqueezed/packed tensor of the wrong rank into the video refiner; a stage that squeezes the temporal dimension (single-frame output) before the refiner.","commonSituations":"Reusing the refiner from an image pipeline; a preprocessing stage collapsing T=1 latents to 4D; latents stored/transferred through a path that drops a singleton dim.","solutions":["Keep latents 5D: unsqueeze dim 2 if the temporal axis was squeezed","Check the producing stage emits (B, C, T, H, W) video latents","If refining images, use the image-specific stage, not the SANA-WM video refiner"],"exampleFix":"# before\nbatch.latents = z_4d  # (B, C, H, W)\n# after\nbatch.latents = z_4d.unsqueeze(2)  # (B, C, 1, H, W) -- note also sink_size constraint","handlingStrategy":"type-guard","validationCode":"assert batch.latents is not None and batch.latents.ndim == 5, tuple(batch.latents.shape if batch.latents is not None else ())","typeGuard":"def is_5d_latents(z) -> bool:\n    return isinstance(z, torch.Tensor) and z.ndim == 5","tryCatchPattern":"try:\n    out = refiner.forward(batch, server_args)\nexcept ValueError as e:\n    if \"5D latents\" in str(e) and batch.latents.ndim == 4:\n        batch.latents = batch.latents.unsqueeze(2)\n        out = refiner.forward(batch, server_args)\n    else:\n        raise","preventionTips":["Standardize on (B, C, T, H, W) across all video stages","Avoid squeezing singleton temporal dims in transport code","Add shape assertions in stage unit tests"],"tags":["sana-wm","refiner","latent-shape","ndim","valueerror"],"backgroundTag":"tensor-shape-mismatch","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}