{"record":{"id":"00a9b396da8cd4b1","repo":"keras-team/keras","slug":"argument-call-function-is-only-supported-for-fun","errorCode":null,"errorMessage":"Argument `call_function` is only supported for Functional models. Received model of type '{model.__class__.__name__}', with call_function={clone_function}","messagePattern":"Argument `call_function` is only supported for Functional models\\. Received model of type '(.+?)', with call_function=(.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/models/cloning.py","lineNumber":200,"sourceCode":"            return _clone_functional_model(\n                model,\n                clone_function=clone_function,\n                call_function=call_function,\n                input_tensors=input_tensors,\n            )\n\n    # Case of a custom model class\n    if clone_function or input_tensors:\n        raise ValueError(\n            \"Arguments `clone_function` and `input_tensors` \"\n            \"are only supported for Sequential models \"\n            \"or Functional models. Received model of \"\n            f\"type '{model.__class__.__name__}', with \"\n            f\"clone_function={clone_function} and \"\n            f\"input_tensors={input_tensors}\"\n        )\n    if call_function is not None:\n        raise ValueError(\n            \"Argument `call_function` is only supported \"\n            \"for Functional models. Received model of \"\n            f\"type '{model.__class__.__name__}', with \"\n            f\"call_function={clone_function}\"\n        )\n    config = serialization_lib.serialize_keras_object(model)\n    return serialization_lib.deserialize_keras_object(\n        config, custom_objects={model.__class__.__name__: model.__class__}\n    )\n\n\ndef _wrap_clone_function(\n    clone_function, call_function=None, recursive=False, cache=None\n):\n    \"\"\"Wrapper to handle recursiveness and layer sharing.\"\"\"\n    if clone_function is None:\n\n        def _clone_layer(layer):","sourceCodeStart":182,"sourceCodeEnd":218,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/models/cloning.py#L182-L218","documentation":"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.","triggerScenarios":"keras.models.clone_model(sequential_or_subclassed_model, call_function=fn).","commonSituations":"Sharing one cloning helper across Functional and Sequential/subclassed models; call-graph surgery code applied indiscriminately.","solutions":["Restrict call_function to Functional models: check the model type before passing it.","For subclassed or Sequential models, call clone_model(model) plain or rebuild the model manually."],"exampleFix":"# before\nclone = keras.models.clone_model(model, call_function=fn)  # model is Sequential\n\n# after\nkwargs = {'call_function': fn} if is_functional(model) else {}\nclone = keras.models.clone_model(model, **kwargs)","handlingStrategy":"type-guard","validationCode":"if call_function is not None:\n    assert is_functional(model), 'call_function requires a Functional model'","typeGuard":"def is_functional(model) -> bool:\n    return getattr(model, '_is_graph_network', False)","tryCatchPattern":null,"preventionTips":["Only pass call_function on models built from keras.Input."],"tags":["keras","models","clone-model","functional","unsupported-argument"],"backgroundTag":"unsupported-argument-for-type","analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}