{"record":{"id":"8b1fa8fe42fb7b23","repo":"sgl-project/sglang","slug":"sana-wm-seed-list-length-must-be-1-or-match-latent","errorCode":null,"errorMessage":"SANA-WM seed list length must be 1 or match latent batch size; got {len(seed)} seeds for batch {batch_size}.","messagePattern":"SANA-WM seed list length must be 1 or match latent batch size; got (.+?) seeds for batch (.+?)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/pipelines_core/stages/model_specific_stages/sana_wm/base.py","lineNumber":1210,"sourceCode":"        seed: int | list[int] | tuple[int, ...] | None,\n        *,\n        batch_size: int,\n        device: torch.device,\n    ) -> torch.Generator | list[torch.Generator]:\n        if seed is None:\n            seed = 0\n        if isinstance(seed, (list, tuple)):\n            if not seed:\n                raise ValueError(\"SANA-WM seed list must not be empty.\")\n            if len(seed) == 1:\n                seed = seed[0]\n            elif len(seed) == batch_size:\n                return [\n                    torch.Generator(device=device).manual_seed(int(sample_seed))\n                    for sample_seed in seed\n                ]\n            else:\n                raise ValueError(\n                    \"SANA-WM seed list length must be 1 or match latent batch \"\n                    f\"size; got {len(seed)} seeds for batch {batch_size}.\"\n                )\n        return torch.Generator(device=device).manual_seed(int(seed))\n\n    @staticmethod\n    def _canonical_condition_image_tensor(image: torch.Tensor) -> torch.Tensor:\n        \"\"\"Return image as NCHW RGB float tensor without changing its value range.\"\"\"\n        image = image.float()\n        if image.dim() == 5 and image.shape[2] == 1:\n            image = image.squeeze(2)\n        if image.dim() == 3:\n            if image.shape[0] in (1, 3, 4):\n                image = image.unsqueeze(0)\n            elif image.shape[-1] in (1, 3, 4):\n                image = image.permute(2, 0, 1).unsqueeze(0)\n            else:\n                raise ValueError(","sourceCodeStart":1192,"sourceCodeEnd":1228,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/pipelines_core/stages/model_specific_stages/sana_wm/base.py#L1192-L1228","documentation":"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.","triggerScenarios":"Passing seed=[1,2,3] for a batch of 2 (or 4); seed lists whose length diverges from the latent batch size.","commonSituations":"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.","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"],"exampleFix":"# before\nseeds = [r.seed for r in requests if r.seed is not None]  # partial\n# after\nseeds = [r.seed if r.seed is not None else 0 for r in requests]  # len == batch","handlingStrategy":"validation","validationCode":"assert not isinstance(seed, (list, tuple)) or len(seed) in (1, batch_size)","typeGuard":"def seeds_match(s, batch: int) -> bool:\n    return not isinstance(s, (list, tuple)) or len(s) in (1, batch)","tryCatchPattern":null,"preventionTips":["Fill unseeded samples with 0 instead of dropping them","Compute seed lists from the final request batch"],"tags":["seed","batch-size","generator","sana-wm"],"backgroundTag":"length-mismatch","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}