sgl-project/sglang · error · ValueError

SANA-WM forward_long requires encoder_hidden_states.

Error message

SANA-WM forward_long requires encoder_hidden_states.

What it means

forward_long (SANA-WM's chunked/streaming long-video forward) requires text conditioning just like forward. Passing encoder_hidden_states=None raises immediately; there is no unconditional path.

Source

Thrown at python/sglang/multimodal_gen/runtime/models/dits/sana_wm.py:756

        encoder_attention_mask: Optional[torch.Tensor] = None,
        camera_conditions: Optional[torch.Tensor] = None,
        chunk_plucker: Optional[torch.Tensor] = None,
        *,
        kv_cache: Optional[list] = None,
        save_kv_cache: bool = True,
        start_f: Optional[int] = None,
        end_f: Optional[int] = None,
        frame_index: Optional[torch.Tensor] = None,
        **kwargs,
    ) -> Tuple[torch.Tensor, list]:
        """Streaming autoregressive forward over a chunk of latent frames.

        RoPE / camera / plücker are windowed to the chunk's GLOBAL frame range
        ``[start_f, end_f)``; a per-block 10-slot ``kv_cache`` carries recurrent
        state / concat-windows across chunks. Returns ``(out, new_cache)``.
        """
        if encoder_hidden_states is None:
            raise ValueError("SANA-WM forward_long requires encoder_hidden_states.")
        if timestep is None:
            raise ValueError("SANA-WM forward_long requires timestep.")

        if kv_cache is None:
            kv_cache = [[None] * _NUM_STREAM_CACHE_SLOTS for _ in self.blocks]

        B, C, T_raw, H_raw, W_raw = hidden_states.shape
        p_t, p_h, p_w = self.patch_size
        T = T_raw // p_t
        H = H_raw // p_h
        W = W_raw // p_w
        start = 0 if start_f is None else int(start_f)
        end = start + T if end_f is None else int(end_f)

        x = self.x_embedder(hidden_states.to(dtype=self.x_embedder.proj.weight.dtype))

        # Timestep AdaLN-single: force the framewise (B, 1, T) path so blocks
        # always apply per-frame modulation.

View on GitHub (pinned to 0132848349)

Solutions

  1. Pass encoder_hidden_states on every forward_long chunk call (same embeddings for all chunks of one generation)
  2. If unconditional generation is intended, pass zeros matching the expected embedding shape

Example fix

# before
out, cache = model.forward_long(h, t, start_f=0, end_f=16, kv_cache=cache)
# after
out, cache = model.forward_long(h, t, encoder_hidden_states=ehs, start_f=0, end_f=16, kv_cache=cache)
Defensive patterns

Strategy: validation

Validate before calling

assert encoder_hidden_states is not None before each forward_long chunk call

Prevention

When it happens

Trigger: Calling forward_long(hidden_states, timestep, start_f, end_f, ...) without encoder_hidden_states, or with a kwargs dict missing the key.

Common situations: Building a streaming generation loop and forgetting the text embeddings in the chunk-call signature; reusing a wrapper written for forward with different kwarg names.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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