{"record":{"id":"28bcd1066702b14b","repo":"sgl-project/sglang","slug":"sana-wm-realtime-denoising-expects-this-tick-s-pre","errorCode":null,"errorMessage":"SANA-WM realtime denoising expects this tick's pre-noised chunk latents (B, C, n, H, W) from the latent-preparation stage.","messagePattern":"SANA-WM realtime denoising expects this tick's pre-noised chunk latents \\(B, C, n, H, W\\) from the latent-preparation stage\\.","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":247,"sourceCode":"        )\n\n    @staticmethod\n    def _evict_stale_kv_cache(\n        kv_cache: list,\n        chunk_idx: int,\n        valid: list[int],\n        num_cached_blocks: int,\n        num_blocks: int,\n    ) -> None:\n        SanaWMSelfForcingSampler.evict_stale_kv_cache(\n            kv_cache, chunk_idx, valid, num_cached_blocks, num_blocks\n        )\n\n    # Realtime per-chunk path (sessions): per-session state in RealtimeCausalDiTState.\n    @torch.no_grad()\n    def _forward_realtime_chunk(self, batch: Req, server_args: ServerArgs) -> Req:\n        if batch.latents is None or batch.latents.ndim != 5:\n            raise ValueError(\n                \"SANA-WM realtime denoising expects this tick's pre-noised chunk \"\n                \"latents (B, C, n, H, W) from the latent-preparation stage.\"\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        if batch.session is None:\n            raise ValueError(\"SANA-WM realtime denoising requires a realtime session\")\n        state = get_realtime_causal_dit_state(batch.session)\n        if batch.block_idx == 0 and state.latents is not None:\n            state.dispose()  # session restart on chunk 0 (mirrors the base stage)\n\n        sc = self._resolve_stream_conditioning(\n            batch, server_args, device=device, target_dtype=target_dtype\n        )\n        sampler_cfg = sc.sampler_cfg","sourceCodeStart":229,"sourceCodeEnd":265,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/pipelines_core/stages/model_specific_stages/sana_wm/streaming.py#L229-L265","documentation":"_forward_realtime_chunk requires batch.latents to be a 5D (B, C, n, H, W) tensor of pre-noised chunk latents produced by the latent-preparation stage of the realtime streaming pipeline. None or wrong rank means the realtime tick's input is missing/malformed.","triggerScenarios":"Dispatching a realtime session chunk before the latent-preparation stage ran, or that stage failing silently; feeding offline-style 4D latents into the realtime path; batch.latents dropped during Req serialization for the session tick.","commonSituations":"Wiring the streaming denoiser directly after conditioning without the latent-prep stage; a session-restart race where chunk 0 arrives without fresh latents; a preprocessing bug squeezing the chunk dim.","solutions":["Confirm the latent-preparation stage runs before the streaming denoiser for every tick","Validate batch.latents is not None and ndim==5 at the tick boundary before dispatch","Re-run the tick after a session restart so latents are re-prepared"],"exampleFix":"# before\nresp = streaming_stage.forward(tick_batch, server_args)  # latents None\n# after\ntick_batch = latent_prep_stage.forward(tick_batch, server_args)  # sets 5D latents\nresp = streaming_stage.forward(tick_batch, server_args)","handlingStrategy":"validation","validationCode":"if batch.latents is None or batch.latents.ndim != 5:\n    batch = latent_prep_stage.forward(batch, server_args)\nassert batch.latents is not None and batch.latents.ndim == 5","typeGuard":"def has_realtime_chunk_latents(b) -> bool:\n    return b.latents is not None and b.latents.ndim == 5","tryCatchPattern":"try:\n    resp = stage.forward(batch, server_args)\nexcept ValueError as e:\n    if \"pre-noised chunk latents\" in str(e):\n        batch = latent_prep_stage.forward(batch, server_args)\n        resp = stage.forward(batch, server_args)\n    else:\n        raise","preventionTips":["Make latent-preparation a mandatory stage in realtime pipelines","Reset/re-prepare latents on session restart before chunk 0","Assert tick inputs in integration tests"],"tags":["sana-wm","streaming","realtime","latents","valueerror"],"backgroundTag":"missing-pipeline-input","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}