{"record":{"id":"0d1ddcabd3b0341c","repo":"keras-team/keras","slug":"expected-model-argument-to-be-a-sequential-mod","errorCode":null,"errorMessage":"Expected `model` argument to be a `Sequential` model instance. Received: model={model}","messagePattern":"Expected `model` argument to be a `Sequential` model instance\\. Received: model=(.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/models/cloning.py","lineNumber":279,"sourceCode":"    except that it creates new layers (and thus new weights) instead\n    of sharing the weights of the existing layers.\n\n    Args:\n        model: Instance of `Sequential`.\n        input_tensors: optional list of input tensors\n            to build the model upon. If not provided,\n            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","sourceCodeStart":261,"sourceCodeEnd":297,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/models/cloning.py#L261-L297","documentation":"_clone_sequential_model() is the internal Sequential branch of clone_model and asserts its model argument is a Sequential instance. If a non-Sequential reaches it (usually via direct internal calls or broken type dispatch), it raises this ValueError echoing the received object.","triggerScenarios":"Directly calling keras.src.models.cloning._clone_sequential_model(functional_or_custom_model); indirectly when a Sequential-lookalike does not actually subclass keras.Sequential.","commonSituations":"Copy-pasting internal cloning code; custom model classes that mimic Sequential's API but do not subclass it.","solutions":["Use the public keras.models.clone_model(model), which dispatches by model type.","Ensure your model actually subclasses keras.Sequential if you rely on Sequential-specific cloning.","For lookalike classes, clone from config: type(model).from_config(model.get_config())."],"exampleFix":"# before\nfrom keras.src.models.cloning import _clone_sequential_model\nclone = _clone_sequential_model(my_model, clone_function=fn)\n\n# after\nclone = keras.models.clone_model(my_model, clone_function=fn)","handlingStrategy":"type-guard","validationCode":"import keras\nassert isinstance(model, keras.Sequential), 'use keras.models.clone_model for non-Sequential models'","typeGuard":"import keras\ndef is_sequential(m) -> bool:\n    return isinstance(m, keras.Sequential)","tryCatchPattern":null,"preventionTips":["Never call private _clone_sequential_model; use the public clone_model."],"tags":["keras","models","clone-model","sequential","internal-api","type-check"],"backgroundTag":"wrong-argument-type","analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}