sgl-project/sglang · error · ValueError
SANA-WM seed list length must be 1 or match latent batch siz
Error message
SANA-WM seed list length must be 1 or match latent batch size; got {len(seed)} seeds for batch {batch_size}. What it means
Raised by _generator_from_seed when a seed list has length other than 1 or batch_size — either one shared seed or exactly one seed per latent sample is allowed.
Source
Thrown at python/sglang/multimodal_gen/runtime/pipelines_core/stages/model_specific_stages/sana_wm/base.py:1210
seed: int | list[int] | tuple[int, ...] | None,
*,
batch_size: int,
device: torch.device,
) -> torch.Generator | list[torch.Generator]:
if seed is None:
seed = 0
if isinstance(seed, (list, tuple)):
if not seed:
raise ValueError("SANA-WM seed list must not be empty.")
if len(seed) == 1:
seed = seed[0]
elif len(seed) == batch_size:
return [
torch.Generator(device=device).manual_seed(int(sample_seed))
for sample_seed in seed
]
else:
raise ValueError(
"SANA-WM seed list length must be 1 or match latent batch "
f"size; got {len(seed)} seeds for batch {batch_size}."
)
return torch.Generator(device=device).manual_seed(int(seed))
@staticmethod
def _canonical_condition_image_tensor(image: torch.Tensor) -> torch.Tensor:
"""Return image as NCHW RGB float tensor without changing its value range."""
image = image.float()
if image.dim() == 5 and image.shape[2] == 1:
image = image.squeeze(2)
if image.dim() == 3:
if image.shape[0] in (1, 3, 4):
image = image.unsqueeze(0)
elif image.shape[-1] in (1, 3, 4):
image = image.permute(2, 0, 1).unsqueeze(0)
else:
raise ValueError(View on GitHub (pinned to 0132848349)
Solutions
- Use a single int (or length-1 list) for a shared seed across the batch
- Or provide exactly batch_size seeds, filling unseeded samples with 0
- Compute seeds from the same request list that determines batch_size
Example fix
# before seeds = [r.seed for r in requests if r.seed is not None] # partial # after seeds = [r.seed if r.seed is not None else 0 for r in requests] # len == batch
Defensive patterns
Strategy: validation
Validate before calling
assert not isinstance(seed, (list, tuple)) or len(seed) in (1, batch_size)
Type guard
def seeds_match(s, batch: int) -> bool:
return not isinstance(s, (list, tuple)) or len(s) in (1, batch) Prevention
- Fill unseeded samples with 0 instead of dropping them
- Compute seed lists from the final request batch
When it happens
Trigger: Passing seed=[1,2,3] for a batch of 2 (or 4); seed lists whose length diverges from the latent batch size.
Common situations: Batch size recomputed after seeds set; some requests in a batch carry seeds and others don't, producing a partial list; off-by-one when chunking requests.
Related errors
- You have passed a list of generators of length {len(generato
- SANA-WM generator list length must match latent batch size;
- SANA-WM seed list must not be empty.
- You have passed a list of generators of length {len(generato
- You have passed a list of generators of length {len(generato
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/8b1fa8fe42fb7b23.
Report an issue: GitHub.