{"record":{"id":"ba6721187c2fb074","repo":"keras-team/keras","slug":"when-providing-the-input-tensor-argument-you-ca-ba6721","errorCode":null,"errorMessage":"When providing the `input_tensor` argument, you cannot provide an incompatible `dtype` argument.","messagePattern":"When providing the `input_tensor` argument, you cannot provide an incompatible `dtype` argument\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/layers/core/input_layer.py","lineNumber":65,"sourceCode":"                        \"When providing the `input_tensor` argument, you \"\n                        \"cannot provide an incompatible `batch_size` argument.\"\n                    )\n            if shape is not None:\n                if (\n                    len(shape) != len(input_tensor.shape) - 1\n                    or shape != input_tensor.shape[1:]\n                ):\n                    raise ValueError(\n                        \"When providing the `input_tensor` argument, you \"\n                        \"cannot provide an incompatible `shape` argument.\"\n                    )\n            if batch_shape is not None and batch_shape != input_tensor.shape:\n                raise ValueError(\n                    \"When providing the `input_tensor` argument, you \"\n                    \"cannot provide an incompatible `batch_shape` argument.\"\n                )\n            if dtype is not None and input_tensor.dtype != dtype:\n                raise ValueError(\n                    \"When providing the `input_tensor` argument, you \"\n                    \"cannot provide an incompatible `dtype` argument.\"\n                )\n            if sparse is not None and input_tensor.sparse != sparse:\n                raise ValueError(\n                    \"When providing the `input_tensor` argument, you \"\n                    \"cannot provide an incompatible `sparse` argument.\"\n                )\n            batch_shape = input_tensor.shape\n            dtype = input_tensor.dtype\n            sparse = input_tensor.sparse\n        else:\n            if shape is not None and batch_shape is not None:\n                raise ValueError(\n                    \"You cannot pass both `shape` and `batch_shape` at the \"\n                    \"same time.\"\n                )\n            if batch_size is not None and batch_shape is not None:","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/layers/core/input_layer.py#L47-L83","documentation":"Consistency check in InputLayer.__init__: with input_tensor provided, a `dtype` argument that differs from the tensor's dtype is rejected, since the wrapped KerasTensor already carries its dtype and cannot be silently reinterpreted.","triggerScenarios":"Thrown at keras/src/layers/core/input_layer.py:65 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Omit dtype and inherit input_tensor.dtype","Pass dtype matching the tensor exactly, e.g. dtype=input_tensor.dtype"],"exampleFix":null,"handlingStrategy":"validation","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"}