{"record":{"id":"7fee0e8f4f11a6f7","repo":"keras-team/keras","slug":"graph-disconnected-cannot-find-parent-for-tensor","errorCode":null,"errorMessage":"Graph disconnected: cannot find parent for tensor {x} at operation '{operation}'. The following previous operations were accessed without issue: {operations_with_complete_input}","messagePattern":"Graph disconnected: cannot find parent for tensor (.+?) at operation '(.+?)'\\. The following previous operations were accessed without issue: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/ops/function.py","lineNumber":368,"sourceCode":"\n    # Get sorted list of node depths.\n    depth_keys = list(nodes_by_depth.keys())\n    depth_keys.sort(reverse=True)\n\n    # Check that all tensors required are computable.\n    # computable_tensors: all tensors in the graph\n    # that can be computed from the inputs provided.\n    computable_tensors = set()\n    for x in inputs:\n        computable_tensors.add(x)\n\n    operations_with_complete_input = []  # To provide a better error msg.\n    for depth in depth_keys:\n        for node in nodes_by_depth[depth]:\n            for x in tree.flatten(node.input_tensors):\n                if x not in computable_tensors:\n                    operation = node.operation\n                    raise ValueError(\n                        \"Graph disconnected: cannot find parent for \"\n                        f\"tensor {x} at operation '{operation}'. \"\n                        \"The following previous operations were accessed \"\n                        f\"without issue: {operations_with_complete_input}\"\n                    )\n                operations_with_complete_input.append(node.operation.name)\n\n            for x in tree.flatten(node.outputs):\n                computable_tensors.add(x)\n\n    # Ensure name unicity, which will be crucial for serialization\n    # (since serialized nodes refer to operations by their name).\n    all_names = [operation.name for operation in operations]\n    for name in all_names:\n        if all_names.count(name) != 1:\n            raise ValueError(\n                f'The name \"{name}\" is used {all_names.count(name)} '\n                \"times in the model. All operation names should be unique.\"","sourceCodeStart":350,"sourceCodeEnd":386,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/ops/function.py#L350-L386","documentation":"When building a keras.ops.Function, map_graph walks the symbolic graph and requires every input tensor of every node to be producible from the function's declared inputs or constants. If a node consumes a tensor that was never connected to the provided inputs, the graph is disconnected and this ValueError names the orphan tensor and its operation.","triggerScenarios":"Creating keras.ops.Function(inputs, outputs) where an output depends on a KerasTensor that is not downstream of any input in inputs — typically an intermediate tensor from another model captured by mistake, or using a layer's output instead of the layer call on the input.","commonSituations":"Refactoring functional code and passing the wrong tensor into outputs; mixing shared layers across models so an output references another model's tensor; extracting intermediate outputs with the wrong variable; copy-paste wiring mistakes in multi-branch models.","solutions":["Trace every tensor listed in outputs back to the declared inputs and fix the branch that starts from an unrelated KerasTensor","Pass all required source tensors in the inputs list","If the orphan tensor comes from another model, re-declare it as an explicit input (keras.Input) or rebuild that part of the graph on top of your inputs"],"exampleFix":"# before\nx = keras.Input((28,28,1))\ny = some_other_model_output  # unrelated KerasTensor\nout = layers.Add()([x, y])\nfn = keras.ops.Function(x, out)  # Graph disconnected\n\n# after\nx2 = keras.Input((28,28,1))\ny2 = layers.Add()([x, x2])\nfn = keras.ops.Function([x, x2], y2)","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Build outputs only from tensors derived from the declared inputs","When extracting intermediate outputs, pass them as extra outputs of the same Function, not from another graph","Run model.summary()/plot to visually verify connectivity before wrapping in Function"],"tags":["keras","graph","disconnected-graph","functional-api"],"backgroundTag":"disconnected-computation-graph","analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}