{"record":{"id":"3cccde79b68f34a9","repo":"sgl-project/sglang","slug":"invalid-tokens-per-frame-tokens-per-frame-from","errorCode":null,"errorMessage":"Invalid tokens_per_frame={tokens_per_frame} from {latent_height=} {latent_width=} {self.patch_size=}","messagePattern":"Invalid tokens_per_frame=(.+?) from (.+?) (.+?) (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/configs/pipeline_configs/ltx_2.py","lineNumber":362,"sourceCode":"        if latent_height <= 0 or latent_width <= 0:\n            raise ValueError(\n                \"Invalid latent H/W computed from batch.height/width: \"\n                f\"{batch.height=} {batch.width=} {self.vae_scale_factor=}\"\n            )\n        if (latent_height % int(self.patch_size)) != 0 or (\n            latent_width % int(self.patch_size)\n        ) != 0:\n            raise ValueError(\n                \"Invalid spatial patching for packed token latents. Expected latent H/W \"\n                \"to be divisible by patch_size, got \"\n                f\"{latent_height=} {latent_width=} {self.patch_size=}.\"\n            )\n\n        post_patch_h = latent_height // int(self.patch_size)\n        post_patch_w = latent_width // int(self.patch_size)\n        tokens_per_frame = int(post_patch_h) * int(post_patch_w)\n        if tokens_per_frame <= 0:\n            raise ValueError(\n                f\"Invalid tokens_per_frame={tokens_per_frame} from \"\n                f\"{latent_height=} {latent_width=} {self.patch_size=}\"\n            )\n        if int(seq_len) % int(tokens_per_frame) != 0:\n            raise ValueError(\n                f\"LTX-2 token latents seq_len={seq_len} is not divisible by \"\n                f\"tokens_per_frame={tokens_per_frame}. Cannot time-shard for SP.\"\n            )\n        latent_num_frames = int(seq_len) // int(tokens_per_frame)\n        return int(latent_num_frames), int(tokens_per_frame)\n\n    def shard_latents_for_sp(self, batch, latents):\n        \"\"\"Shard LTX-2 packed token latents across SP ranks by latent time (frame) dimension.\"\"\"\n        sp_world_size = get_sp_world_size()\n        if sp_world_size <= 1:\n            return latents, False\n\n        # Default behavior for 5D latents.","sourceCodeStart":344,"sourceCodeEnd":380,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/configs/pipeline_configs/ltx_2.py#L344-L380","documentation":"After computing tokens_per_frame = (latent_height // patch_size) * (latent_width // patch_size), the config asserts it is positive. In practice this is unreachable if the earlier checks pass (latent dims > 0 and patch_size > 0), so hitting it indicates corrupted state or bypassed validation, such as NaN/None values coerced oddly or integer overflow in exotic configurations.","triggerScenarios":"Calling shard_latents_for_sp after earlier guards were bypassed (e.g. subclass overriding checks, monkey-patching in tests) leaving latent_height, latent_width, or patch_size in a state that yields a non-positive product.","commonSituations":"Test monkey-patching that skips validation; extremely degenerate inputs where floor division underflows; defensive dead-code path triggered by refactors that change earlier checks.","solutions":["Inspect latent_height, latent_width, and patch_size immediately before the call to see which value is degenerate","Ensure no monkey-patching or subclass skips the preceding positivity checks","Report as a bug if all preceding validations genuinely passed — this branch should be unreachable"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"tpf = (batch.height // config.vae_scale_factor // config.patch_size) * (batch.width // config.vae_scale_factor // config.patch_size)\nassert tpf > 0, tpf","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Avoid monkey-patching validation internals in tests; test through the public path","Treat this branch as an assertion failure and file a bug if reachable"],"tags":["ltx-2","video-generation","defensive-check","sequence-parallelism"],"backgroundTag":"invalid-config-value","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}