{"record":{"id":"962b288bb2d98c17","repo":"sgl-project/sglang","slug":"sana-wm-refiner-requires-batch-latents-from-stage","errorCode":null,"errorMessage":"SANA-WM refiner requires batch.latents from stage 1.","messagePattern":"SANA-WM refiner requires batch\\.latents from stage 1\\.","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":711,"sourceCode":"                height=noisy.shape[3],\n                width=noisy.shape[4],\n                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)","sourceCodeStart":693,"sourceCodeEnd":729,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/pipelines_core/stages/model_specific_stages/sana_wm/refiner.py#L693-L729","documentation":"The refiner's forward() requires batch.latents to be set by the preceding stage-1 generation stage. If batch.latents is None the refiner has nothing to refine, so it fails fast with this ValueError rather than producing garbage.","triggerScenarios":"Running the SANA-WM refiner stage without a prior denoising stage in the pipeline, or the stage-1 output failing to write latents onto the Req (skip flag, serialization drop, or wrong pipeline wiring).","commonSituations":"Building a custom pipeline that omits the stage-1 denoiser; a conditioning/skip path that returns the batch before latents are assigned; debugging the refiner in isolation with a hand-built Req.","solutions":["Ensure the stage-1 SANA-WM denoising stage runs before the refiner and sets batch.latents","Verify pipeline stage ordering in pipeline_config","When unit-testing the refiner, construct batch.latents explicitly (5D tensor)"],"exampleFix":"# before\nbatch.latents = None\nrefiner.forward(batch, server_args)\n# after\nbatch.latents = stage1_denoiser.forward(batch, server_args).latents\nrefiner.forward(batch, server_args)","handlingStrategy":"validation","validationCode":"if batch.latents is None:\n    raise RuntimeError(\"stage-1 did not produce latents; check pipeline order\")","typeGuard":"null","tryCatchPattern":"try:\n    out = refiner.forward(batch, server_args)\nexcept ValueError as e:\n    if \"batch.latents\" in str(e):\n        batch = stage1.forward(batch, server_args)\n        out = refiner.forward(batch, server_args)\n    else:\n        raise","preventionTips":["Assert required Req fields between pipeline stages in tests","Keep a canonical pipeline builder rather than assembling stages ad hoc","Log batch.latents presence at stage boundaries when debugging"],"tags":["sana-wm","refiner","missing-latents","pipeline-order","valueerror"],"backgroundTag":"missing-pipeline-input","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}