{"record":{"id":"a122f293d8d47408","repo":"unslothai/unsloth","slug":"prompts-and-seeds-must-have-the-same-length-got","errorCode":null,"errorMessage":"prompts and seeds must have the same length (got {len(prompts)} prompts, {len(seeds)} seeds)","messagePattern":"prompts and seeds must have the same length \\(got (.+?) prompts, (.+?) seeds\\)","errorType":"validation","errorClass":"ValueError","httpStatus":400,"severity":"error","filePath":"studio/backend/core/inference/diffusion_batched.py","lineNumber":74,"sourceCode":"\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)\n    else:\n        count = max(1, int(batch_size))\n\n    if seeds is not None:\n        job_seeds = seeds\n        base_seed = seeds[0]\n    else:\n        base_seed = int(seed) if seed is not None else int(draw_seed()) & SEED_MASK\n        job_seeds = [(base_seed + i) & SEED_MASK for i in range(count)]\n","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/unslothai/unsloth/blob/203007d19051dcd2ae33876786d117c99f6b0368/studio/backend/core/inference/diffusion_batched.py#L56-L92","documentation":"When both prompts and seeds lists are supplied, their lengths must match because seed i drives prompt i — the pairing is positional. A mismatch would either drop prompts or mis-assign seeds, so it is rejected up front with both counts in the message.","triggerScenarios":"Calling generate with prompts=[\"a\", \"b\", \"c\"] and seeds=[1, 2] (or any len(seeds) != len(prompts)).","commonSituations":"Client builds prompts from one source (product list) and seeds from another (saved favorites) and they drift; a prompt added in the UI without a matching locked seed; off-by-one after filtering prompts but not seeds.","solutions":["Align the lists: either truncate/pad the shorter one explicitly, or derive seeds from a base (omit seeds) if per-prompt pinning is not needed.","Add an assertion before the call: assert len(prompts) == len(seeds)."],"exampleFix":"# before\nengine.generate(prompts=[\"a\", \"b\", \"c\"], seeds=[1, 2])\n# after\nprompts, seeds = prompts[:len(seeds)], seeds[:len(prompts)]  # explicit policy\nengine.generate(prompts=prompts, seeds=seeds)","handlingStrategy":"validation","validationCode":"if prompts is not None and seeds is not None:\n    assert len(prompts) == len(seeds), f\"{len(prompts)} prompts vs {len(seeds)} seeds\"\n# or align explicitly before the call:\nn = min(len(prompts), len(seeds))\nprompts, seeds = prompts[:n], seeds[:n]","typeGuard":null,"tryCatchPattern":"try:\n    out = engine.generate(prompts=prompts, seeds=seeds)\nexcept ValueError as e:\n    if \"same length\" in str(e):\n        n = min(len(prompts), len(seeds))\n        out = engine.generate(prompts=prompts[:n], seeds=seeds[:n])\n    else:\n        raise","preventionTips":["Build prompts and seeds from the same source list so they cannot drift.","Zip-based generation: seeds derived per prompt index (base + i) avoids the second list entirely."],"tags":["diffusion","batching","seeds","validation","length-mismatch"],"backgroundTag":null,"analyzedSha":"203007d19051dcd2ae33876786d117c99f6b0368","analyzedAt":"2026-08-15T02:48:39.846Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}