{"record":{"id":"30496591ac75f15c","repo":"sgl-project/sglang","slug":"qwenimageeditplus-expects-either-one-shared-condit","errorCode":null,"errorMessage":"QwenImageEditPlus expects either one shared condition image or the same number of condition images and prompts.","messagePattern":"QwenImageEditPlus expects either one shared condition image or the same number of condition images and prompts\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/configs/pipeline_configs/qwen_image.py","lineNumber":99,"sourceCode":"    if images is None:\n        return []\n    return images if isinstance(images, list) else [images]\n\n\ndef _build_qwen_edit_image_prompt(num_images: int) -> str:\n    img_prompt_template = \"Picture {}: <|vision_start|><|image_pad|><|vision_end|>\"\n    return \"\".join(img_prompt_template.format(i + 1) for i in range(num_images))\n\n\ndef _resolve_qwen_edit_per_prompt_images(prompt_list, image_list):\n    if len(prompt_list) <= 1:\n        return [image_list]\n\n    if len(image_list) <= 1:\n        return [list(image_list) for _ in prompt_list]\n\n    if len(image_list) != len(prompt_list):\n        raise ValueError(\n            \"QwenImageEditPlus expects either one shared condition image or \"\n            \"the same number of condition images and prompts.\"\n        )\n\n    return [[image] for image in image_list]\n\n\ndef _shard_qwen_edit_img_cache_for_sp(\n    img_cache: torch.Tensor, noisy_img_seq_len: int, device: torch.device\n) -> torch.Tensor:\n    noisy_img_cache = shard_rotary_emb_for_sp(img_cache[:noisy_img_seq_len, :])\n    condition_img_cache = shard_rotary_emb_for_sp(img_cache[noisy_img_seq_len:, :])\n    return torch.cat([noisy_img_cache, condition_img_cache], dim=0).to(device=device)\n\n\ndef _shard_qwen_edit_freqs_cis_for_sp(freqs_cis, noisy_img_seq_len, device):\n    if isinstance(freqs_cis[0], torch.Tensor) and freqs_cis[0].dim() == 2:\n        img_cache, txt_cache = freqs_cis","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/configs/pipeline_configs/qwen_image.py#L81-L117","documentation":"QwenImageEditPlus supports exactly two valid image/prompt pairings: one shared condition image broadcast to all prompts, or a 1:1 list of condition images per prompt. Any other count mismatch (2..N-1 images vs M prompts where N != M) is rejected with this ValueError during image-processor kwargs preparation.","triggerScenarios":"Calling QwenImageEditPlus generation with e.g. 3 images and 5 prompts (neither 1 nor equal counts); passing image=[img1, img2] with a batch of 3 prompt strings.","commonSituations":"Building a batch edit request where some prompts have multiple images and others one; accidentally flattening nested image lists so the length no longer matches the prompt batch; dynamic UIs letting users attach arbitrary image counts per prompt.","solutions":["Use a single shared image broadcast to all prompts: image=[one_pil_image]","Or make counts exactly equal: len(image) == len(prompt), one image per prompt","If prompts need different image counts, run separate requests per prompt (one call per prompt with its own image list)"],"exampleFix":"# before\nimages = [img1, img2]\nprompts = [\"edit a\", \"edit b\", \"edit c\"]\npipe(prompt=prompts, image=images)  # 2 images vs 3 prompts -> error\n\n# after\nimages = [img1, img2, img3]\npipe(prompt=prompts, image=images)  # 1:1 counts","handlingStrategy":"validation","validationCode":"images, prompts = list(images), list(prompts)\nassert len(images) == 1 or len(images) == len(prompts), (\n    f\"need 1 shared image or {len(prompts)} images, got {len(images)}\")","typeGuard":null,"tryCatchPattern":"try:\n    kwargs = pipe.prepare_image_processor_kwargs(images, prompts)\nexcept ValueError as e:\n    if \"same number of condition images and prompts\" in str(e):\n        # split into per-prompt calls\n        results = [pipe(p, image=[i] if len(images) > 1 else images) for p, i in zip(prompts, images)]\n    else:\n        raise","preventionTips":["Normalize request shape client-side: broadcast single image or enforce 1:1","Log len(images) vs len(prompt) before submitting batch edits"],"tags":["qwen-image","image-editing","batch-validation","multimodal"],"backgroundTag":"batch-size-mismatch","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}