{"record":{"id":"5e09239fd06c8c6d","repo":"sgl-project/sglang","slug":"negative-prompt-negative-prompt-has-batch-siz","errorCode":null,"errorMessage":"`negative_prompt`: {negative_prompt} has batch size {len(negative_prompt)}, but `prompt`: {prompt} has batch size {batch_size}. Please make sure that passed `negative_prompt` matches the batch size of `prompt`.","messagePattern":"`negative_prompt`: (.+?) has batch size (.+?), but `prompt`: (.+?) has batch size (.+?)\\. Please make sure that passed `negative_prompt` matches the batch size of `prompt`\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/pipelines_core/stages/model_specific_stages/glm_image.py","lineNumber":1032,"sourceCode":"        prompt_embeds = prompt_embeds.repeat(1, 1, 1)\n        prompt_embeds = prompt_embeds.reshape(1, seq_len, -1)\n\n        negative_prompt_embeds = None\n        if do_classifier_free_guidance:\n            negative_prompt = \"\"\n            negative_prompt = (\n                batch_size * [negative_prompt]\n                if isinstance(negative_prompt, str)\n                else negative_prompt\n            )\n\n            if prompt is not None and type(prompt) is not type(negative_prompt):\n                raise TypeError(\n                    f\"`negative_prompt` should be the same type to `prompt`, but got {type(negative_prompt)} !=\"\n                    f\" {type(prompt)}.\"\n                )\n            elif batch_size != len(negative_prompt):\n                raise ValueError(\n                    f\"`negative_prompt`: {negative_prompt} has batch size {len(negative_prompt)}, but `prompt`:\"\n                    f\" {prompt} has batch size {batch_size}. Please make sure that passed `negative_prompt` matches\"\n                    \" the batch size of `prompt`.\"\n                )\n\n            negative_prompt_embeds = self._get_glyph_embeds(\n                negative_prompt, max_sequence_length, device, dtype\n            )\n\n            seq_len = negative_prompt_embeds.size(1)\n            negative_prompt_embeds = negative_prompt_embeds.repeat(1, 1, 1)\n            negative_prompt_embeds = negative_prompt_embeds.reshape(1, seq_len, -1)\n\n        return prompt_embeds, negative_prompt_embeds\n\n    def prepare_latents(\n        self,\n        batch_size,","sourceCodeStart":1014,"sourceCodeEnd":1050,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/pipelines_core/stages/model_specific_stages/glm_image.py#L1014-L1050","documentation":"When negative_prompt is a list, its length must equal the batch size implied by prompt. This ValueError is raised right after the type check when len(negative_prompt) != batch_size, because each batch item needs its own negative prompt embedding.","triggerScenarios":"Calling forward() with prompt as a list of length N but negative_prompt as a list of length M != N (including the common single-element [\"blurry\"] against a multi-prompt batch).","commonSituations":"Batching prompts dynamically while keeping a hardcoded one-element negative prompt list; appending prompts to a batch without extending the negative prompt list.","solutions":["Repeat the negative prompt to match batch size: negative_prompt * batch_size or [neg] * len(prompt)","Compute batch size from prompt before building the negative list","Wrap in a caller-side check comparing len(prompt) and len(negative_prompt)"],"exampleFix":"# before\npipe(prompt=[\"a cat\", \"a dog\", \"a bird\"], negative_prompt=[\"blurry\"])\n\n# after\nprompts = [\"a cat\", \"a dog\", \"a bird\"]\npipe(prompt=prompts, negative_prompt=[\"blurry\"] * len(prompts))","handlingStrategy":"validation","validationCode":"if isinstance(negative_prompt, list) and isinstance(prompt, list):\n    if len(negative_prompt) != len(prompt):\n        negative_prompt = negative_prompt[:1] * len(prompt)  # broadcast single neg","typeGuard":null,"tryCatchPattern":"except ValueError as e:\n    if \"batch size\" in str(e) and isinstance(negative_prompt, list):\n        negative_prompt = negative_prompt * batch_size\n        retry_call()\n    else:\n        raise","preventionTips":["Broadcast the negative prompt to len(prompt) in a wrapper","Never hard-code a one-element negative list for variable batches","Property-test batch sizes against negative-prompt lengths"],"tags":["glm-image","negative-prompt","batch-size","input-validation","valueerror"],"backgroundTag":"batch-size-mismatch","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}