keras-team/keras · error · ValueError
When providing the `input_tensor` argument, you cannot…
Error message
When providing the `input_tensor` argument, you cannot provide an incompatible `sparse` argument.
What it means
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.
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
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at keras/src/layers/core/input_layer.py:70 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of keras-team/keras@7a34a03db6 (2026-08-25).
Data as JSON: /api/errors/8d01e810d24f7a57.
Report an issue: GitHub.
Appendix: source
Thrown at keras/src/layers/core/input_layer.py:70
len(shape) != len(input_tensor.shape) - 1
or shape != input_tensor.shape[1:]
):
raise ValueError(
"When providing the `input_tensor` argument, you "
"cannot provide an incompatible `shape` argument."
)
if batch_shape is not None and batch_shape != input_tensor.shape:
raise ValueError(
"When providing the `input_tensor` argument, you "
"cannot provide an incompatible `batch_shape` argument."
)
if dtype is not None and input_tensor.dtype != dtype:
raise ValueError(
"When providing the `input_tensor` argument, you "
"cannot provide an incompatible `dtype` argument."
)
if sparse is not None and input_tensor.sparse != sparse:
raise ValueError(
"When providing the `input_tensor` argument, you "
"cannot provide an incompatible `sparse` argument."
)
batch_shape = input_tensor.shape
dtype = input_tensor.dtype
sparse = input_tensor.sparse
else:
if shape is not None and batch_shape is not None:
raise ValueError(
"You cannot pass both `shape` and `batch_shape` at the "
"same time."
)
if batch_size is not None and batch_shape is not None:
raise ValueError(
"You cannot pass both `batch_size` and `batch_shape` "
"at the same time."
)
if shape is None and batch_shape is None:View on GitHub (pinned to 7a34a03db6)