sgl-project/sglang · error · ValueError
Invalid latent H/W computed from batch.height/width: {batch.
Error message
Invalid latent H/W computed from batch.height/width: {batch.height=} {batch.width=} {self.vae_scale_factor=} What it means
After dividing batch height/width by vae_scale_factor, the LTX-2 config checks that the resulting latent dimensions are positive. A zero or negative latent_height/latent_width means the request's resolution is smaller than one VAE latent cell. The error message includes batch.height, batch.width, and vae_scale_factor for diagnosis.
Source
Thrown at python/sglang/multimodal_gen/configs/pipeline_configs/ltx_2.py:345
- 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 "
f"{latent_height=} {latent_width=} {self.patch_size=}."
)
post_patch_h = latent_height // int(self.patch_size)
post_patch_w = latent_width // int(self.patch_size)
tokens_per_frame = int(post_patch_h) * int(post_patch_w)
if tokens_per_frame <= 0:
raise ValueError(
f"Invalid tokens_per_frame={tokens_per_frame} from "View on GitHub (pinned to 0132848349)
Solutions
- Increase the request resolution so height and width are at least vae_scale_factor (ideally a multiple of vae_scale_factor * patch_size)
- Check upstream code that computes batch.height/batch.width for truncation or unit confusion (pixels vs latent units)
- Verify vae_scale_factor is not accidentally set too large for the intended resolution
Example fix
# before batch = VideoBatch(height=64, width=64) # with vae_scale_factor=32 -> latent 2x2 (ok) but height=24 -> 0 # after batch = VideoBatch(height=768, width=1280) # latent 96x160 with vae_scale_factor=8
Defensive patterns
Strategy: validation
Validate before calling
lh = batch.height // config.vae_scale_factor; lw = batch.width // config.vae_scale_factor assert lh > 0 and lw > 0, (batch.height, batch.width, config.vae_scale_factor)
Prevention
- Enforce a minimum resolution of vae_scale_factor (ideally its multiple) at request intake
- Reject or quantize non-positive/tiny dimensions before the pipeline sees them
When it happens
Trigger: Calling shard_latents_for_sp with a batch where height or width is smaller than vae_scale_factor (e.g. height=4 with vae_scale_factor=8 yields latent_height=0), or with non-positive height/width.
Common situations: Passing thumbnails or tiny test resolutions (e.g. 64x64 with a scale factor larger than the resolution), unit tests with dummy dimensions, or resolution/aspect-ratio math bugs upstream that produce tiny dims.
Related errors
- Invalid {self.vae_scale_factor=}. Must be > 0.
- Invalid {self.patch_size=}. Must be > 0.
- Invalid spatial patching for packed token latents. Expected
- Invalid tokens_per_frame={tokens_per_frame} from {latent_hei
- LTX-2 token latents seq_len={seq_len} is not divisible by to
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/2cbcbe38a4471b86.
Report an issue: GitHub.