{"record":{"id":"187ce71652a9519f","repo":"keras-team/keras","slug":"invalid-quantization-mode-expected-one-of-dtype","errorCode":null,"errorMessage":"Invalid quantization mode. Expected one of {dtype_policies.QUANTIZATION_MODES}. Received: mode={mode}","messagePattern":"Invalid quantization mode\\. Expected one of (.+?)\\. Received: mode=(.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/layers/layer.py","lineNumber":1380,"sourceCode":"\n    def quantize(self, mode=None, type_check=True, config=None):\n        raise self._not_implemented_error(self.quantize)\n\n    def _check_quantize_args(self, mode, compute_dtype):\n        if not self.built:\n            raise ValueError(\n                \"Cannot quantize a layer that isn't yet built. \"\n                f\"Layer '{self.name}' (of type '{self.__class__.__name__}') \"\n                \"is not built yet.\"\n            )\n        if getattr(self, \"_is_quantized\", False):\n            raise ValueError(\n                f\"Layer '{self.name}' is already quantized with \"\n                f\"dtype_policy='{self.dtype_policy.name}'. \"\n                f\"Received: mode={mode}\"\n            )\n        if mode not in dtype_policies.QUANTIZATION_MODES:\n            raise ValueError(\n                \"Invalid quantization mode. \"\n                f\"Expected one of {dtype_policies.QUANTIZATION_MODES}. \"\n                f\"Received: mode={mode}\"\n            )\n        if mode == \"int8\" and compute_dtype == \"float16\":\n            raise ValueError(\n                f\"Quantization mode='{mode}' doesn't work well with \"\n                \"compute_dtype='float16'. Consider loading model/layer with \"\n                \"another dtype policy such as 'mixed_bfloat16' or \"\n                \"'mixed_float16' before calling `quantize()`.\"\n            )\n\n    def quantized_call(self, *args, **kwargs):\n        current_remat_mode = get_current_remat_mode()\n\n        if (\n            current_remat_mode != self._remat_mode\n            and current_remat_mode is not None","sourceCodeStart":1362,"sourceCodeEnd":1398,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/layers/layer.py#L1362-L1398","documentation":"quantize(mode=...) only accepts the modes listed in dtype_policies.QUANTIZATION_MODES (e.g. 'int8', 'int8_gptq', 'float8'). Any other string — typos, unsupported modes like 'int4' or 'binary' — raises this error.","triggerScenarios":"model.quantize('int4'); layer.quantize('dynamic'); passing a DTypePolicy object or wrong-cased string like 'INT8'.","commonSituations":"Assuming a mode exists because another framework supports it; version differences where newer modes are unavailable in the installed Keras.","solutions":["Check keras.src.dtype_policies.QUANTIZATION_MODES (or docs) and pass one of those exact strings","Upgrade Keras if the mode you need (e.g. float8) was added later","For 4-bit weight quantization use mode 'int8_gptq'/'gptq' with a GPTQConfig"],"exampleFix":"# before\nmodel.quantize('int4')\n# after\nmodel.quantize('int8_gptq', config=GPTQConfig(bits=4, calibration_data=calib))","handlingStrategy":"validation","validationCode":"from keras.src.dtype_policies import QUANTIZATION_MODES\nassert mode in QUANTIZATION_MODES, (mode, QUANTIZATION_MODES)","typeGuard":"def is_valid_mode(mode):\n    from keras.src.dtype_policies import QUANTIZATION_MODES\n    return mode in QUANTIZATION_MODES","tryCatchPattern":null,"preventionTips":["Print QUANTIZATION_MODES for your installed Keras before choosing a mode","Check Keras release notes for newly added quantization modes"],"tags":["keras","quantization","invalid-argument"],"backgroundTag":"quantization-config-invalid","analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}