{"record":{"id":"dc870fd382ed28df","repo":"sgl-project/sglang","slug":"batching-config-rule-max-cost-must-be-0","errorCode":null,"errorMessage":"batching config rule max_cost must be > 0","messagePattern":"batching config rule max_cost must be > 0","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/managers/dynamic_batch_admission.py","lineNumber":115,"sourceCode":"            offload=_optional_bool(data.get(\"offload\")),\n            max_batch_size=int(data[\"max_batch_size\"]),\n            max_cost=_optional_float(data.get(\"max_cost\")),\n            source=source,\n        )\n        rule.validate()\n        return rule\n\n    def validate(self) -> None:\n        if self.model is not None and self.model_contains is not None:\n            raise ValueError(\n                \"batching config rule cannot set both model and model_contains\"\n            )\n        if self.model is None and self.model_contains is None:\n            raise ValueError(\"batching config rule requires model or model_contains\")\n        if self.max_batch_size < 1:\n            raise ValueError(\"batching config rule max_batch_size must be >= 1\")\n        if self.max_cost is not None and self.max_cost <= 0.0:\n            raise ValueError(\"batching config rule max_cost must be > 0\")\n        if (\n            self.device_memory_gb_min is not None\n            and self.device_memory_gb_max is not None\n            and self.device_memory_gb_min > self.device_memory_gb_max\n        ):\n            raise ValueError(\n                \"batching config rule device_memory_gb_min must be <= device_memory_gb_max\"\n            )\n\n    def matches(\n        self,\n        *,\n        model_path: str,\n        resolution: str | None,\n        device_memory_gb: float | None,\n        offload: bool,\n    ) -> bool:\n        if self.model is not None and self.model != model_path:","sourceCodeStart":97,"sourceCodeEnd":133,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/managers/dynamic_batch_admission.py#L97-L133","documentation":"The optional max_cost cap on a rule, when present, must be strictly positive. validate() raises when max_cost is set to 0 or a negative number.","triggerScenarios":"A rule containing \"max_cost\": 0 or \"max_cost\": -1.0 (max_cost omitted or None is fine).","commonSituations":"Author uses max_cost: 0 to mean 'no cost cap' instead of omitting the key; unit mistakes producing tiny/negative values.","solutions":["Remove the \"max_cost\" key entirely if no cap is desired","Otherwise set it to a positive float"],"exampleFix":"// before\n{\"model\": \"x\", \"max_batch_size\": 4, \"max_cost\": 0}\n// after\n{\"model\": \"x\", \"max_batch_size\": 4}","handlingStrategy":"validation","validationCode":"for i, r in enumerate(rules):\n    c = r.get(\"max_cost\")\n    if c is not None and (not isinstance(c, (int, float)) or c <= 0):\n        raise SystemExit(f\"rule[{i}]: max_cost must be > 0 or omitted\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Omit optional caps rather than setting 0 to mean 'none'"],"tags":["config","batching","validation","range-check"],"backgroundTag":"config-value-out-of-range","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}