sgl-project/sglang · error · ValueError
SANA-WM height/width must be divisible by the LTX-2 spatial
Error message
SANA-WM height/width must be divisible by the LTX-2 spatial stride ({h_stride}, {w_stride}); got height={batch.height}, width={batch.width}. What it means
SANA-WM's latent shape preparation requires spatial dimensions divisible by the LTX-2 VAE strides. If batch.height or batch.width isn't a multiple of the respective stride, latent dims wouldn't be integers, so prepare_latent_shape rejects the request with the exact strides and offending dimensions.
Source
Thrown at python/sglang/multimodal_gen/configs/pipeline_configs/sana_wm.py:181
return ModelDeploymentConfig(
dit_layerwise_offload_modes=("memory",),
# Conservative auto-FSDP gate for the 720p world-model path. Users
# can still force FSDP explicitly on smaller cards.
fsdp_auto_min_available_memory_gb=60,
)
# --- Latent shape ---
def prepare_latent_shape(self, batch, batch_size: int, num_frames: int):
"""
Returns 5D latent shape: (B, 128, T_latent, H_sp, W_sp).
T_latent = ceil((num_frames - 1) / temporal_stride) + 1
"""
t_stride = self.vae_stride[0]
h_stride = self.vae_stride[1]
w_stride = self.vae_stride[2] if len(self.vae_stride) > 2 else h_stride
if batch.height % h_stride != 0 or batch.width % w_stride != 0:
raise ValueError(
"SANA-WM height/width must be divisible by the LTX-2 spatial "
f"stride ({h_stride}, {w_stride}); got "
f"height={batch.height}, width={batch.width}."
)
T_latent = (num_frames - 1) // t_stride + 1
H_sp = batch.height // h_stride
W_sp = batch.width // w_stride
z_dim = self.vae_config.arch_config.latent_channels # 128
return (batch_size, z_dim, T_latent, H_sp, W_sp)
def adjust_num_frames(self, num_frames: int) -> int:
"""Ensure (num_frames - 1) is divisible by VAE temporal stride."""
t_stride = self.vae_stride[0]
if (num_frames - 1) % t_stride != 0:
adjusted = ((num_frames - 1) // t_stride) * t_stride + 1
logger.warning(View on GitHub (pinned to 0132848349)
Solutions
- Round height/width to the nearest multiple of the stride: h = round(h / h_stride) * h_stride
- Print/inspect self.vae_stride and ensure both dimensions satisfy h % h_stride == 0 and w % w_stride == 0
- Snap user input at the API boundary rather than letting raw values through
Example fix
# before pipe(height=1000, width=700) # 1000 % 32 == 16 -> error # after h_stride, w_stride = 32, 32 pipe(height=round(1000/h_stride)*h_stride, width=round(700/w_stride)*w_stride) # 992x704
Defensive patterns
Strategy: validation
Validate before calling
h_stride, w_stride = pipe.vae_stride[1], pipe.vae_stride[2] if len(pipe.vae_stride) > 2 else pipe.vae_stride[1]
if batch.height % h_stride or batch.width % w_stride:
batch.height = round(batch.height / h_stride) * h_stride
batch.width = round(batch.width / w_stride) * w_stride Try / catch
try:
latent_shape = pipe.prepare_latent_shape(batch, batch_size, num_frames)
except ValueError as e:
if "divisible by" in str(e):
batch.height = round(batch.height / h_stride) * h_stride
batch.width = round(batch.width / w_stride) * w_stride
latent_shape = pipe.prepare_latent_shape(batch, batch_size, num_frames)
else:
raise Prevention
- Snap all user-supplied resolutions to VAE stride multiples at the API boundary
- Read vae_stride from the config rather than hardcoding
When it happens
Trigger: Requesting video/image generation with height/width like 1000 (not divisible by a stride of e.g. 32), or odd sizes from arbitrary user input; mixing up the stride order when setting vae_stride.
Common situations: Free-form resolution fields in a UI; upscaling/scaling math producing non-multiple sizes; assuming any even number works when the LTX-2 VAE needs multiples of 32/64.
Related errors
- Invalid latent H/W computed from batch.height/width: {batch.
- Invalid spatial patching for packed token latents. Expected
- camera_conditions must have shape (T,20) or (B,T,20), got {t
- Video generation failed: {error_msg}
- Lost connection to server after {consecutive_errors} consecu
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/a25e9aff96c49248.
Report an issue: GitHub.