{"record":{"id":"e7c1e4e2700e950c","repo":"keras-team/keras","slug":"expected-clone-function-argument-to-be-a-callabl","errorCode":null,"errorMessage":"Expected `clone_function` argument to be a callable. Received: clone_function={clone_function}","messagePattern":"Expected `clone_function` argument to be a callable\\. Received: clone_function=(.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/models/cloning.py","lineNumber":286,"sourceCode":"            placeholders will be created.\n        clone_function: callable to be applied on non-input layers in the model.\n            By default, it clones the layer (without copying the weights).\n\n    Returns:\n        An instance of `Sequential` reproducing the behavior\n        of the original model, on top of new inputs tensors,\n        using newly instantiated weights.\n    \"\"\"\n\n    if not isinstance(model, Sequential):\n        raise ValueError(\n            \"Expected `model` argument \"\n            \"to be a `Sequential` model instance. \"\n            f\"Received: model={model}\"\n        )\n\n    if not callable(clone_function):\n        raise ValueError(\n            \"Expected `clone_function` argument to be a callable. \"\n            f\"Received: clone_function={clone_function}\"\n        )\n\n    new_layers = [clone_function(layer) for layer in model.layers]\n\n    if isinstance(model._layers[0], InputLayer):\n        ref_input_layer = model._layers[0]\n        input_name = ref_input_layer.name\n        input_batch_shape = ref_input_layer.batch_shape\n        input_dtype = ref_input_layer._dtype\n        input_optional = ref_input_layer.optional\n    else:\n        input_name = None\n        input_dtype = None\n        input_batch_shape = None\n        input_optional = False\n","sourceCodeStart":268,"sourceCodeEnd":304,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/models/cloning.py#L268-L304","documentation":"_clone_sequential_model() requires clone_function to be callable because it maps it over every layer: [clone_function(layer) for layer in model.layers]. Passing None, a string, or any non-callable object raises this ValueError.","triggerScenarios":"_clone_sequential_model(model, clone_function=None) or clone_function='default' - anything not callable.","commonSituations":"Config-driven cloning where clone_function arrives as a string name; passing a class or module instead of a function.","solutions":["Pass a callable such as lambda layer: layer.__class__.from_config(layer.get_config()), or omit clone_function to use the default.","If the function arrives serialized as a string, resolve it through a registry dict first."],"exampleFix":"# before\nclone = keras.models.clone_model(model, clone_function='copy_layer')\n\n# after\ndef copy_layer(layer):\n    return layer.__class__.from_config(layer.get_config())\nclone = keras.models.clone_model(model, clone_function=copy_layer)","handlingStrategy":"type-guard","validationCode":"assert callable(clone_function), 'clone_function must be callable'","typeGuard":"def is_callable_fn(f) -> bool:\n    return callable(f)","tryCatchPattern":null,"preventionTips":["Resolve string-named clone functions through an explicit registry before passing them."],"tags":["keras","models","clone-model","callable-check","type-check"],"backgroundTag":"wrong-argument-type","analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}