{"record":{"id":"0c9c565d2cc33ff4","repo":"sgl-project/sglang","slug":"invalid-precision-self-precision-must-be-int4","errorCode":null,"errorMessage":"Invalid precision: {self.precision}. Must be 'int4' or 'nvfp4'","messagePattern":"Invalid precision: (.+?)\\. Must be 'int4' or 'nvfp4'","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/layers/quantization/configs/nunchaku_config.py","lineNumber":137,"sourceCode":"            rank=self.rank,\n            act_unsigned=self.act_unsigned,\n        )\n\n    def _get_quant_rules(self) -> dict[str, list[str]]:\n        if self.model_cls is not None and hasattr(\n            self.model_cls, \"get_nunchaku_quant_rules\"\n        ):\n            return self.model_cls.get_nunchaku_quant_rules()\n        return {}\n\n    def __post_init__(self):\n        if self.group_size is None:\n            if self.precision == \"nvfp4\":\n                self.group_size = 16\n            elif self.precision == \"int4\":\n                self.group_size = 64\n            else:\n                raise ValueError(\n                    f\"Invalid precision: {self.precision}. Must be 'int4' or 'nvfp4'\"\n                )\n\n        if self.precision not in [\"int4\", \"nvfp4\"]:\n            raise ValueError(\n                f\"Invalid precision: {self.precision}. Must be 'int4' or 'nvfp4'\"\n            )\n\n        if self.rank <= 0:\n            raise ValueError(f\"Rank must be positive, got {self.rank}\")\n\n    @classmethod\n    def from_dict(cls, config_dict: dict) -> \"NunchakuConfig\":\n        \"\"\"Create configuration from dictionary.\"\"\"\n        return cls(**config_dict)\n\n    def to_dict(self) -> dict:\n        \"\"\"Convert configuration to dictionary.\"\"\"","sourceCodeStart":119,"sourceCodeEnd":155,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/layers/quantization/configs/nunchaku_config.py#L119-L155","documentation":"NunchakuConfig.__post_init__ rejects a precision that is neither 'int4' nor 'nvfp4'. The first check fires only when group_size was omitted, because the default group size depends on the precision (16 for nvfp4, 64 for int4).","triggerScenarios":"Constructing NunchakuConfig(precision='fp8') or any other string with group_size=None; the inference chain hits the else branch while trying to pick a default group size.","commonSituations":"Copy-pasting a config from a different quantization library using 'int8'/'fp8'; case mismatch like 'INT4'; passing None precision.","solutions":["Set precision to exactly 'int4' or 'nvfp4'","Fix case/typo in the precision string","If you need a custom group size, provide group_size explicitly — but precision must still be valid"],"exampleFix":"# before\ncfg = NunchakuConfig(precision=\"fp8\")\n\n# after\ncfg = NunchakuConfig(precision=\"int4\", group_size=64)","handlingStrategy":"validation","validationCode":"if cfg_kwargs.get(\"precision\") not in (\"int4\", \"nvfp4\"):\n    raise SystemExit(\"precision must be 'int4' or 'nvfp4'\")\ncfg = NunchakuConfig(**cfg_kwargs)","typeGuard":"def is_valid_nunchaku_precision(p: object) -> bool:\n    return isinstance(p, str) and p in (\"int4\", \"nvfp4\")","tryCatchPattern":null,"preventionTips":["Validate precision against the allowed set at CLI/config parse time","Normalize casing early: precision.strip().lower()"],"tags":["quantization","config-validation","nunchaku"],"backgroundTag":"invalid-config-value","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}