sgl-project/sglang · error · ValueError
Stage-1 latent has {z.shape[2]} frames but sink_size={sink_s
Error message
Stage-1 latent has {z.shape[2]} frames but sink_size={sink_size}. What it means
_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.
Source
Thrown at python/sglang/multimodal_gen/runtime/pipelines_core/stages/model_specific_stages/sana_wm/refiner.py:628
)
denoised = latent_tokens.float() - velocity_tokens.float() * raw_timestep
return denoised[:, n_context_tokens:, :].to(self.dtype)
@torch.inference_mode()
def _refine_one(
self,
latent: torch.Tensor,
prompt: str,
*,
fps: float,
seed: int,
sink_size: int = 1,
) -> torch.Tensor:
device = get_local_torch_device()
z = latent.to(device=device, dtype=self.dtype)
if z.shape[2] <= sink_size:
raise ValueError(
f"Stage-1 latent has {z.shape[2]} frames but sink_size={sink_size}."
)
self.log_info(
"SANA-WM refiner start: latent=%s, fps=%.3f, seed=%d, "
"sink_size=%d, sigmas=%s, diagnostics=%s",
tuple(z.shape),
fps,
seed,
sink_size,
STAGE_2_DISTILLED_SIGMA_VALUES,
"on" if sana_wm_diagnostics_enabled() else "off",
)
log_sana_wm_tensor_stats("refiner.input_latent", z)
prompt_embeds, prompt_attention_mask = self._encode_prompt(prompt, device)
sigmas = torch.tensor(
STAGE_2_DISTILLED_SIGMA_VALUES, dtype=torch.float32, device=deviceView on GitHub (pinned to 0132848349)
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
Example fix
# before z = torch.randn(1, 16, 1, 32, 32) # 1 frame, sink_size=1 refined = stage._refine_one(z, fps=25.0, seed=0) # after z = torch.randn(1, 16, 33, 32, 32) # sink + 32 refinable frames refined = stage._refine_one(z, fps=25.0, seed=0)
Defensive patterns
Strategy: validation
Validate before calling
sink = stage.sink_size if hasattr(stage, "sink_size") else 1
assert latent.shape[2] > sink, f"need >{sink} frames, got {latent.shape[2]}" Type guard
def refinable(latent: torch.Tensor, sink_size: int = 1) -> bool:
return latent.ndim == 5 and latent.shape[2] > sink_size Try / catch
try:
refined = stage._refine_one(latent, fps=fps, seed=seed)
except ValueError:
refined = latent # skip refinement for degenerate clips
log.warning("skipping SANA-WM refine: too few frames") Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- SANA-WM refiner expects 5D latents shaped (B, C, T, H, W), g
- SANA-WM refiner requires a string prompt or one prompt per b
- SANA-WM refiner requires batch.latents from stage 1.
- SANA-WM refiner decoding expects decoded video shaped (B, C,
- SANA-WM refiner decoding expected a sink frame plus refined
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/5037de58dea92e97.
Report an issue: GitHub.