keras-team/keras · error · ValueError

All entries in `input_tensors` must be KerasTensors…

Error message

All entries in `input_tensors` must be KerasTensors. Received invalid values: inputs_tensors={input_tensors}

What it means

Type guard in _clone_functional_model: when input_tensors is provided, every leaf of that (possibly nested) structure must be a backend.KerasTensor. The cloned graph will be built by calling layers on these placeholders, so raw ops tensors (e.g. raw TF tensors or numpy arrays) are rejected before tree structure is asserted.

Solutions

  1. Create placeholders with keras.Input(...) matching the model's inputs and pass those as input_tensors
  2. Do not pass concrete data batches or backend-native tensors; cloning builds a new symbolic graph
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at keras/src/models/cloning.py:385 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/92bfc0cb00681dd0. Report an issue: GitHub.

Appendix: source

Thrown at keras/src/models/cloning.py:385

    if not callable(clone_function):
        raise ValueError(
            "Expected `clone_function` argument to be a callable. "
            f"Received: clone_function={clone_function}"
        )

    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):

View on GitHub (pinned to 7a34a03db6)