{"record":{"id":"661a45d2282d756f","repo":"keras-team/keras","slug":"implicitly-enabling-gptq-quantization-by-setting","errorCode":null,"errorMessage":"Implicitly enabling GPTQ quantization by setting `dtype_policy` to '{value}' is not supported. GPTQ requires a calibration dataset and a `GPTQConfig` object.\n\nPlease use the `.quantize('gptq', config=...)` method on the layer or model instead.","messagePattern":"Implicitly enabling GPTQ quantization by setting `dtype_policy` to '(.+?)' is not supported\\. GPTQ requires a calibration dataset and a `GPTQConfig` object\\.\n\nPlease use the `\\.quantize\\('gptq', config=\\.\\.\\.\\)` method on the layer or model instead\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/layers/layer.py","lineNumber":809,"sourceCode":"            variable.assign(value)\n\n    @property\n    def dtype_policy(self):\n        return self._dtype_policy\n\n    @dtype_policy.setter\n    def dtype_policy(self, value):\n        policy = dtype_policies.get(value)\n        if isinstance(self._dtype_policy, DTypePolicyMap) and self.path:\n            if self.path in self._dtype_policy:\n                del self._dtype_policy[self.path]\n            self._dtype_policy[self.path] = policy\n        else:\n            self._dtype_policy = policy\n        if policy.quantization_mode is not None:\n            if self.built and not getattr(self, \"_is_quantized\", False):\n                if policy.quantization_mode == \"gptq\":\n                    raise ValueError(\n                        \"Implicitly enabling GPTQ quantization by setting \"\n                        f\"`dtype_policy` to '{value}' is not supported. \"\n                        \"GPTQ requires a calibration dataset and a \"\n                        \"`GPTQConfig` object.\\n\\n\"\n                        \"Please use the `.quantize('gptq', config=...)` method \"\n                        \"on the layer or model instead.\"\n                    )\n                self.quantize(policy.quantization_mode)\n\n    @property\n    def dtype(self):\n        \"\"\"Alias of `layer.variable_dtype`.\"\"\"\n        return self.variable_dtype\n\n    @property\n    def compute_dtype(self):\n        \"\"\"The dtype of the computations performed by the layer.\"\"\"\n        if isinstance(self._dtype_policy, DTypePolicyMap) and self.path:","sourceCodeStart":791,"sourceCodeEnd":827,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/layers/layer.py#L791-L827","documentation":"GPTQ quantization needs a calibration dataset and a GPTQConfig, so Keras refuses to enable it implicitly when you assign a dtype_policy string like 'gptq' to an already-built layer. Other quantization modes (int8, float8) can be enabled via dtype_policy, but 'gptq' cannot.","triggerScenarios":"Setting layer.dtype_policy = 'int8_gptq' (or a policy whose quantization_mode == 'gptq') on a built layer, or deserializing such a policy without going through quantize().","commonSituations":"Copying dtype policy strings from int8 examples and swapping in gptq; trying to reproduce a quantized checkpoint by only setting the policy.","solutions":["Call layer.quantize('gptq', config=GPTQConfig(...)) or model.quantize('gptq', config=...) with calibration data instead of setting dtype_policy","If you only need weight-only int8, use a non-GPTQ policy such as 'int8' via dtype_policy"],"exampleFix":"# before\nlayer.dtype_policy = 'int8_gptq'\n# after\nfrom keras.quantizers import GPTQConfig\nmodel.quantize('gptq', config=GPTQConfig(bits=4, calibration_data=calib))","handlingStrategy":"validation","validationCode":"if layer.dtype_policy.quantization_mode == 'gptq':\n    raise SystemExit('enable GPTQ via quantize(), not dtype_policy')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use .quantize('gptq', config=GPTQConfig(...)) with calibration data","Do not assign policy strings containing 'gptq' to built layers"],"tags":["keras","quantization","gptq","dtype-policy"],"backgroundTag":"quantization-config-invalid","analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}