sgl-project/sglang · error · ValueError
condition_frame_indexes={cond_indexes} exceeds the latent fr
Error message
condition_frame_indexes={cond_indexes} exceeds the latent frame count {num_latent_frames} for num_frames={batch.num_frames} What it means
The stage computes the maximum condition_frame_index and compares it against the number of latent frames derived from batch.num_frames (after VAE temporal compression). Any conditioning frame index >= num_latent_frames is out of range for the latent tensor and is rejected.
Source
Thrown at python/sglang/multimodal_gen/runtime/pipelines_core/stages/model_specific_stages/cosmos3.py:561
pixel_input = batch.preprocessed_video.to(
device=device, dtype=vae_dtype
)
cond_indexes = Cosmos3ImagePreprocessStage._resolve_condition_indexes(
batch
)
else:
pixel_input = batch.preprocessed_image.unsqueeze(2).to(
device=device, dtype=vae_dtype
)
cond_indexes = [0]
with self.use_declared_component(component_name="vae", module=self.vae):
with torch.no_grad():
cond_latent = self._vae_encode(pixel_input).to(dtype)
max_idx = max(cond_indexes)
if max_idx >= num_latent_frames:
raise ValueError(
f"condition_frame_indexes={cond_indexes} exceeds the "
f"latent frame count {num_latent_frames} for "
f"num_frames={batch.num_frames}"
)
condition_latents = torch.zeros_like(noise)
condition_mask = torch.zeros(
batch_dim, 1, num_latent_frames, 1, 1, device=device, dtype=dtype
)
for idx in cond_indexes:
src = min(idx, cond_latent.shape[2] - 1)
condition_latents[:, :, idx, :, :] = cond_latent[:, :, src, :, :]
condition_mask[:, :, idx, :, :] = 1.0
latents = (
condition_mask * condition_latents + (1.0 - condition_mask) * noise
)
batch.extra["condition_latents"] = condition_latentsView on GitHub (pinned to 0132848349)
Solutions
- Reduce condition_frame_indexes so max index < num_latent_frames (typically (num_frames-1)//temporal_stride)
- Increase num_frames so the clip yields enough latent frames to cover the requested condition indexes
- Compute latent indexes from frame indexes with the VAE temporal compression factor before passing them
Example fix
# before sp.condition_frame_indexes = [30] # num_frames=57 -> ~8 latent frames # after sp.condition_frame_indexes = [0, 7] # within latent frame count
Defensive patterns
Strategy: validation
Validate before calling
num_latent = (batch.num_frames - 1) // temporal_stride + 1 assert max(cond_indexes) < num_latent
Type guard
def valid_cond_indexes(idxs: list[int], num_latent_frames: int) -> bool:
return bool(idxs) and max(idxs) < num_latent_frames Prevention
- Derive latent indexes from frame indexes using the VAE temporal compression factor
- Clamp condition indexes to num_latent_frames - 1 when reusing configs across clip lengths
When it happens
Trigger: Setting condition_frame_indexes in sampling params to a value >= num_latent_frames, e.g. passing frame index 30 for a short clip where the VAE compresses num_frames down to only a few latent frames.
Common situations: Reusing condition_frame_indexes tuned for long clips on short num_frames requests; forgetting the (num_frames - 1) // temporal_compression reduction when mapping frame indices to latent indices.
Related errors
- Cosmos3 action input accepts one image field; use a list or
- Cosmos3 action prompt must be a string or non-empty list
- Cosmos3 batched prompts must tokenize to the same length bec
- sound generation was requested (sound_duration > 0) but the
- action_mode is set but the loaded Cosmos3 checkpoint has no
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/e0c6dd8efedc1afc.
Report an issue: GitHub.