keras-team/keras · error · ValueError

Argument `call_function` is only supported for Functional mo

Error message

Argument `call_function` is only supported for Functional models. Received model of type '{model.__class__.__name__}', with call_function={clone_function}

What it means

Like clone_function/input_tensors, call_function is a Functional-only feature of clone_model: it needs the model's internal call graph. For any non-Functional model (Sequential or subclassed), clone_model raises this ValueError when call_function is not None.

Source

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

            return _clone_functional_model(
                model,
                clone_function=clone_function,
                call_function=call_function,
                input_tensors=input_tensors,
            )

    # Case of a custom model class
    if clone_function or input_tensors:
        raise ValueError(
            "Arguments `clone_function` and `input_tensors` "
            "are only supported for Sequential models "
            "or Functional models. Received model of "
            f"type '{model.__class__.__name__}', with "
            f"clone_function={clone_function} and "
            f"input_tensors={input_tensors}"
        )
    if call_function is not None:
        raise ValueError(
            "Argument `call_function` is only supported "
            "for Functional models. Received model of "
            f"type '{model.__class__.__name__}', with "
            f"call_function={clone_function}"
        )
    config = serialization_lib.serialize_keras_object(model)
    return serialization_lib.deserialize_keras_object(
        config, custom_objects={model.__class__.__name__: model.__class__}
    )


def _wrap_clone_function(
    clone_function, call_function=None, recursive=False, cache=None
):
    """Wrapper to handle recursiveness and layer sharing."""
    if clone_function is None:

        def _clone_layer(layer):

View on GitHub (pinned to 7a34a03db6)

Solutions

  1. Restrict call_function to Functional models: check the model type before passing it.
  2. For subclassed or Sequential models, call clone_model(model) plain or rebuild the model manually.

Example fix

# before
clone = keras.models.clone_model(model, call_function=fn)  # model is Sequential

# after
kwargs = {'call_function': fn} if is_functional(model) else {}
clone = keras.models.clone_model(model, **kwargs)
Defensive patterns

Strategy: type-guard

Validate before calling

if call_function is not None:
    assert is_functional(model), 'call_function requires a Functional model'

Type guard

def is_functional(model) -> bool:
    return getattr(model, '_is_graph_network', False)

Prevention

When it happens

Trigger: keras.models.clone_model(sequential_or_subclassed_model, call_function=fn).

Common situations: Sharing one cloning helper across Functional and Sequential/subclassed models; call-graph surgery code applied indiscriminately.

Related errors


AI-assisted analysis of keras-team/keras@7a34a03db6 (2026-08-25). Data as JSON: /api/errors/00a9b396da8cd4b1. Report an issue: GitHub.