sgl-project/sglang · error · ValueError

seed list length must match num_outputs_per_prompt ({num_vid

Error message

seed list length must match num_outputs_per_prompt ({num_videos_per_prompt}), got {len(seed)}

What it means

When the seed argument is passed as a list, its length must equal num_videos_per_prompt (the number of outputs generated per prompt); the stage builds one seed per output. Any other length is rejected to keep the seed-to-output mapping deterministic.

Source

Thrown at python/sglang/multimodal_gen/runtime/pipelines_core/stages/input_validation.py:98

        prompt_count = len(batch.prompt) if isinstance(batch.prompt, list) else 1
        dynamic_batch_seeds = batch.extra.get("dynamic_batch_seeds")

        if dynamic_batch_seeds is not None:
            if (
                not isinstance(dynamic_batch_seeds, list)
                or len(dynamic_batch_seeds) != prompt_count
            ):
                raise ValueError(
                    "dynamic_batch_seeds must be a list with one seed per prompt"
                )
            base_seeds = [int(item) for item in dynamic_batch_seeds]
            seeds = []
            for base_seed in base_seeds:
                seeds.extend([base_seed + i for i in range(num_videos_per_prompt)])
        elif isinstance(seed, list):
            if len(seed) != num_videos_per_prompt:
                raise ValueError(
                    f"seed list length must match num_outputs_per_prompt "
                    f"({num_videos_per_prompt}), got {len(seed)}"
                )
            seeds = [int(item) for item in seed]
        else:
            # Keep per-prompt seed streams deterministic and non-overlapping.
            base_seeds = [
                int(seed) + i * num_videos_per_prompt for i in range(prompt_count)
            ]
            seeds = []
            for base_seed in base_seeds:
                seeds.extend([base_seed + i for i in range(num_videos_per_prompt)])
        batch.seeds = seeds

        # Create generators based on generator_device parameter
        # Note: This will overwrite any existing batch.generator
        generator_device = batch.generator_device
        if generator_device is None:

View on GitHub (pinned to 0132848349)

Solutions

  1. Either pass a single int seed instead of a list for the common one-output case, or make len(seed) == num_videos_per_prompt
  2. If you want per-prompt seeds with multiple prompts, use dynamic_batch_seeds instead of a seed list

Example fix

// before
out = pipe(prompt="sunset", seed=[1, 2], num_videos_per_prompt=1)

// after
out = pipe(prompt="sunset", seed=[1, 2], num_videos_per_prompt=2)
Defensive patterns

Strategy: validation

Validate before calling

if isinstance(seed, list):
    assert len(seed) == num_videos_per_prompt, f"need {num_videos_per_prompt} seeds, got {len(seed)}"

Type guard

def valid_seed_list(seed, n: int) -> bool:
    return not isinstance(seed, list) or len(seed) == n

Prevention

When it happens

Trigger: Calling generation with seed=[s1, s2] (or an empty list) while num_videos_per_prompt=1 (the default), or setting num_videos_per_prompt=4 but providing fewer seeds.

Common situations: Copying seed lists from multi-output examples into default single-output requests; changing num_outputs/num_videos_per_prompt without adjusting the seed list; confusing per-prompt seeds (dynamic_batch_seeds) with per-output seeds.

Related errors


AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28). Data as JSON: /api/errors/b336d85e8ff82ae8. Report an issue: GitHub.