{"record":{"id":"5037de58dea92e97","repo":"sgl-project/sglang","slug":"stage-1-latent-has-z-shape-2-frames-but-sink-si","errorCode":null,"errorMessage":"Stage-1 latent has {z.shape[2]} frames but sink_size={sink_size}.","messagePattern":"Stage-1 latent has (.+?) frames but sink_size=(.+?)\\.","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":628,"sourceCode":"                    )\n\n        denoised = latent_tokens.float() - velocity_tokens.float() * raw_timestep\n        return denoised[:, n_context_tokens:, :].to(self.dtype)\n\n    @torch.inference_mode()\n    def _refine_one(\n        self,\n        latent: torch.Tensor,\n        prompt: str,\n        *,\n        fps: float,\n        seed: int,\n        sink_size: int = 1,\n    ) -> torch.Tensor:\n        device = get_local_torch_device()\n        z = latent.to(device=device, dtype=self.dtype)\n        if z.shape[2] <= sink_size:\n            raise ValueError(\n                f\"Stage-1 latent has {z.shape[2]} frames but sink_size={sink_size}.\"\n            )\n        self.log_info(\n            \"SANA-WM refiner start: latent=%s, fps=%.3f, seed=%d, \"\n            \"sink_size=%d, sigmas=%s, diagnostics=%s\",\n            tuple(z.shape),\n            fps,\n            seed,\n            sink_size,\n            STAGE_2_DISTILLED_SIGMA_VALUES,\n            \"on\" if sana_wm_diagnostics_enabled() else \"off\",\n        )\n        log_sana_wm_tensor_stats(\"refiner.input_latent\", z)\n\n        prompt_embeds, prompt_attention_mask = self._encode_prompt(prompt, device)\n\n        sigmas = torch.tensor(\n            STAGE_2_DISTILLED_SIGMA_VALUES, dtype=torch.float32, device=device","sourceCodeStart":610,"sourceCodeEnd":646,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/pipelines_core/stages/model_specific_stages/sana_wm/refiner.py#L610-L646","documentation":"_refine_one moves the stage-1 latent to device and validates that its temporal dimension (z.shape[2]) is strictly greater than sink_size (default 1). The refiner keeps the first sink_size frame(s) fixed and refines the remainder, so a latent with no refinable frames (e.g. exactly 1 frame with sink_size=1) is invalid.","triggerScenarios":"Feeding a stage-1 latent whose frame count equals or is below sink_size (a single-frame latent with the default sink_size=1), or configuring a larger sink_size than frames-1.","commonSituations":"Testing the refiner with a tiny 1-frame dummy latent; still/image mode where stage 1 emitted a sink-only latent; misconfigured sink_size in the refiner options.","solutions":["Feed a stage-1 latent with at least sink_size+1 frames (typically a full video latent)","If intentionally refining single frames, lower sink_size below the frame count","Check the stage-1 generation config produced the expected temporal length"],"exampleFix":"# before\nz = torch.randn(1, 16, 1, 32, 32)  # 1 frame, sink_size=1\nrefined = stage._refine_one(z, fps=25.0, seed=0)\n# after\nz = torch.randn(1, 16, 33, 32, 32)  # sink + 32 refinable frames\nrefined = stage._refine_one(z, fps=25.0, seed=0)","handlingStrategy":"validation","validationCode":"sink = stage.sink_size if hasattr(stage, \"sink_size\") else 1\nassert latent.shape[2] > sink, f\"need >{sink} frames, got {latent.shape[2]}\"","typeGuard":"def refinable(latent: torch.Tensor, sink_size: int = 1) -> bool:\n    return latent.ndim == 5 and latent.shape[2] > sink_size","tryCatchPattern":"try:\n    refined = stage._refine_one(latent, fps=fps, seed=seed)\nexcept ValueError:\n    refined = latent  # skip refinement for degenerate clips\n    log.warning(\"skipping SANA-WM refine: too few frames\")","preventionTips":["Generate stage-1 latents with the full configured temporal length","Validate frame counts right after stage 1","Keep sink_size < generated_frames - 1 in config review"],"tags":["sana-wm","refiner","latent-shape","sink-frame","valueerror"],"backgroundTag":"tensor-shape-mismatch","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}