{"record":{"id":"38c43166cd578675","repo":"keras-team/keras","slug":"arguments-clone-function-and-input-tensors-are","errorCode":null,"errorMessage":"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}","messagePattern":"Arguments `clone_function` and `input_tensors` are only supported for Sequential models or Functional models\\. Received model of type '(.+?)', with clone_function=(.+?) and input_tensors=(.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/models/cloning.py","lineNumber":191,"sourceCode":"        # If the get_config() method is the same as a regular Functional\n        # model, we're safe to use _clone_functional_model (which relies\n        # on a Functional constructor). In the case where the get_config\n        # is custom, this may not necessarily work, but if clone_function\n        # or input_tensors are passed, we attempt it anyway\n        # in order to preserve backwards compatibility.\n        if utils.is_default(model.get_config) or (\n            clone_function or input_tensors\n        ):\n            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    )","sourceCodeStart":173,"sourceCodeEnd":209,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/models/cloning.py#L173-L209","documentation":"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.","triggerScenarios":"keras.models.clone_model(my_subclassed_model, clone_function=fn) or input_tensors=tensor where the model is neither Sequential nor Functional.","commonSituations":"Model-agnostic cloning utilities; subclassed models embedding custom training logic, common in research code.","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."],"exampleFix":"# before\nclone = keras.models.clone_model(subclassed_model, clone_function=fn)\n\n# after\nclone = keras.models.clone_model(subclassed_model)  # config round-trip","handlingStrategy":"type-guard","validationCode":"if not isinstance(model, keras.Sequential) and not is_functional(model):\n    assert not clone_function and not input_tensors, 'clone_function/input_tensors only for Sequential/Functional'","typeGuard":"def supports_clone_args(model) -> bool:\n    import keras\n    return isinstance(model, keras.Sequential) or getattr(model, '_is_graph_network', False)","tryCatchPattern":null,"preventionTips":["Give subclassed models working get_config/from_config so plain clone_model works."],"tags":["keras","models","clone-model","subclassed-model","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"}