{"record":{"id":"d87f87ab8a137f22","repo":"keras-team/keras","slug":"argument-input-tensors-must-contain-a-single-ten","errorCode":null,"errorMessage":"Argument `input_tensors` must contain a single tensor.","messagePattern":"Argument `input_tensors` must contain a single tensor\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/models/cloning.py","lineNumber":308,"sourceCode":"\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\n    if input_tensors is not None:\n        if isinstance(input_tensors, (list, tuple)):\n            if len(input_tensors) != 1:\n                raise ValueError(\n                    \"Argument `input_tensors` must contain a single tensor.\"\n                )\n            input_tensors = input_tensors[0]\n        if not isinstance(input_tensors, backend.KerasTensor):\n            raise ValueError(\n                \"Argument `input_tensors` must be a KerasTensor. \"\n                f\"Received invalid value: input_tensors={input_tensors}\"\n            )\n        inputs = Input(\n            tensor=input_tensors,\n            name=input_name,\n            optional=input_optional,\n        )\n        new_layers = [inputs] + new_layers\n    else:\n        if input_batch_shape is not None:\n            inputs = Input(\n                batch_shape=input_batch_shape,","sourceCodeStart":290,"sourceCodeEnd":326,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/models/cloning.py#L290-L326","documentation":"When cloning a Sequential model onto new inputs, input_tensors must reduce to exactly one tensor because a Sequential model has a single input. A list/tuple with zero or two-plus tensors raises this ValueError.","triggerScenarios":"clone_model(seq_model, input_tensors=[]) or input_tensors=[t1, t2] - a list whose length is not 1.","commonSituations":"Generic cloning code that always wraps inputs in a list; adapting multi-input Functional examples to Sequential.","solutions":["Pass the single tensor directly (no list), or a one-element list: input_tensors=[t].","For genuinely multi-input models, use a Functional model instead of Sequential."],"exampleFix":"# before\nclone = keras.models.clone_model(seq_model, input_tensors=[t1, t2])\n\n# after\nclone = keras.models.clone_model(seq_model, input_tensors=t1)","handlingStrategy":"validation","validationCode":"if isinstance(input_tensors, (list, tuple)):\n    assert len(input_tensors) == 1, 'Sequential clone takes exactly one input tensor'\n    input_tensors = input_tensors[0]","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pass a bare tensor for single-input models.","Use Functional models for multi-input architectures."],"tags":["keras","models","clone-model","sequential","input-tensors"],"backgroundTag":"wrong-argument-cardinality","analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}