{"record":{"id":"7a1411cb38d01348","repo":"sgl-project/sglang","slug":"batching-config-rule-requires-max-batch-size","errorCode":null,"errorMessage":"batching config rule requires max_batch_size","messagePattern":"batching config rule requires max_batch_size","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/managers/dynamic_batch_admission.py","lineNumber":89,"sourceCode":"    model_contains: str | None = None\n    resolution: str | None = None\n    device_memory_gb_min: float | None = None\n    device_memory_gb_max: float | None = None\n    offload: bool | None = None\n    max_batch_size: int = 1\n    max_cost: float | None = None\n    source: str = \"user\"\n\n    @classmethod\n    def from_dict(cls, data: dict[str, Any], *, source: str) -> BatchingRule:\n        if not isinstance(data, dict):\n            raise ValueError(\n                f\"batching config rule from {source} must be an object, \"\n                f\"got {type(data).__name__}\"\n            )\n        _validate_rule_keys(data, source=source)\n        if \"max_batch_size\" not in data:\n            raise ValueError(\"batching config rule requires max_batch_size\")\n\n        rule = cls(\n            model=_optional_str(data.get(\"model\")),\n            model_contains=_optional_str(data.get(\"model_contains\")),\n            resolution=_optional_str(data.get(\"resolution\")),\n            device_memory_gb_min=_optional_float(data.get(\"device_memory_gb_min\")),\n            device_memory_gb_max=_optional_float(data.get(\"device_memory_gb_max\")),\n            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(","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/managers/dynamic_batch_admission.py#L71-L107","documentation":"A batching rule entry in the dynamic batch admission config JSON must include a max_batch_size field; it is the only mandatory key. from_dict parses each rule object (after key validation) and throws this ValueError when max_batch_size is absent.","triggerScenarios":"Calling load_batching_config / BatchingRule.from_dict on a JSON config where a rule object omits 'max_batch_size' (e.g. {\"model\": \"x\", \"resolution\": \"1024\"}).","commonSituations":"Hand-written or template batching config files where the author listed only matching selectors (model/resolution) and forgot the actual batch-size limit; also configs migrated from a schema where batch size was optional or defaulted.","solutions":["Add \"max_batch_size\": <N> (>= 1) to every rule object in the batching config JSON","Validate the config with a JSON schema or a dry-run load_batching_config call before server startup","Check for typos in the key (unknown keys are reported separately by _validate_rule_keys)"],"exampleFix":"// before\n{\"model\": \"qwen-image\", \"resolution\": \"1024\"}\n// after\n{\"model\": \"qwen-image\", \"resolution\": \"1024\", \"max_batch_size\": 8}","handlingStrategy":"validation","validationCode":"import json\ncfg = json.load(open(path))\nrules = cfg.get(\"rules\", cfg) if isinstance(cfg, dict) else cfg\nfor i, r in enumerate(rules):\n    if not isinstance(r, dict) or \"max_batch_size\" not in r:\n        raise SystemExit(f\"rule[{i}] missing max_batch_size\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Lint every rule object for max_batch_size before deploying the config","Keep a canonical example rule in the repo and diff new rules against it"],"tags":["config","batching","validation","multimodal"],"backgroundTag":"missing-required-config-field","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}