sgl-project/sglang · error · ValueError
SANA-WM denoising expects 5D latents shaped (B, C, T, H, W),
Error message
SANA-WM denoising expects 5D latents shaped (B, C, T, H, W), got {tuple(batch.latents.shape)}. What it means
Raised by the SANA-WM denoising forward when batch.latents.ndim != 5. The video denoiser expects latents shaped (B, C, T, H, W).
Source
Thrown at python/sglang/multimodal_gen/runtime/pipelines_core/stages/model_specific_stages/sana_wm/base.py:828
def _combine_cfg_parallel_noise(
noise_pred: torch.Tensor,
guidance_scale: float,
cfg_rank: int,
) -> torch.Tensor:
if cfg_rank == 0:
partial = guidance_scale * noise_pred
elif cfg_rank == 1:
partial = (1.0 - guidance_scale) * noise_pred
else:
partial = torch.zeros_like(noise_pred)
return cfg_model_parallel_all_reduce(partial)
@torch.no_grad()
def forward(self, batch: Req, server_args: ServerArgs) -> Req:
if batch.latents is None:
raise ValueError("SANA-WM denoising requires initialized latents.")
if batch.latents.ndim != 5:
raise ValueError(
"SANA-WM denoising expects 5D latents shaped (B, C, T, H, W), "
f"got {tuple(batch.latents.shape)}."
)
device = get_local_torch_device()
target_dtype = PRECISION_TO_TYPE.get(
getattr(server_args.pipeline_config, "dit_precision", "bf16"),
torch.bfloat16,
)
scheduler = getattr(
batch, "scheduler", None
) or get_or_create_request_scheduler(batch, self.scheduler)
self._move_scheduler_tensors_to_device(scheduler, device)
timesteps = batch.timesteps
if timesteps is None:
raise ValueError("SANA-WM denoising requires prepared timesteps.")
timesteps = timesteps.to(device=device)
View on GitHub (pinned to 0132848349)
Solutions
- Add the batch dim: latents = latents.unsqueeze(0) if 4D
- Verify the latent-init stage produces 5D output (B,C,T,H,W)
- For image-only conditioning, expand T=1 rather than dropping the axis
Example fix
# before latents = latents # (C,T,H,W) # after latents = latents.unsqueeze(0) # (1,C,T,H,W)
Defensive patterns
Strategy: type-guard
Validate before calling
assert batch.latents is not None and batch.latents.ndim == 5
Type guard
def latents_5d(batch) -> bool:
l = getattr(batch, 'latents', None)
return l is not None and l.ndim == 5 Prevention
- Unsqueeze batch dim in custom latent-prep code
- Unit-test latent shapes from every producing stage
When it happens
Trigger: Latents of shape (C,T,H,W) (missing batch dim), (B,C,H,W) (image latents, missing time), or (B,T,H,W) passed into the denoising stage.
Common situations: Image-pipeline latents reused for the video pipeline; a stage dropped or never added the batch dimension; conditioning latents prepared as 4D.
Related errors
- camera trajectory must have shape (F, 4, 4); got {c2w.shape}
- unsupported intrinsics shape {arr.shape}; expected (4,), (3,
- SANA-WM denoising requires initialized latents.
- condition_image tensor must be CHW or HWC with 1, 3, or 4 ch
- camera_conditions must have shape (T,20) or (B,T,20), got {t
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/328055f1941961fd.
Report an issue: GitHub.