sgl-project/sglang · error · ValueError

SANA-WM stage-1 expects exactly one Gemma-2 text encoder.

Error message

SANA-WM stage-1 expects exactly one Gemma-2 text encoder.

What it means

Raised by the stage-1 forward when self.text_encoders does not contain exactly one entry. SANA-WM's first stage is hardwired to a single Gemma-2 text encoder for prompt embedding.

Source

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

            dim=0,
        )
        index[seq_dim] = select
        return tensor[tuple(index)]

    @staticmethod
    def _seq_lens_from_masks(masks: list[torch.Tensor | None]) -> list[list[int]]:
        seq_lens = []
        for mask in masks:
            if mask is None:
                seq_lens.append([])
            else:
                seq_lens.append([int(x) for x in mask.long().sum(dim=-1).tolist()])
        return seq_lens

    @torch.no_grad()
    def forward(self, batch: Req, server_args: ServerArgs) -> Req:
        if len(self.text_encoders) != 1:
            raise ValueError(
                "SANA-WM stage-1 expects exactly one Gemma-2 text encoder."
            )
        assert batch.prompt is not None

        max_length = self._text_encoder_max_length(server_args)
        chi_prompt = self._chi_prompt(server_args)
        prompt_text = batch.prompt
        if isinstance(prompt_text, str):
            prompt_text = [prompt_text]
        else:
            prompt_text = list(prompt_text)

        tokenizer = self.tokenizers[0]
        if chi_prompt:
            prompt_text = [chi_prompt + text for text in prompt_text]
            max_length_all = len(tokenizer.encode(chi_prompt)) + max_length - 2
        else:
            max_length_all = max_length

View on GitHub (pinned to 0132848349)

Solutions

  1. Ensure exactly one Gemma-2 text encoder is loaded/registered for the stage
  2. Check encoder loading logs for silent failures leaving the list empty
  3. Fix the model config to include only the Gemma-2 text encoder for stage 1
Defensive patterns

Strategy: validation

Validate before calling

assert len(stage.text_encoders) == 1, f'got {len(stage.text_encoders)} text encoders'

Prevention

When it happens

Trigger: Configuring the pipeline with zero text encoders (missing/failed model load) or multiple text encoders, then running a request through the SANA-WM stage-1 forward.

Common situations: Model config lists multiple encoders (e.g. adding a second text tower) or the Gemma-2 encoder failed to register during init; misconfigured encoder list in server args.

Related errors


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