{"record":{"id":"8d01e810d24f7a57","repo":"keras-team/keras","slug":"when-providing-the-input-tensor-argument-you-ca-8d01e8","errorCode":null,"errorMessage":"When providing the `input_tensor` argument, you cannot provide an incompatible `sparse` argument.","messagePattern":"When providing the `input_tensor` argument, you cannot provide an incompatible `sparse` argument\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/layers/core/input_layer.py","lineNumber":70,"sourceCode":"                    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:\n                raise ValueError(\n                    \"You cannot pass both `batch_size` and `batch_shape` \"\n                    \"at the same time.\"\n                )\n            if shape is None and batch_shape is None:","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/layers/core/input_layer.py#L52-L88","documentation":"Raised by InputLayer.__init__ when an input_tensor is supplied together with a `sparse` flag that disagrees with input_tensor.sparse. When a tensor is passed, its sparse attribute wins, so any conflicting explicit argument is rejected as a guard against silently ignoring user input.","triggerScenarios":"Thrown at keras/src/layers/core/input_layer.py:70 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Set sparse=None (or match it to input_tensor.sparse) when passing input_tensor","Pass sparse=input_tensor.sparse to make the intent explicit","Omit input_tensor and construct the layer from shape/batch_shape plus the desired sparse value"],"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"}