{"record":{"id":"abb6def915343368","repo":"sgl-project/sglang","slug":"expected-seq-len-0-for-packed-token-latents","errorCode":null,"errorMessage":"Expected {seq_len=} > 0 for packed token latents.","messagePattern":"Expected (.+?) > 0 for packed token latents\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/configs/pipeline_configs/ltx_2.py","lineNumber":336,"sourceCode":"        # kernel runs and move bf16 output. The fp8 path makes its own copy.\n        return latents\n\n    def _infer_video_latent_frames_and_tokens_per_frame(\n        self, batch, seq_len: int\n    ) -> tuple[int, int]:\n        \"\"\"Infer latent-frame count and tokens-per-frame for packed token latents [B, S, D].\n\n        Notes:\n        - This assumes `patch_size_t == 1` (no temporal patching).\n        - Tokens are ordered as (frame, height, width) after packing.\n        \"\"\"\n        if int(self.patch_size_t) != 1:\n            raise ValueError(\n                \"LTX-2 SP time-sharding for packed token latents currently requires \"\n                f\"{self.patch_size_t=}. (Expected 1)\"\n            )\n        if int(seq_len) <= 0:\n            raise ValueError(f\"Expected {seq_len=} > 0 for packed token latents.\")\n        if int(self.vae_scale_factor) <= 0:\n            raise ValueError(f\"Invalid {self.vae_scale_factor=}. Must be > 0.\")\n        if int(self.patch_size) <= 0:\n            raise ValueError(f\"Invalid {self.patch_size=}. Must be > 0.\")\n\n        latent_height = int(batch.height) // int(self.vae_scale_factor)\n        latent_width = int(batch.width) // int(self.vae_scale_factor)\n        if latent_height <= 0 or latent_width <= 0:\n            raise ValueError(\n                \"Invalid latent H/W computed from batch.height/width: \"\n                f\"{batch.height=} {batch.width=} {self.vae_scale_factor=}\"\n            )\n        if (latent_height % int(self.patch_size)) != 0 or (\n            latent_width % int(self.patch_size)\n        ) != 0:\n            raise ValueError(\n                \"Invalid spatial patching for packed token latents. Expected latent H/W \"\n                \"to be divisible by patch_size, got \"","sourceCodeStart":318,"sourceCodeEnd":354,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/configs/pipeline_configs/ltx_2.py#L318-L354","documentation":"LTX-2's _infer_video_latent_frames_and_tokens_per_frame needs a strictly positive packed-token sequence length to reconstruct latent frame geometry for SP sharding; seq_len <= 0 would divide nowhere and indicates an empty/corrupt latent.","triggerScenarios":"Calling shard_latents_for_sp with a packed latent whose token sequence length is 0 or negative — e.g. an all-padding latent, a zero-frame video, or an upstream packing bug producing an empty token dimension.","commonSituations":"Passing height/width/frame values that round down to zero latent tokens; a VAE encode returning an empty tensor; truncation/stride settings that eliminate all frames.","solutions":["Verify video dimensions produce at least one latent token: frames >= temporal stride, height/width large enough after VAE downsampling","Check the packed latent tensor shape right before sharding and abort with a clear message if seq dimension is 0","Fix upstream packing/truncation so the token dimension is non-empty"],"exampleFix":"# before\nlatents = pack(latent)  # may be empty for tiny inputs\nshard_latents_for_sp(latents)\n\n# after\nassert latents.shape[-2] > 0, f\"empty packed latents: {latents.shape}\"\nshard_latents_for_sp(latents)","handlingStrategy":"validation","validationCode":"seq = packed_latents.shape[-2]\nassert seq > 0, f\"packed latent token seq_len must be > 0, got {seq}\"","typeGuard":null,"tryCatchPattern":"except ValueError as e:\n    if \"seq_len\" in str(e):\n        # re-check dims/frames and resubmit with valid resolution/frames\n        raise ValueError(f\"invalid video geometry: {height}x{width}x{frames}\") from e","preventionTips":["Validate height/width/frames against VAE downsampling before encode","Never pass zero-frame or truncated videos","Assert non-empty packed latents before SP sharding"],"tags":["sglang","ltx-2","sequence-length","latent-packing","sequence-parallelism","video"],"backgroundTag":"invalid-parameter-range","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}