sgl-project/sglang · error · ValueError

Cannot forward both `prompt`: {prompt} and `prompt_embeds`:

Error message

Cannot forward both `prompt`: {prompt} and `prompt_embeds`: {prompt_embeds}. Please make sure to only forward one of the two.

What it means

Diffusers-style mutual-exclusion check: the pipeline accepts either a raw prompt or precomputed prompt_embeds, never both. Passing both makes the intended conditioning ambiguous, so a ValueError is raised before any model call.

Source

Thrown at python/sglang/multimodal_gen/runtime/pipelines_core/stages/model_specific_stages/glm_image.py:1101

            and height % (self.vae_scale_factor * self.transformer.config.patch_size)
            != 0
            or width is not None
            and width % (self.transformer.config.patch_size) != 0
        ):
            logger.warning(
                f"`height` and `width` have to be divisible by {self.vae_scale_factor * 2} but are {height} and {width}. Dimensions will be resized accordingly"
            )

        if callback_on_step_end_tensor_inputs is not None and not all(
            k in self._callback_tensor_inputs
            for k in callback_on_step_end_tensor_inputs
        ):
            raise ValueError(
                f"`callback_on_step_end_tensor_inputs` has to be in {self._callback_tensor_inputs}, but found {[k for k in callback_on_step_end_tensor_inputs if k not in self._callback_tensor_inputs]}"
            )

        if prompt is not None and prompt_embeds is not None:
            raise ValueError(
                f"Cannot forward both `prompt`: {prompt} and `prompt_embeds`: {prompt_embeds}. Please make sure to"
                " only forward one of the two."
            )
        elif prompt is None and prompt_embeds is None:
            raise ValueError(
                "Provide either `prompt` or `prompt_embeds`. Cannot leave both `prompt` and `prompt_embeds` undefined."
            )
        elif prompt is not None and (
            not isinstance(prompt, str) and not isinstance(prompt, list)
        ):
            raise ValueError(
                f"`prompt` has to be of type `str` or `list` but is {type(prompt)}"
            )

    @property
    def guidance_scale(self):
        return self._guidance_scale

View on GitHub (pinned to 0132848349)

Solutions

  1. If using prompt_embeds, pass prompt=None
  2. If using raw text, pass prompt_embeds=None
  3. Audit shared wrapper functions so they do not forward both kwargs simultaneously

Example fix

# before
pipe(prompt="a cat", prompt_embeds=cached_embeds)

# after
pipe(prompt=None, prompt_embeds=cached_embeds)
Defensive patterns

Strategy: validation

Validate before calling

if prompt_embeds is not None:
    kwargs["prompt"] = None
assert not (kwargs.get("prompt") and kwargs.get("prompt_embeds"))

Type guard

def exactly_one_conditioning(prompt, prompt_embeds) -> bool:
    return (prompt is None) != (prompt_embeds is None)

Try / catch

except ValueError as e:
    if "Cannot forward both" in str(e):
        pipe(prompt=None, prompt_embeds=prompt_embeds)
    else:
        raise

Prevention

When it happens

Trigger: Calling forward()/check_inputs with prompt="a cat" and prompt_embeds=precomputed_tensor both set (common when caching embeddings but forgetting to drop the prompt argument).

Common situations: Optimization work that caches prompt embeddings for reuse while the original prompt kwarg is still passed through a shared call site; prompt-embedding caching layers (e.g. for repeated negative prompts) applied unconditionally.

Related errors


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