{"record":{"id":"30be86589b17a460","repo":"sgl-project/sglang","slug":"sp-sharded-ltx-2-ti2v-expected-raw-seq-len-divisib","errorCode":null,"errorMessage":"SP-sharded LTX-2 TI2V expected raw seq_len divisible by tokens_per_frame.","messagePattern":"SP-sharded LTX-2 TI2V expected raw seq_len divisible by tokens_per_frame\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"critical","filePath":"python/sglang/multimodal_gen/runtime/pipelines_core/stages/model_specific_stages/ltx_2/denoising.py","lineNumber":998,"sourceCode":"                (int(latents.shape[1]) - int(num_img_tokens), condition_latents[1]),\n            ]\n\n        tokens_per_frame = int(getattr(batch, \"sp_video_tokens_per_frame\", 0))\n        if tokens_per_frame <= 0:\n            raise ValueError(\n                \"SP-sharded LTX-2 TI2V requires batch.sp_video_tokens_per_frame.\"\n            )\n        if int(num_img_tokens) != int(tokens_per_frame):\n            raise ValueError(\n                \"LTX-2 conditioning token count must match one latent frame when using SP.\"\n            )\n\n        raw_shape = getattr(batch, \"raw_latent_shape\", None)\n        if raw_shape is None:\n            raise ValueError(\"SP-sharded LTX-2 TI2V requires batch.raw_latent_shape.\")\n        global_seq_len = int(raw_shape[1])\n        if global_seq_len % tokens_per_frame != 0:\n            raise ValueError(\n                \"SP-sharded LTX-2 TI2V expected raw seq_len divisible by tokens_per_frame.\"\n            )\n\n        global_num_frames = global_seq_len // tokens_per_frame\n        local_start_frame = int(getattr(batch, \"sp_video_start_frame\", 0))\n        local_num_frames = int(getattr(batch, \"sp_video_latent_num_frames\", 0))\n        local_end_frame = local_start_frame + local_num_frames\n\n        spans: list[tuple[int, torch.Tensor]] = []\n        if local_start_frame == 0:\n            spans.append((0, condition_latents[0]))\n\n        if len(condition_latents) == 2:\n            last_global_frame = global_num_frames - 1\n            if local_start_frame <= last_global_frame < local_end_frame:\n                local_last_frame = last_global_frame - local_start_frame\n                spans.append(\n                    (local_last_frame * tokens_per_frame, condition_latents[1])","sourceCodeStart":980,"sourceCodeEnd":1016,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/pipelines_core/stages/model_specific_stages/ltx_2/denoising.py#L980-L1016","documentation":"During sequence-parallel (SP) sharded LTX-2 text/image-to-video generation, the stage computes per-rank frame spans by dividing the global raw latent sequence length by tokens_per_frame. If batch.raw_latent_shape[1] is not an integer multiple of tokens_per_frame, the frame arithmetic breaks and this ValueError is thrown.","triggerScenarios":"Running an SP-sharded LTX-2 TI2V pipeline where batch.raw_latent_shape[1] (global_seq_len) % tokens_per_frame != 0, e.g. a latent shape that doesn't correspond to whole frames, or a wrong tokens_per_frame for the checkpoint.","commonSituations":"Mismatched resolution/duration settings producing non-frame-aligned latent lengths; using an SP degree or VA chunking that yields a partial final frame; feeding a raw_latent_shape computed from pixels instead of latents.","solutions":["Verify batch.raw_latent_shape[1] equals num_frames * tokens_per_frame before launching the SP run","Adjust frame count / resolution so the latent seq_len is frame-aligned","Check that tokens_per_frame matches the LTX-2 latent patching config for this checkpoint"],"exampleFix":"// before\nbatch.raw_latent_shape = (1, 12345, 64)  // 12345 % tokens_per_frame != 0\n// after\nassert global_seq_len % tokens_per_frame == 0\nbatch.raw_latent_shape = (1, num_frames * tokens_per_frame, 64)","handlingStrategy":"validation","validationCode":"tokens_per_frame = get_tokens_per_frame(ckpt)\nseq_len = int(batch.raw_latent_shape[1])\nassert seq_len % tokens_per_frame == 0, f\"seq_len {seq_len} not frame-aligned (tokens_per_frame={tokens_per_frame})\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate frame alignment at request construction, before SP dispatch","Keep tokens_per_frame pinned per checkpoint config"],"tags":["ltx-2","sequence-parallel","video-generation","shape-validation"],"backgroundTag":"tensor-shape-mismatch","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}