{"record":{"id":"ed2191d03ea96399","repo":"keras-team/keras","slug":"autocastscope-can-only-be-used-with-a-floating-p","errorCode":null,"errorMessage":"`AutocastScope` can only be used with a floating-point target dtype, such as 'float16'. Received: dtype={dtype}","messagePattern":"`AutocastScope` can only be used with a floating-point target dtype, such as 'float16'\\. Received: dtype=(.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/backend/common/variables.py","lineNumber":688,"sourceCode":"    return dtype.startswith(\"int\") or dtype.startswith(\"uint\")\n\n\ndef get_autocast_scope():\n    return global_state.get_global_attribute(\"autocast_scope\")\n\n\nclass AutocastScope:\n    \"\"\"Context manager that enables the autocasting of float variables.\n\n    Under this context manager, float `Variables`s will be cast to `dtype`\n    (note that `dtype` must also be float).\n    \"\"\"\n\n    def __init__(self, dtype):\n        if dtype is not None:\n            dtype = standardize_dtype(dtype)\n            if not is_float_dtype(dtype):\n                raise ValueError(\n                    \"`AutocastScope` can only be used with \"\n                    \"a floating-point target dtype, such as 'float16'. \"\n                    f\"Received: dtype={dtype}\"\n                )\n        self.dtype = dtype\n        self.original_scope = None\n\n    def maybe_cast(self, value):\n        from keras.src import backend\n\n        if self.dtype is not None and is_float_dtype(value.dtype):\n            return backend.cast(value, dtype=self.dtype)\n        return value\n\n    def __enter__(self):\n        self.original_scope = get_autocast_scope()\n        global_state.set_global_attribute(\"autocast_scope\", self)\n","sourceCodeStart":670,"sourceCodeEnd":706,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/backend/common/variables.py#L670-L706","documentation":"Error \"`AutocastScope` can only be used with a floating-point target dtype, such as 'float16'. Received: dtype={dtype}\" thrown in keras-team/keras.","triggerScenarios":"Thrown at keras/src/backend/common/variables.py:688 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}