keras-team/keras · error · ValueError
`input_tensors` must have the same structure as…
Error message
`input_tensors` must have the same structure as model.input\nReference structure: {model.input}\nReceived structure: {input_tensors} What it means
Structural guard in _clone_functional_model: the provided input_tensors must mirror the exact nesting structure of model.input (same dict keys / list / tuple shape). After flattening, layers are zipped positionally with the placeholders, so a mismatched structure (e.g. a flat list for a dict of inputs, or wrong nesting depth) would silently wire inputs to the wrong layers and is rejected instead.
Solutions
- Mirror model.input's structure exactly: pass a dict with the same keys if the model was built from dict inputs, or a list with the same length and nesting
- Use tree.structure(model.input) as a reference, or omit input_tensors to let placeholders be generated automatically
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at keras/src/models/cloning.py:392 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/87610939f19e7c45.
Report an issue: GitHub.
Appendix: source
Thrown at keras/src/models/cloning.py:392
if not isinstance(model, Functional):
raise ValueError(
"Expected `model` argument "
f"to be a Functional Model instance. Received: model={model}"
)
if input_tensors is not None:
if not all(
isinstance(x, backend.KerasTensor)
for x in tree.flatten(input_tensors)
):
raise ValueError(
"All entries in `input_tensors` must be KerasTensors. "
f"Received invalid values: inputs_tensors={input_tensors}"
)
try:
tree.assert_same_structure(input_tensors, model.input)
except ValueError as e:
raise ValueError(
"`input_tensors` must have the same structure as model.input"
f"\nReference structure: {model.input}"
f"\nReceived structure: {input_tensors}"
) from e
else:
input_tensors = tree.map_structure(
lambda x: Input(batch_shape=x.shape, dtype=x.dtype, name=x.name),
model.input,
)
def operation_fn(layer):
new_layer = clone_function(layer)
return new_layer
output_tensors = model._run_through_graph(
input_tensors,
operation_fn=operation_fn,
call_fn=call_function,View on GitHub (pinned to 7a34a03db6)