sgl-project/sglang · error · ValueError

SANA-WM CFG requires negative prompt embeds.

Error message

SANA-WM CFG requires negative prompt embeds.

What it means

Raised by the SANA-WM denoising forward when classifier-free guidance is enabled (batch.do_classifier_free_guidance) but negative prompt embeds are None. CFG needs both positive and negative text conditions.

Source

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

            _first_tensor(batch.prompt_attention_mask), device=device
        )
        if pos_embeds is None:
            raise ValueError("SANA-WM denoising requires positive prompt embeds.")

        do_cfg = bool(batch.do_classifier_free_guidance)
        neg_embeds = None
        neg_mask = None
        if do_cfg:
            neg_embeds = _to_device_dtype(
                _first_tensor(server_args.pipeline_config.get_neg_prompt_embeds(batch)),
                device=device,
                dtype=target_dtype,
            )
            neg_mask = _to_device_dtype(
                _first_tensor(batch.negative_attention_mask), device=device
            )
            if neg_embeds is None:
                raise ValueError("SANA-WM CFG requires negative prompt embeds.")

            pos_embeds, neg_embeds, pos_mask, neg_mask = (
                _align_sana_wm_cfg_text_conditions(
                    pos_embeds, neg_embeds, pos_mask, neg_mask
                )
            )

        extra = batch.extra or {}
        diffusers_kwargs = extra.get("diffusers_kwargs", {})
        if not isinstance(diffusers_kwargs, dict):
            diffusers_kwargs = {}
        chunk_kwargs = {}
        for key in ("chunk_index", "chunk_size", "chunk_split_strategy"):
            value = extra.get(key, diffusers_kwargs.get(key))
            if value is not None:
                chunk_kwargs[key] = value
        camera_conditions = _to_device_dtype(
            extra.get("camera_conditions"), device=device, dtype=target_dtype

View on GitHub (pinned to 0132848349)

Solutions

  1. Provide a negative prompt (even a plain '' encoded through the text encoder) so embeds exist
  2. Or disable CFG: set do_classifier_free_guidance=False on the request
  3. Ensure the text stage encodes both positive and negative prompts when CFG is on

Example fix

# before
request.do_classifier_free_guidance = True  # no negative prompt set
# after
request.negative_prompt = request.negative_prompt or ''
request.do_classifier_free_guidance = bool(request.negative_prompt)
Defensive patterns

Strategy: validation

Validate before calling

if batch.do_classifier_free_guidance:
    assert _first_tensor(batch.negative_prompt_embeds) is not None

Type guard

def cfg_ready(batch) -> bool:
    return not batch.do_classifier_free_guidance or getattr(batch, 'negative_prompt_embeds', None) is not None

Prevention

When it happens

Trigger: Enabling CFG on a request that has no negative prompt, or where the negative prompt embeds were not computed/attached by the text stage.

Common situations: do_classifier_free_guidance defaults true while negative_prompt is empty; negative-prompt encoding branch skipped; field name mismatch for negative embeds.

Related errors


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