{"record":{"id":"5b0a53f4ba22d5b9","repo":"sgl-project/sglang","slug":"invalid-self-patch-size-must-be-0","errorCode":null,"errorMessage":"Invalid {self.patch_size=}. Must be > 0.","messagePattern":"Invalid (.+?)\\. Must be > 0\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/configs/pipeline_configs/ltx_2.py","lineNumber":340,"sourceCode":"        self, batch, seq_len: int\n    ) -> tuple[int, int]:\n        \"\"\"Infer latent-frame count and tokens-per-frame for packed token latents [B, S, D].\n\n        Notes:\n        - This assumes `patch_size_t == 1` (no temporal patching).\n        - Tokens are ordered as (frame, height, width) after packing.\n        \"\"\"\n        if int(self.patch_size_t) != 1:\n            raise ValueError(\n                \"LTX-2 SP time-sharding for packed token latents currently requires \"\n                f\"{self.patch_size_t=}. (Expected 1)\"\n            )\n        if int(seq_len) <= 0:\n            raise ValueError(f\"Expected {seq_len=} > 0 for packed token latents.\")\n        if int(self.vae_scale_factor) <= 0:\n            raise ValueError(f\"Invalid {self.vae_scale_factor=}. Must be > 0.\")\n        if int(self.patch_size) <= 0:\n            raise ValueError(f\"Invalid {self.patch_size=}. Must be > 0.\")\n\n        latent_height = int(batch.height) // int(self.vae_scale_factor)\n        latent_width = int(batch.width) // int(self.vae_scale_factor)\n        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)","sourceCodeStart":322,"sourceCodeEnd":358,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/configs/pipeline_configs/ltx_2.py#L322-L358","documentation":"LTX-2 pipeline config requires patch_size > 0 before computing post-patch token counts for SP time-sharding of packed token latents. patch_size is used both as a divisor for latent height/width and later to compute tokens_per_frame, so a non-positive value breaks the arithmetic. This ValueError fires when the transformer patch size is 0 or negative.","triggerScenarios":"Calling shard_latents_for_sp on a config where patch_size is 0 or negative, e.g. a config dict missing the patch_size key and defaulting to 0, or a bad override.","commonSituations":"Hand-edited or programmatically generated LTX-2 configs that omit or corrupt patch_size; version changes that renamed the config key (e.g. patch_size vs spatial_patch_size) leaving the old key unset.","solutions":["Set patch_size to the model's actual spatial patch size (commonly 2 for LTX-2 packed token latents)","Verify the config dict key name matches what the loader expects and prints the resolved value before use","Assert positivity of all patch fields when constructing the config"],"exampleFix":"// before\nconfig.patch_size = 0\nconfig.shard_latents_for_sp(batch)  # ValueError\n\n// after\nconfig.patch_size = 2\nconfig.shard_latents_for_sp(batch)","handlingStrategy":"validation","validationCode":"assert config.patch_size and int(config.patch_size) > 0, f\"bad patch_size={config.patch_size}\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Assert patch_size positivity when building/overriding the LTX-2 config","Diff custom configs against the shipped reference config after upgrades"],"tags":["ltx-2","video-generation","config-validation","sequence-parallelism"],"backgroundTag":"invalid-config-value","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}