{"record":{"id":"e0c6dd8efedc1afc","repo":"sgl-project/sglang","slug":"condition-frame-indexes-cond-indexes-exceeds-the","errorCode":null,"errorMessage":"condition_frame_indexes={cond_indexes} exceeds the latent frame count {num_latent_frames} for num_frames={batch.num_frames}","messagePattern":"condition_frame_indexes=(.+?) exceeds the latent frame count (.+?) for num_frames=(.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/pipelines_core/stages/model_specific_stages/cosmos3.py","lineNumber":561,"sourceCode":"                pixel_input = batch.preprocessed_video.to(\n                    device=device, dtype=vae_dtype\n                )\n                cond_indexes = Cosmos3ImagePreprocessStage._resolve_condition_indexes(\n                    batch\n                )\n            else:\n                pixel_input = batch.preprocessed_image.unsqueeze(2).to(\n                    device=device, dtype=vae_dtype\n                )\n                cond_indexes = [0]\n\n            with self.use_declared_component(component_name=\"vae\", module=self.vae):\n                with torch.no_grad():\n                    cond_latent = self._vae_encode(pixel_input).to(dtype)\n\n            max_idx = max(cond_indexes)\n            if max_idx >= num_latent_frames:\n                raise ValueError(\n                    f\"condition_frame_indexes={cond_indexes} exceeds the \"\n                    f\"latent frame count {num_latent_frames} for \"\n                    f\"num_frames={batch.num_frames}\"\n                )\n\n            condition_latents = torch.zeros_like(noise)\n            condition_mask = torch.zeros(\n                batch_dim, 1, num_latent_frames, 1, 1, device=device, dtype=dtype\n            )\n            for idx in cond_indexes:\n                src = min(idx, cond_latent.shape[2] - 1)\n                condition_latents[:, :, idx, :, :] = cond_latent[:, :, src, :, :]\n                condition_mask[:, :, idx, :, :] = 1.0\n\n            latents = (\n                condition_mask * condition_latents + (1.0 - condition_mask) * noise\n            )\n            batch.extra[\"condition_latents\"] = condition_latents","sourceCodeStart":543,"sourceCodeEnd":579,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/pipelines_core/stages/model_specific_stages/cosmos3.py#L543-L579","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"# before\nsp.condition_frame_indexes = [30]  # num_frames=57 -> ~8 latent frames\n\n# after\nsp.condition_frame_indexes = [0, 7]  # within latent frame count","handlingStrategy":"validation","validationCode":"num_latent = (batch.num_frames - 1) // temporal_stride + 1\nassert max(cond_indexes) < num_latent","typeGuard":"def valid_cond_indexes(idxs: list[int], num_latent_frames: int) -> bool:\n    return bool(idxs) and max(idxs) < num_latent_frames","tryCatchPattern":null,"preventionTips":["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"],"tags":["cosmos3","video","frame-index","out-of-range","validation"],"backgroundTag":"index-out-of-range","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}