deeplearning4j/deeplearning4j · error · IllegalStateException
Cannot do forward pass: inputs not set
Error message
Cannot do forward pass: inputs not set
What it means
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.
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.
Example fix
// before
INDArray out = mergeVertex.doForward(false, workspaceMgr); // throws: inputs not set
// after
mergeVertex.setInputs(new INDArray[]{firstActivations, secondActivations});
INDArray out = mergeVertex.doForward(false, workspaceMgr); Defensive patterns
Strategy: validation
Validate before calling
// Java
if (!mergeVertex.hasInputs() || !mergeVertex.canDoForward()) {
mergeVertex.setInputs(new INDArray[]{a, b});
} Try / catch
// Java
try {
INDArray out = mergeVertex.doForward(training, workspaceMgr);
} catch (IllegalStateException e) {
if (e.getMessage().contains("inputs not set")) {
mergeVertex.setInputs(pendingInputs);
// retry forward
} else { throw e; }
} Prevention
- Always feed all graph inputs before feedForward/fit.
- In custom loops, follow topological vertex order.
- Check canDoForward() before doForward in test harnesses.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.
Related errors
- Cannot do backward pass: errors not set
- Cannot do backward pass: errors not set
- Cannot do forward pass: inputs not set
- Cannot calculate score without input and labels
- Cannot calculate score without input and labels
AI-assisted analysis of deeplearning4j/deeplearning4j@4c22ac5fe4 (2026-09-07).
Data as JSON: /api/errors/3699aa0d48565319.
Report an issue: GitHub.
Appendix: source
Thrown at deeplearning4j/deeplearning4j-nn/src/main/java/org/deeplearning4j/nn/graph/vertex/impl/MergeVertex.java:77
@Override
public String toString() {
return "MergeVertex(id=" + this.getVertexIndex() + ",name=\"" + this.getVertexName() + "\")";
}
@Override
public boolean hasLayer() {
return false;
}
@Override
public Layer getLayer() {
return null;
}
@Override
public INDArray doForward(boolean training, LayerWorkspaceMgr workspaceMgr) {
if (!canDoForward())
throw new IllegalStateException("Cannot do forward pass: inputs not set");
if (inputs.length == 1) {
//No-op case
val shape = inputs[0].shape();
forwardPassShapes = new long[][] {Arrays.copyOf(shape, shape.length)};
return workspaceMgr.leverageTo(ArrayType.ACTIVATIONS, inputs[0]);
}
INDArray[] in = new INDArray[inputs.length];
for( int i= 0; i < in.length; i++) {
in[i] = inputs[i].castTo(dataType); //No-op if correct type
}
forwardPassShapes = new long[in.length][0];
val nExamples = in[0].size(0);
fwdPassRank = in[0].rank();
for (int i = 0; i < in.length; i++) {
val currShape = in[i].shape();View on GitHub (pinned to 4c22ac5fe4)