keras-team/keras · error · ValueError

Expected `model` argument to be a Functional Model…

Error message

Expected `model` argument to be a Functional Model instance. Received: model={model}

What it means

Type guard in clone_functional (_clone_functional_model): the model argument must be an instance of Functional. Cloning works by walking the model's functional graph (inputs, outputs, layer connectivity), which subclassed Model instances without a functional DAG do not expose, so anything else is rejected upfront.

Solutions

  1. Pass a Functional model (one built with the functional API from Input tensors)
  2. For subclassed models, use keras.models.clone_model with a custom clone_function or copy weights manually
  3. Rebuild your logic as a Functional model if you need functional cloning
Defensive patterns

Strategy: type-guard

When it happens

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

Appendix: source

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

            to build the model upon. If not provided,
            placeholders will be created.
        clone_function: callable to be applied on non-input layers in the model.
            By default, it clones the layer (without copying the weights).

    Returns:
        An instance of `Functional` reproducing the behavior
        of the original model, on top of new inputs tensors,
        using newly instantiated weights.
    """

    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"

View on GitHub (pinned to 7a34a03db6)