{"record":{"id":"3699aa0d48565319","repo":"deeplearning4j/deeplearning4j","slug":"cannot-do-forward-pass-inputs-not-set-3699aa","errorCode":null,"errorMessage":"Cannot do forward pass: inputs not set","messagePattern":"Cannot do forward pass: inputs not set","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"deeplearning4j/deeplearning4j-nn/src/main/java/org/deeplearning4j/nn/graph/vertex/impl/MergeVertex.java","lineNumber":77,"sourceCode":"    @Override\n    public String toString() {\n        return \"MergeVertex(id=\" + this.getVertexIndex() + \",name=\\\"\" + this.getVertexName() + \"\\\")\";\n    }\n\n    @Override\n    public boolean hasLayer() {\n        return false;\n    }\n\n    @Override\n    public Layer getLayer() {\n        return null;\n    }\n\n    @Override\n    public INDArray doForward(boolean training, LayerWorkspaceMgr workspaceMgr) {\n        if (!canDoForward())\n            throw new IllegalStateException(\"Cannot do forward pass: inputs not set\");\n\n        if (inputs.length == 1) {\n            //No-op case\n            val shape = inputs[0].shape();\n            forwardPassShapes = new long[][] {Arrays.copyOf(shape, shape.length)};\n            return workspaceMgr.leverageTo(ArrayType.ACTIVATIONS, inputs[0]);\n        }\n\n        INDArray[] in = new INDArray[inputs.length];\n        for( int  i= 0; i < in.length; i++) {\n            in[i] = inputs[i].castTo(dataType); //No-op if correct type\n        }\n\n        forwardPassShapes = new long[in.length][0];\n        val nExamples = in[0].size(0);\n        fwdPassRank = in[0].rank();\n        for (int i = 0; i < in.length; i++) {\n            val currShape = in[i].shape();","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/deeplearning4j/deeplearning4j/blob/4c22ac5fe4a8350d05d224e7f4499429f7f69c93/deeplearning4j/deeplearning4j-nn/src/main/java/org/deeplearning4j/nn/graph/vertex/impl/MergeVertex.java#L59-L95","documentation":"MergeVertex.doForward() throws this IllegalStateException when canDoForward() reports that the vertex's inputs array has not been populated before a forward pass is requested. In DL4J's ComputationGraph, each vertex must receive its input activations (via setInputs) before doForward is called; the forward pass cannot proceed without them. It is an internal state/lifecycle error, typically a symptom of the graph not having been fed inputs correctly.","triggerScenarios":"Calling doForward (directly or via ComputationGraph.feedForward) on a MergeVertex whose setInputs() was never called, or was called with a null/empty array, or whose inputs were cleared after a reset without re-supplying them.","commonSituations":"Custom graph iteration code that calls vertex forward passes out of order; feeding a subset of graph inputs so upstream activations never reach the merge vertex; calling doForward manually in unit tests without calling setInputs first.","solutions":["Ensure all graph inputs are set via ComputationGraph.setInput(...) or feed(Input... arrays) before running feedForward.","Check the topological order of your custom forward iteration so MergeVertex executes after its source vertices produce activations.","If calling the vertex directly in a test, call setInputs(new INDArray[]{...}) before doForward.","Guard with vertex.canDoForward() before invoking doForward."],"exampleFix":"// before\nINDArray out = mergeVertex.doForward(false, workspaceMgr); // throws: inputs not set\n\n// after\nmergeVertex.setInputs(new INDArray[]{firstActivations, secondActivations});\nINDArray out = mergeVertex.doForward(false, workspaceMgr);","handlingStrategy":"validation","validationCode":"// Java\nif (!mergeVertex.hasInputs() || !mergeVertex.canDoForward()) {\n    mergeVertex.setInputs(new INDArray[]{a, b});\n}","typeGuard":null,"tryCatchPattern":"// Java\ntry {\n    INDArray out = mergeVertex.doForward(training, workspaceMgr);\n} catch (IllegalStateException e) {\n    if (e.getMessage().contains(\"inputs not set\")) {\n        mergeVertex.setInputs(pendingInputs);\n        // retry forward\n    } else { throw e; }\n}","preventionTips":["Always feed all graph inputs before feedForward/fit.","In custom loops, follow topological vertex order.","Check canDoForward() before doForward in test harnesses."],"tags":["deeplearning4j","state","lifecycle","neural-network"],"backgroundTag":"invalid-state-transition","analyzedSha":"4c22ac5fe4a8350d05d224e7f4499429f7f69c93","analyzedAt":"2026-09-07T05:27:04.714Z","contentChangedAt":"2026-09-07T05:27:04.714Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}