{"record":{"id":"caf739a384137fed","repo":"unslothai/unsloth","slug":"prompts-supports-at-most-max-batch-images-entrie","errorCode":null,"errorMessage":"prompts supports at most {MAX_BATCH_IMAGES} entries per call","messagePattern":"prompts supports at most (.+?) entries per call","errorType":"validation","errorClass":"ValueError","httpStatus":400,"severity":"error","filePath":"studio/backend/core/inference/diffusion_batched.py","lineNumber":64,"sourceCode":"    batch_size: int,\n    draw_seed: Callable[[], int],\n) -> tuple[list[tuple[str, int]], int]:\n    \"\"\"The per-image ``(prompt, seed)`` jobs plus the base seed for this call.\n\n    - ``prompts`` (list): one image per prompt. With ``seeds`` too, lengths must\n      match (seed i drives prompt i); without, seeds derive from the base.\n    - ``seeds`` (list) alone: one image per seed, all with ``prompt``.\n    - neither: ``batch_size`` images of ``prompt`` with derived seeds\n      base..base+batch_size-1 (each masked JSON-safe).\n\n    ``draw_seed`` supplies a fresh random base when the caller sent none (the\n    engine passes a ``torch.Generator`` draw). Raises ``ValueError`` on empty /\n    oversized lists, a length mismatch, or an out-of-range seed.\"\"\"\n    if prompts is not None:\n        if not prompts or not all(isinstance(p, str) and p.strip() for p in prompts):\n            raise ValueError(\"prompts must be a non-empty list of non-empty strings\")\n        if len(prompts) > MAX_BATCH_IMAGES:\n            raise ValueError(f\"prompts supports at most {MAX_BATCH_IMAGES} entries per call\")\n    if seeds is not None:\n        if not seeds:\n            raise ValueError(\"seeds must be a non-empty list of integers\")\n        if len(seeds) > MAX_BATCH_IMAGES:\n            raise ValueError(f\"seeds supports at most {MAX_BATCH_IMAGES} entries per call\")\n        seeds = [int(s) for s in seeds]\n        if any(s < 0 or s > SEED_MASK for s in seeds):\n            raise ValueError(\"every seed must be between 0 and 2**53 - 1 (JSON-safe)\")\n        if prompts is not None and len(seeds) != len(prompts):\n            raise ValueError(\n                f\"prompts and seeds must have the same length \"\n                f\"(got {len(prompts)} prompts, {len(seeds)} seeds)\"\n            )\n\n    if prompts is not None:\n        count = len(prompts)\n    elif seeds is not None:\n        count = len(seeds)","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/unslothai/unsloth/blob/203007d19051dcd2ae33876786d117c99f6b0368/studio/backend/core/inference/diffusion_batched.py#L46-L82","documentation":"The prompts list is capped at MAX_BATCH_IMAGES = 32 entries per call. This bounds VRAM and time for one request; anything longer is a ValueError before generation starts. Send multiple calls if you need more images.","triggerScenarios":"Calling generate with a prompts list of 33+ entries (len(prompts) > 32).","commonSituations":"Bulk generation scripts feeding a whole CSV of prompts in one request; prompt-enumeration loops (styles x subjects) exceeding 32 combinations.","solutions":["Chunk the list client-side into batches of at most 32 and issue one call per chunk.","Alternatively use the seeds list form (also capped at 32) or repeated single-prompt calls."],"exampleFix":"# before\nengine.generate(prompts=all_100_prompts)\n# after\nMAX = 32\nfor i in range(0, len(all_100_prompts), MAX):\n    engine.generate(prompts=all_100_prompts[i:i+MAX])","handlingStrategy":"validation","validationCode":"MAX_BATCH_IMAGES = 32\n\ndef chunked(seq, n=MAX_BATCH_IMAGES):\n    for i in range(0, len(seq), n):\n        yield seq[i:i+n]","typeGuard":"def within_batch_limit(prompts) -> bool:\n    return prompts is None or len(prompts) <= 32","tryCatchPattern":"try:\n    out = engine.generate(prompts=prompts)\nexcept ValueError as e:\n    if \"at most\" in str(e) and \"prompts\" in str(e):\n        out = [engine.generate(prompts=c) for c in chunked(prompts)]\n    else:\n        raise","preventionTips":["Hard-cap the prompts control at 32 entries in the UI.","Chunk bulk jobs client-side and show progress per chunk."],"tags":["diffusion","batching","limits","validation"],"backgroundTag":null,"analyzedSha":"203007d19051dcd2ae33876786d117c99f6b0368","analyzedAt":"2026-08-15T02:48:39.846Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}