keras-team/keras · error · ValueError

Unexpected keyword argument(s): {tuple(kwargs.keys())}

Error message

Unexpected keyword argument(s): {tuple(kwargs.keys())}

What it means

clone_model() accepts a fixed set of keyword arguments (plus a legacy 'cache' that is popped first). Any remaining unrecognized kwarg raises this ValueError listing the offending names. It is a guard against API drift between Keras versions.

Source

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

    ```

    Note that subclassed models cannot be cloned by default,
    since their internal layer structure is not known.
    To achieve equivalent functionality
    as `clone_model` in the case of a subclassed model, simply make sure
    that the model class implements `get_config()`
    (and optionally `from_config()`), and call:

    ```python
    new_model = model.__class__.from_config(model.get_config())
    ```

    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 "

View on GitHub (pinned to 7a34a03db6)

Solutions

  1. Check the current signature: keras.models.clone_model(model, input_tensors=None, clone_function=None, call_function=None, recursive=False).
  2. Remove or fix the misspelled/unsupported keyword.
  3. If wrapping clone_model, filter kwargs against inspect.signature instead of forwarding **kwargs wholesale.

Example fix

# before
new_model = keras.models.clone_model(model, imput_tensors=inputs)

# after
new_model = keras.models.clone_model(model, input_tensors=inputs)
Defensive patterns

Strategy: validation

Validate before calling

import inspect
allowed = inspect.signature(keras.models.clone_model).parameters
kwargs = {k: v for k, v in kwargs.items() if k in allowed}

Try / catch

try:
    keras.models.clone_model(model, **kwargs)
except ValueError as e:
    if 'Unexpected keyword argument' in str(e):
        kwargs = {k: v for k, v in kwargs.items() if k in allowed}
        keras.models.clone_model(model, **kwargs)
    else:
        raise

Prevention

When it happens

Trigger: Calling keras.models.clone_model(model, some_old_arg=...) - a misspelled kwarg like imput_tensors, or kwargs from a different Keras version's signature forwarded via **kwargs.

Common situations: Code written against another Keras version's clone_model signature; wrapper functions that forward **kwargs blindly.

Related errors


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