keras-team/keras · error · ValueError
`call_function` argument is not supported with Sequential mo
Error message
`call_function` argument is not supported with Sequential models. In a Sequential model, layers aren't called at model-construction time (they're merely listed). Use `call_function` with Functional models only. Received model of type '{model.__class__.__name__}', with call_function={clone_function} What it means
call_function lets you replay a Functional model's call graph at clone time. Sequential models have no recorded call graph - layers are only listed, never called - so clone_model(model, call_function=fn) on a Sequential raises this ValueError. Use clone_function for Sequential instead.
Source
Thrown at keras/src/models/cloning.py:150
In the case of a subclassed model, you cannot using a custom
`clone_function`.
"""
cache = kwargs.pop("cache", None)
if kwargs:
raise ValueError(
f"Unexpected keyword argument(s): {tuple(kwargs.keys())}"
)
if isinstance(model, Sequential):
# Wrap clone_function to handle recursiveness and layer sharing.
clone_function = _wrap_clone_function(
clone_function,
call_function=call_function,
recursive=recursive,
cache=cache,
)
if call_function is not None:
raise ValueError(
"`call_function` argument is not supported with Sequential "
"models. In a Sequential model, layers aren't called "
"at model-construction time (they're merely listed). "
"Use `call_function` with Functional models only. "
"Received model of "
f"type '{model.__class__.__name__}', with "
f"call_function={clone_function}"
)
return _clone_sequential_model(
model,
clone_function=clone_function,
input_tensors=input_tensors,
)
if isinstance(model, Functional):
# Wrap clone_function to handle recursiveness and layer sharing.
clone_function = _wrap_clone_function(
clone_function,
call_function=call_function,View on GitHub (pinned to 7a34a03db6)
Solutions
- Pass clone_function(layer) -> layer instead; it customizes per-layer cloning for Sequential.
- If you need call-graph customization, rebuild the model as Functional (built from keras.Input plus layer calls) first.
- Simply drop call_function for Sequential models.
Example fix
# before
clone = keras.models.clone_model(seq_model, call_function=my_call_fn)
# after
clone = keras.models.clone_model(
seq_model, clone_function=lambda l: l.__class__.from_config(l.get_config())) Defensive patterns
Strategy: type-guard
Validate before calling
kwargs = {'call_function': fn} if is_functional(model) else {}
clone = keras.models.clone_model(model, **kwargs) Type guard
def is_functional(model) -> bool:
return getattr(model, '_functional_construction', False) or getattr(model, '_is_graph_network', False) Prevention
- Branch cloning logic on model type (Sequential vs Functional vs subclassed).
When it happens
Trigger: keras.models.clone_model(sequential_model, call_function=my_fn).
Common situations: Generic cloning utilities that always pass call_function regardless of model type; migrating a workflow from Functional to Sequential models.
Related errors
- Argument `call_function` is only supported for Functional mo
- Expected `model` argument to be a `Sequential` model instanc
- Argument `input_tensors` must contain a single tensor.
- Unexpected keyword argument(s): {tuple(kwargs.keys())}
- Arguments `clone_function` and `input_tensors` are only supp
AI-assisted analysis of keras-team/keras@7a34a03db6 (2026-08-25).
Data as JSON: /api/errors/014f4f4e0d6ac8f6.
Report an issue: GitHub.