{"record":{"id":"a927ec4dea61634d","repo":"sgl-project/sglang","slug":"cannot-forward-both-prompt-prompt-and-prompt","errorCode":null,"errorMessage":"Cannot forward both `prompt`: {prompt} and `prompt_embeds`: {prompt_embeds}. Please make sure to only forward one of the two.","messagePattern":"Cannot forward both `prompt`: (.+?) and `prompt_embeds`: (.+?)\\. Please make sure to only forward one of the two\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/pipelines_core/stages/model_specific_stages/glm_image.py","lineNumber":1101,"sourceCode":"            and height % (self.vae_scale_factor * self.transformer.config.patch_size)\n            != 0\n            or width is not None\n            and width % (self.transformer.config.patch_size) != 0\n        ):\n            logger.warning(\n                f\"`height` and `width` have to be divisible by {self.vae_scale_factor * 2} but are {height} and {width}. Dimensions will be resized accordingly\"\n            )\n\n        if callback_on_step_end_tensor_inputs is not None and not all(\n            k in self._callback_tensor_inputs\n            for k in callback_on_step_end_tensor_inputs\n        ):\n            raise ValueError(\n                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]}\"\n            )\n\n        if prompt is not None and prompt_embeds is not None:\n            raise ValueError(\n                f\"Cannot forward both `prompt`: {prompt} and `prompt_embeds`: {prompt_embeds}. Please make sure to\"\n                \" only forward one of the two.\"\n            )\n        elif prompt is None and prompt_embeds is None:\n            raise ValueError(\n                \"Provide either `prompt` or `prompt_embeds`. Cannot leave both `prompt` and `prompt_embeds` undefined.\"\n            )\n        elif prompt is not None and (\n            not isinstance(prompt, str) and not isinstance(prompt, list)\n        ):\n            raise ValueError(\n                f\"`prompt` has to be of type `str` or `list` but is {type(prompt)}\"\n            )\n\n    @property\n    def guidance_scale(self):\n        return self._guidance_scale\n","sourceCodeStart":1083,"sourceCodeEnd":1119,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/pipelines_core/stages/model_specific_stages/glm_image.py#L1083-L1119","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["If using prompt_embeds, pass prompt=None","If using raw text, pass prompt_embeds=None","Audit shared wrapper functions so they do not forward both kwargs simultaneously"],"exampleFix":"# before\npipe(prompt=\"a cat\", prompt_embeds=cached_embeds)\n\n# after\npipe(prompt=None, prompt_embeds=cached_embeds)","handlingStrategy":"validation","validationCode":"if prompt_embeds is not None:\n    kwargs[\"prompt\"] = None\nassert not (kwargs.get(\"prompt\") and kwargs.get(\"prompt_embeds\"))","typeGuard":"def exactly_one_conditioning(prompt, prompt_embeds) -> bool:\n    return (prompt is None) != (prompt_embeds is None)","tryCatchPattern":"except ValueError as e:\n    if \"Cannot forward both\" in str(e):\n        pipe(prompt=None, prompt_embeds=prompt_embeds)\n    else:\n        raise","preventionTips":["In embedding-caching wrappers, explicitly null out prompt","Centralize the prompt vs prompt_embeds decision in one call site","Test both code paths after refactoring conditioning logic"],"tags":["glm-image","prompt-embeds","mutual-exclusion","input-validation","valueerror"],"backgroundTag":"mutually-exclusive-arguments","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}