{"record":{"id":"10fe77d0bf28f25d","repo":"keras-team/keras","slug":"overwrite-with-gradient-must-be-a-boolean-recei","errorCode":null,"errorMessage":"`overwrite_with_gradient` must be a boolean. Received: {value}","messagePattern":"`overwrite_with_gradient` must be a boolean\\. Received: (.+?)","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"keras/src/backend/common/variables.py","lineNumber":365,"sourceCode":"        return self._path\n\n    @property\n    def overwrite_with_gradient(self):\n        \"\"\"Whether this variable should be overwritten by the gradient.\n\n        This property is designed for a special case where we want to overwrite\n        the variable directly with its computed gradient. For example, in float8\n        training, new `scale` and `amax_history` are computed as gradients, and\n        we want to overwrite them directly instead of following the typical\n        procedure such as gradient descent with a learning rate, gradient\n        clipping and weight decaying.\n        \"\"\"\n        return self._overwrite_with_gradient\n\n    @overwrite_with_gradient.setter\n    def overwrite_with_gradient(self, value):\n        if not isinstance(value, bool):\n            raise TypeError(\n                \"`overwrite_with_gradient` must be a boolean. \"\n                f\"Received: {value}\"\n            )\n        self._overwrite_with_gradient = value\n\n    @property\n    def regularizer(self):\n        return self._regularizer\n\n    @regularizer.setter\n    def regularizer(self, value):\n        if value is not None and not callable(value):\n            raise ValueError(\n                \"Invalid value for attribute `regularizer`. Expected a \"\n                \"callable (such as a `keras.regularizers.Regularizer` \"\n                f\"instance) or `None`. Received: regularizer={value}\"\n            )\n        self._regularizer = value","sourceCodeStart":347,"sourceCodeEnd":383,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/backend/common/variables.py#L347-L383","documentation":"Raised by the overwrite_with_gradient property setter when a non-bool value is assigned. This flag controls a special gradient mode (e.g. float8 training, where scale/amax_history variables are overwritten directly by their computed gradients) and must be strictly True or False; the isinstance check in the setter rejects anything else.","triggerScenarios":"Thrown at keras/src/backend/common/variables.py:365 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Assign a Python bool: variable.overwrite_with_gradient = True or False.","If the value arrives from config/JSON, convert it with bool(value) before assigning."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}