unslothai/unsloth · error · ValueError

prompts and seeds must have the same length (got {len(prompt

Error message

prompts and seeds must have the same length (got {len(prompts)} prompts, {len(seeds)} seeds)

What it means

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.

Source

Thrown at studio/backend/core/inference/diffusion_batched.py:74

    ``draw_seed`` supplies a fresh random base when the caller sent none (the
    engine passes a ``torch.Generator`` draw). Raises ``ValueError`` on empty /
    oversized lists, a length mismatch, or an out-of-range seed."""
    if prompts is not None:
        if not prompts or not all(isinstance(p, str) and p.strip() for p in prompts):
            raise ValueError("prompts must be a non-empty list of non-empty strings")
        if len(prompts) > MAX_BATCH_IMAGES:
            raise ValueError(f"prompts supports at most {MAX_BATCH_IMAGES} entries per call")
    if seeds is not None:
        if not seeds:
            raise ValueError("seeds must be a non-empty list of integers")
        if len(seeds) > MAX_BATCH_IMAGES:
            raise ValueError(f"seeds supports at most {MAX_BATCH_IMAGES} entries per call")
        seeds = [int(s) for s in seeds]
        if any(s < 0 or s > SEED_MASK for s in seeds):
            raise ValueError("every seed must be between 0 and 2**53 - 1 (JSON-safe)")
        if prompts is not None and len(seeds) != len(prompts):
            raise ValueError(
                f"prompts and seeds must have the same length "
                f"(got {len(prompts)} prompts, {len(seeds)} seeds)"
            )

    if prompts is not None:
        count = len(prompts)
    elif seeds is not None:
        count = len(seeds)
    else:
        count = max(1, int(batch_size))

    if seeds is not None:
        job_seeds = seeds
        base_seed = seeds[0]
    else:
        base_seed = int(seed) if seed is not None else int(draw_seed()) & SEED_MASK
        job_seeds = [(base_seed + i) & SEED_MASK for i in range(count)]

View on GitHub (pinned to 203007d190)

Solutions

  1. 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.
  2. Add an assertion before the call: assert len(prompts) == len(seeds).

Example fix

# before
engine.generate(prompts=["a", "b", "c"], seeds=[1, 2])
# after
prompts, seeds = prompts[:len(seeds)], seeds[:len(prompts)]  # explicit policy
engine.generate(prompts=prompts, seeds=seeds)
Defensive patterns

Strategy: validation

Validate before calling

if prompts is not None and seeds is not None:
    assert len(prompts) == len(seeds), f"{len(prompts)} prompts vs {len(seeds)} seeds"
# or align explicitly before the call:
n = min(len(prompts), len(seeds))
prompts, seeds = prompts[:n], seeds[:n]

Try / catch

try:
    out = engine.generate(prompts=prompts, seeds=seeds)
except ValueError as e:
    if "same length" in str(e):
        n = min(len(prompts), len(seeds))
        out = engine.generate(prompts=prompts[:n], seeds=seeds[:n])
    else:
        raise

Prevention

When it happens

Trigger: Calling generate with prompts=["a", "b", "c"] and seeds=[1, 2] (or any len(seeds) != len(prompts)).

Common situations: 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.

Related errors


AI-assisted analysis of unslothai/unsloth@203007d190 (2026-08-15). Data as JSON: /api/errors/a122f293d8d47408. Report an issue: GitHub.