keras-team/keras · error · ValueError
Arguments `clone_function` and `input_tensors` are only supp
Error message
Arguments `clone_function` and `input_tensors` are only supported for Sequential models or Functional models. Received model of type '{model.__class__.__name__}', with clone_function={clone_function} and input_tensors={input_tensors} What it means
clone_function and input_tensors are only implemented for Sequential and Functional models. For custom subclassed models, clone_model falls back to a config round-trip and raises this ValueError if either argument was supplied, since there is no layer list or graph to clone from.
Source
Thrown at keras/src/models/cloning.py:191
# If the get_config() method is the same as a regular Functional
# model, we're safe to use _clone_functional_model (which relies
# on a Functional constructor). In the case where the get_config
# is custom, this may not necessarily work, but if clone_function
# or input_tensors are passed, we attempt it anyway
# in order to preserve backwards compatibility.
if utils.is_default(model.get_config) or (
clone_function or input_tensors
):
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__}
)View on GitHub (pinned to 7a34a03db6)
Solutions
- For subclassed models call clone_model(model) with no extra args - it rebuilds via get_config()/from_config().
- Ensure the subclass implements get_config()/from_config() correctly so the round trip works.
- Only pass clone_function/input_tensors after confirming the model is Sequential or Functional.
Example fix
# before clone = keras.models.clone_model(subclassed_model, clone_function=fn) # after clone = keras.models.clone_model(subclassed_model) # config round-trip
Defensive patterns
Strategy: type-guard
Validate before calling
if not isinstance(model, keras.Sequential) and not is_functional(model):
assert not clone_function and not input_tensors, 'clone_function/input_tensors only for Sequential/Functional' Type guard
def supports_clone_args(model) -> bool:
import keras
return isinstance(model, keras.Sequential) or getattr(model, '_is_graph_network', False) Prevention
- Give subclassed models working get_config/from_config so plain clone_model works.
When it happens
Trigger: keras.models.clone_model(my_subclassed_model, clone_function=fn) or input_tensors=tensor where the model is neither Sequential nor Functional.
Common situations: Model-agnostic cloning utilities; subclassed models embedding custom training logic, common in research code.
Related errors
- Argument `call_function` is only supported for Functional mo
- Unexpected keyword argument(s): {tuple(kwargs.keys())}
- `call_function` argument is not supported with Sequential mo
- Expected `model` argument to be a `Sequential` model instanc
- Expected `clone_function` argument to be a callable. Receive
AI-assisted analysis of keras-team/keras@7a34a03db6 (2026-08-25).
Data as JSON: /api/errors/38c43166cd578675.
Report an issue: GitHub.