sgl-project/sglang · error · ValueError
Invalid {self.patch_size=}. Must be > 0.
Error message
Invalid {self.patch_size=}. Must be > 0. What it means
LTX-2 pipeline config requires patch_size > 0 before computing post-patch token counts for SP time-sharding of packed token latents. patch_size is used both as a divisor for latent height/width and later to compute tokens_per_frame, so a non-positive value breaks the arithmetic. This ValueError fires when the transformer patch size is 0 or negative.
Source
Thrown at python/sglang/multimodal_gen/configs/pipeline_configs/ltx_2.py:340
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 "
f"{latent_height=} {latent_width=} {self.patch_size=}."
)
post_patch_h = latent_height // int(self.patch_size)View on GitHub (pinned to 0132848349)
Solutions
- Set patch_size to the model's actual spatial patch size (commonly 2 for LTX-2 packed token latents)
- Verify the config dict key name matches what the loader expects and prints the resolved value before use
- Assert positivity of all patch fields when constructing the config
Example fix
// before config.patch_size = 0 config.shard_latents_for_sp(batch) # ValueError // after config.patch_size = 2 config.shard_latents_for_sp(batch)
Defensive patterns
Strategy: validation
Validate before calling
assert config.patch_size and int(config.patch_size) > 0, f"bad patch_size={config.patch_size}" Prevention
- Assert patch_size positivity when building/overriding the LTX-2 config
- Diff custom configs against the shipped reference config after upgrades
When it happens
Trigger: Calling shard_latents_for_sp on a config where patch_size is 0 or negative, e.g. a config dict missing the patch_size key and defaulting to 0, or a bad override.
Common situations: Hand-edited or programmatically generated LTX-2 configs that omit or corrupt patch_size; version changes that renamed the config key (e.g. patch_size vs spatial_patch_size) leaving the old key unset.
Understand the failure class
Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.
Related errors
- Invalid {self.vae_scale_factor=}. Must be > 0.
- Invalid latent H/W computed from batch.height/width: {batch.
- Invalid tokens_per_frame={tokens_per_frame} from {latent_hei
- LTX-2 token latents seq_len={seq_len} is not divisible by to
- LTX-2 SP time-sharding for packed token latents currently re
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/5b0a53f4ba22d5b9.
Report an issue: GitHub.