{"record":{"id":"5df51fd5c10f6c82","repo":"keras-team/keras","slug":"unexpected-keyword-argument-s-tuple-kwargs-keys","errorCode":null,"errorMessage":"Unexpected keyword argument(s): {tuple(kwargs.keys())}","messagePattern":"Unexpected keyword argument\\(s\\): (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/models/cloning.py","lineNumber":137,"sourceCode":"    ```\n\n    Note that subclassed models cannot be cloned by default,\n    since their internal layer structure is not known.\n    To achieve equivalent functionality\n    as `clone_model` in the case of a subclassed model, simply make sure\n    that the model class implements `get_config()`\n    (and optionally `from_config()`), and call:\n\n    ```python\n    new_model = model.__class__.from_config(model.get_config())\n    ```\n\n    In the case of a subclassed model, you cannot using a custom\n    `clone_function`.\n    \"\"\"\n    cache = kwargs.pop(\"cache\", None)\n    if kwargs:\n        raise ValueError(\n            f\"Unexpected keyword argument(s): {tuple(kwargs.keys())}\"\n        )\n\n    if isinstance(model, Sequential):\n        # Wrap clone_function to handle recursiveness and layer sharing.\n        clone_function = _wrap_clone_function(\n            clone_function,\n            call_function=call_function,\n            recursive=recursive,\n            cache=cache,\n        )\n        if call_function is not None:\n            raise ValueError(\n                \"`call_function` argument is not supported with Sequential \"\n                \"models.  In a Sequential model, layers aren't called \"\n                \"at model-construction time (they're merely listed). \"\n                \"Use `call_function` with Functional models only. \"\n                \"Received model of \"","sourceCodeStart":119,"sourceCodeEnd":155,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/models/cloning.py#L119-L155","documentation":"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.","triggerScenarios":"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.","commonSituations":"Code written against another Keras version's clone_model signature; wrapper functions that forward **kwargs blindly.","solutions":["Check the current signature: keras.models.clone_model(model, input_tensors=None, clone_function=None, call_function=None, recursive=False).","Remove or fix the misspelled/unsupported keyword.","If wrapping clone_model, filter kwargs against inspect.signature instead of forwarding **kwargs wholesale."],"exampleFix":"# before\nnew_model = keras.models.clone_model(model, imput_tensors=inputs)\n\n# after\nnew_model = keras.models.clone_model(model, input_tensors=inputs)","handlingStrategy":"validation","validationCode":"import inspect\nallowed = inspect.signature(keras.models.clone_model).parameters\nkwargs = {k: v for k, v in kwargs.items() if k in allowed}","typeGuard":null,"tryCatchPattern":"try:\n    keras.models.clone_model(model, **kwargs)\nexcept ValueError as e:\n    if 'Unexpected keyword argument' in str(e):\n        kwargs = {k: v for k, v in kwargs.items() if k in allowed}\n        keras.models.clone_model(model, **kwargs)\n    else:\n        raise","preventionTips":["Filter **kwargs against the live signature when wrapping clone_model.","Re-check the signature after Keras major-version upgrades."],"tags":["keras","models","clone-model","kwargs","api-mismatch"],"backgroundTag":"unexpected-keyword-argument","analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}