sgl-project/sglang · error · ValueError

SANA-WM denoising requires initialized latents.

Error message

SANA-WM denoising requires initialized latents.

What it means

Raised by the SANA-WM denoising stage forward when batch.latents is None — the denoiser was invoked before a prior stage initialized the noise latents.

Source

Thrown at python/sglang/multimodal_gen/runtime/pipelines_core/stages/model_specific_stages/sana_wm/base.py:826

    @staticmethod
    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.")

View on GitHub (pinned to 0132848349)

Solutions

  1. Ensure the latent-initialization / before-denoising stage runs before the denoiser in the pipeline
  2. Check that _prepare_noise_latents actually assigned batch.latents
  3. Inspect pipeline stage ordering in the config
Defensive patterns

Strategy: type-guard

Validate before calling

assert batch.latents is not None, 'run the latent-init stage before denoising'

Type guard

def ready_to_denoise(batch) -> bool:
    return getattr(batch, 'latents', None) is not None

Prevention

When it happens

Trigger: Running the denoising stage without a preceding latent-init stage having set batch.latents (skipped stage in pipeline order, or first-frame conditioning failed earlier).

Common situations: Pipeline misordering (denoise before init); latent init skipped due to a conditional branch; request routed directly to the denoising stage.

Related errors


AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28). Data as JSON: /api/errors/b7f0373669e5fe3a. Report an issue: GitHub.