sgl-project/sglang · error · ValueError
When using multiple prompts with multiple input images, prov
Error message
When using multiple prompts with multiple input images, provide either one shared image or exactly one image per prompt.
What it means
Raised by DiffusionGenerator._resolve_image_paths_per_prompt when a list of more than one image path is supplied together with multiple prompts, but the image count does not match the prompt count. The API only supports either one shared image broadcast to all prompts, or a strict one-to-one image-per-prompt mapping. Any other combination is ambiguous and rejected before a request is sent.
Source
Thrown at python/sglang/multimodal_gen/runtime/entrypoints/diffusion_generator.py:221
"Please ensure the server is running."
)
logger.info(
f"Successfully connected to remote scheduler at "
f"{self.server_args.scheduler_endpoint}."
)
@staticmethod
def _resolve_image_paths_per_prompt(
prompts: list[str], image_paths: str | list[str] | None
) -> list[str | list[str] | None]:
if len(prompts) <= 1:
return [image_paths]
if not isinstance(image_paths, list) or len(image_paths) <= 1:
return [image_paths for _ in prompts]
if len(image_paths) != len(prompts):
raise ValueError(
"When using multiple prompts with multiple input images, "
"provide either one shared image or exactly one image per prompt."
)
return [[image_path] for image_path in image_paths]
def generate(
self,
sampling_params_kwargs: dict | None = None,
external_trace_header: dict[str, str] | None = None,
) -> GenerationResult | list[GenerationResult] | None:
"""Generate image(s)/video(s) based on the given prompt(s).
Returns a single GenerationResult for a single prompt, a list for
multiple prompts, or None when every request failed.
"""
# 1. prepare requests
prompts = self._resolve_prompts(View on GitHub (pinned to 0132848349)
Solutions
- Make len(image_paths) exactly equal to len(prompts) (one image per prompt)
- Pass a single image path (not a list) to share one image across all prompts
- Pass a single-element list [img] which is also treated as shared
- If you intended N images for 1 prompt, pass a single prompt and a list of N image paths
Example fix
# before generator.generate(prompt=["a cat", "a dog", "a bird"], image_paths=["cat.png", "dog.png"]) # after generator.generate(prompt=["a cat", "a dog", "a bird"], image_paths=["cat.png", "dog.png", "bird.png"]) # or share one image: generator.generate(prompt=["a cat", "a dog", "a bird"], image_paths="ref.png")
Defensive patterns
Strategy: validation
Validate before calling
def check_images(prompts, image_paths):
if isinstance(image_paths, list) and len(image_paths) > 1:
assert len(image_paths) == len(prompts), (
f"{len(image_paths)} images for {len(prompts)} prompts: "
"provide 1 shared image or exactly one per prompt"
) Type guard
def valid_image_arg(image_paths, n_prompts) -> bool:
if not isinstance(image_paths, list) or len(image_paths) <= 1:
return True
return len(image_paths) == n_prompts Prevention
- Validate image count vs prompt count before calling generate
- Construct prompt/image pairs from the same iterable (zip) so lengths cannot diverge
When it happens
Trigger: Calling generate(prompt=[p1,p2,p3], image_paths=[img1,img2]) (3 prompts, 2 images), or any len(image_paths)>1 list whose length differs from len(prompts).
Common situations: Passing a directory scan or glob of images with a differently-sized prompt list; off-by-one when building prompt/image pairs from a dataframe; assuming images are consumed round-robin across prompts.
Related errors
- Unsupported image type: {type(image)}
- generate_action requires an ACTION pipeline, got {sampling_p
- {key}.position_ids is required
- {key}.{field} is required
- You have to specify input_ids
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/77778cc3ee077807.
Report an issue: GitHub.