{"record":{"id":"ddc945ec116aed54","repo":"sgl-project/sglang","slug":"sana-wm-streaming-denoising-expects-5d-latents-b","errorCode":null,"errorMessage":"SANA-WM streaming denoising expects 5D latents (B, C, T, H, W).","messagePattern":"SANA-WM streaming denoising expects 5D latents \\(B, C, T, H, W\\)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/pipelines_core/stages/model_specific_stages/sana_wm/streaming.py","lineNumber":541,"sourceCode":"            do_cfg=do_cfg,\n            embeds=embeds_in,\n            mask=mask_in,\n            camera=cam_in,\n            plucker=plk_in,\n        )\n\n    @torch.no_grad()\n    def forward(self, batch: Req, server_args: ServerArgs) -> Req:\n        # LingBot-style dispatch: realtime sessions denoise ONE chunk per call\n        # with per-session state; otherwise run the whole clip offline.\n        if batch.session is not None:\n            return self._forward_realtime_chunk(batch, server_args)\n        return self._forward_offline(batch, server_args)\n\n    @torch.no_grad()\n    def _forward_offline(self, batch: Req, server_args: ServerArgs) -> Req:\n        if batch.latents is None or batch.latents.ndim != 5:\n            raise ValueError(\n                \"SANA-WM streaming denoising expects 5D latents (B, C, T, H, W).\"\n            )\n\n        pcfg = server_args.pipeline_config\n        device = get_local_torch_device()\n        target_dtype = PRECISION_TO_TYPE.get(\n            getattr(pcfg, \"dit_precision\", \"bf16\"), torch.bfloat16\n        )\n\n        # .clone() detaches from the loader's InferenceMode tensor so the\n        # per-chunk in-place latent updates below are allowed.\n        latents = batch.latents.to(device=device, dtype=target_dtype).clone()\n        init_latents = latents.clone()\n        B, C, total_frames, H, W = latents.shape\n\n        def _iload(_name):\n            return torch.load(f\"{_SANAWM_INJECT_DIR}/{_name}.pt\", map_location=device)\n","sourceCodeStart":523,"sourceCodeEnd":559,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/pipelines_core/stages/model_specific_stages/sana_wm/streaming.py#L523-L559","documentation":"The offline streaming forward (_forward_offline) requires batch.latents to be a 5D (B, C, T, H, W) tensor. None or non-5D latents mean the noise/latent initialization expected by the streaming denoiser is missing or malformed.","triggerScenarios":"Invoking the streaming stage offline without a prior stage creating initial latents; passing image-style 4D latents; a tensor path that squeezed the temporal dim.","commonSituations":"Running the streaming model in offline/batch mode with a hand-built Req; reusing an image pipeline's latent init; a shape-normalizing wrapper between stages.","solutions":["Initialize latents as (B, C, T, H, W) before calling the streaming stage (typical T from duration/fps config)","Unsqueeze squeezed temporal dims","Use the provided latent-init stage rather than manual construction where possible"],"exampleFix":"# before\nbatch.latents = init_noise(b, c, h, w)  # 4D\n# after\nbatch.latents = init_noise(b, c, t, h, w)  # 5D, t = num latent frames","handlingStrategy":"validation","validationCode":"assert batch.latents is not None and batch.latents.ndim == 5, \"offline streaming needs 5D latents\"","typeGuard":"def is_5d_latents(z) -> bool:\n    return isinstance(z, torch.Tensor) and z.ndim == 5","tryCatchPattern":"try:\n    out = stage._forward_offline(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 = stage._forward_offline(batch, server_args)\n    else:\n        raise","preventionTips":["Use the pipeline's latent-init stage for offline runs","Keep tensor rank stable in transport/wrappers","Unit-test with correctly shaped fixtures"],"tags":["sana-wm","streaming","offline","latent-shape","valueerror"],"backgroundTag":"tensor-shape-mismatch","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}