sgl-project/sglang · error · ValueError
Expected {seq_len=} > 0 for packed token latents.
Error message
Expected {seq_len=} > 0 for packed token latents. What it means
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.
Source
Thrown at python/sglang/multimodal_gen/configs/pipeline_configs/ltx_2.py:336
# kernel runs and move bf16 output. The fp8 path makes its own copy.
return latents
def _infer_video_latent_frames_and_tokens_per_frame(
self, batch, seq_len: int
) -> tuple[int, int]:
"""Infer latent-frame count and tokens-per-frame for packed token latents [B, S, D].
Notes:
- This assumes `patch_size_t == 1` (no temporal patching).
- Tokens are ordered as (frame, height, width) after packing.
"""
if int(self.patch_size_t) != 1:
raise ValueError(
"LTX-2 SP time-sharding for packed token latents currently requires "
f"{self.patch_size_t=}. (Expected 1)"
)
if int(seq_len) <= 0:
raise ValueError(f"Expected {seq_len=} > 0 for packed token latents.")
if int(self.vae_scale_factor) <= 0:
raise ValueError(f"Invalid {self.vae_scale_factor=}. Must be > 0.")
if int(self.patch_size) <= 0:
raise ValueError(f"Invalid {self.patch_size=}. Must be > 0.")
latent_height = int(batch.height) // int(self.vae_scale_factor)
latent_width = int(batch.width) // int(self.vae_scale_factor)
if latent_height <= 0 or latent_width <= 0:
raise ValueError(
"Invalid latent H/W computed from batch.height/width: "
f"{batch.height=} {batch.width=} {self.vae_scale_factor=}"
)
if (latent_height % int(self.patch_size)) != 0 or (
latent_width % int(self.patch_size)
) != 0:
raise ValueError(
"Invalid spatial patching for packed token latents. Expected latent H/W "
"to be divisible by patch_size, got "View on GitHub (pinned to 0132848349)
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
Example fix
# before
latents = pack(latent) # may be empty for tiny inputs
shard_latents_for_sp(latents)
# after
assert latents.shape[-2] > 0, f"empty packed latents: {latents.shape}"
shard_latents_for_sp(latents) Defensive patterns
Strategy: validation
Validate before calling
seq = packed_latents.shape[-2]
assert seq > 0, f"packed latent token seq_len must be > 0, got {seq}" Try / catch
except ValueError as e:
if "seq_len" in str(e):
# re-check dims/frames and resubmit with valid resolution/frames
raise ValueError(f"invalid video geometry: {height}x{width}x{frames}") from e Prevention
- Validate height/width/frames against VAE downsampling before encode
- Never pass zero-frame or truncated videos
- Assert non-empty packed latents before SP sharding
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- LTX-2 SP time-sharding for packed token latents currently re
- Krea-2 sequence parallelism does not support ragged/padded m
- padding_side must be 'left' or 'right', got {padding_side}
- Unsupported text encoder output: expected `hidden_states`.
- num_inference_steps must be positive, got {steps}
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/abb6def915343368.
Report an issue: GitHub.