{"record":{"id":"ba0ea5c5dabb6783","repo":"sgl-project/sglang","slug":"sana-wm-refiner-decoding-expects-decoded-video-sha","errorCode":null,"errorMessage":"SANA-WM refiner decoding expects decoded video shaped (B, C, T, H, W), got {tuple(frames.shape)}.","messagePattern":"SANA-WM refiner decoding expects decoded video 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":783,"sourceCode":"            (getattr(batch, \"extra\", None) or {}).get(\"sana_wm_refiner_applied\", True)\n        )\n        try:\n            return super().forward(batch, server_args)\n        finally:\n            self._drop_refiner_sink = True\n\n    @torch.no_grad()\n    def decode(\n        self,\n        latents: torch.Tensor,\n        server_args: ServerArgs,\n        *,\n        vae_dtype: torch.dtype,\n    ) -> torch.Tensor:\n        frames = super().decode(latents, server_args, vae_dtype=vae_dtype)\n        log_sana_wm_tensor_stats(\"refiner.decode.frames_with_sink\", frames)\n        if frames.ndim != 5:\n            raise ValueError(\n                \"SANA-WM refiner decoding expects decoded video shaped \"\n                f\"(B, C, T, H, W), got {tuple(frames.shape)}.\"\n            )\n        if frames.shape[2] <= 1:\n            raise ValueError(\n                \"SANA-WM refiner decoding expected a sink frame plus refined \"\n                f\"frames, got temporal length {frames.shape[2]}.\"\n            )\n        if not getattr(self, \"_drop_refiner_sink\", True):\n            log_sana_wm_tensor_stats(\"refiner.decode.frames_output\", frames)\n            return frames\n        # Match NVlabs `inference_sana_wm.py`: decode with the clean sink anchor,\n        # then drop the first frame from the returned video.\n        frames = frames[:, :, 1:].contiguous()\n        log_sana_wm_tensor_stats(\"refiner.decode.frames_output\", frames)\n        return frames\n","sourceCodeStart":765,"sourceCodeEnd":800,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/pipelines_core/stages/model_specific_stages/sana_wm/refiner.py#L765-L800","documentation":"The refiner's decode() calls the base VAE decode and verifies the result is a 5D video tensor (B, C, T, H, W). If the VAE returns a 4D image tensor or another rank, decoding cannot proceed with the sink-frame logic, so it raises with the observed shape.","triggerScenarios":"Loading an image VAE (or a VAE wrapper returning 4D) instead of the causal video VAE; a decode path that squeezes the temporal dimension for single-chunk outputs.","commonSituations":"Pointing --component_paths.vae at image VAE weights; a custom VAE wrapper normalizing outputs to 4D; config drift after changing pipeline components.","solutions":["Load the supported causal video VAE for the SANA-WM pipeline","If wrapping the VAE, preserve the 5D video output shape","Verify vae_dtype/component path configuration matches the video model"],"exampleFix":"# before\nframes = vae.decode(latents)            # returns (B, C, H, W)\n# after\nframes = vae.decode(latents.squeeze(0)).unsqueeze(0)  # keep (B, C, T, H, W)\n# or: load the causal video VAE so decode returns 5D natively","handlingStrategy":"validation","validationCode":"frames = super_decode(latents)\nif frames.ndim != 5:\n    frames = frames.unsqueeze(2) if frames.ndim == 4 else frames","typeGuard":"def is_5d_video(t) -> bool:\n    return isinstance(t, torch.Tensor) and t.ndim == 5","tryCatchPattern":"try:\n    return stage.decode(latents, server_args, vae_dtype=dt)\nexcept ValueError as e:\n    if \"(B, C, T, H, W)\" in str(e):\n        raise TypeError(f\"VAE {type(stage.vae).__name__} returns non-video output; load the causal video VAE\")\n    raise","preventionTips":["Load the causal video VAE for video pipelines","Wrap VAEs so rank is preserved end to end","Component-swap tests should assert decode output ndim"],"tags":["sana-wm","refiner","vae","decode-shape","valueerror"],"backgroundTag":"tensor-shape-mismatch","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}