deeplearning4j/deeplearning4j · error · UnsupportedOperationException

Not supported

Error message

Not supported

What it means

SoftPlusBp (the backward/backprop op of softplus) is a leaf in the SameDiff differentiation graph: its doDiff() is deliberately unimplemented and always throws UnsupportedOperationException('Not supported'). In ND4J, *_Bp ops exist to propagate gradients, and their own gradient (differentiating the bp op again) is not defined, so the library refuses instead of returning a wrong result. This means second-order differentiation through a softplus bp node is impossible.

Solutions

  1. Restructure the graph so SoftPlusBp appears only in the forward-of-backward path, never inside a region being differentiated again.
  2. Use the plain SoftPlus op and let SameDiff derive its derivative automatically instead of manually inserting the Bp op.
  3. Override/replace the node with a custom DifferentialFunction whose doDiff is implemented (e.g. via sameDiff.math on primitives).

Example fix

// before
SDVariable bp = sameDiff.nn.softPlusBp(input, eps);
SDVariable loss = secondOrderLoss(bp); // differentiates bp again -> throws
// after
SDVariable sp = sameDiff.nn.softPlus(input);            // differentiable primitive
SDVariable loss = secondOrderLoss(sp);                  // autodiff handles derivative
Defensive patterns

Strategy: validation

Validate before calling

boolean diffable(SameDiff sd, String varName) {
    SameDiff fn = sd.getFunction("grad"); // or inspect ops before differentiating
    return sd.ops().stream().noneMatch(o -> o instanceof org.nd4j.linalg.api.ops.impl.transforms.gradient.SoftPlusBp);
}

Try / catch

try {
    sd.createGradFunction();
} catch (UnsupportedOperationException e) {
    if (e.getMessage().contains("Not supported")) {
        // rebuild graph using plain SoftPlus instead of SoftPlusBp
    } else throw e;
}

Prevention

When it happens

Trigger: Calling SameDiff differencing (e.g. SDVariable.diff(), SameDiff.createGradFunction(), or automatic differentiation) on a graph that contains a SoftPlusBp node, so the framework must compute the gradient OF the softplus_bp op itself.

Common situations: Building higher-order gradients (gradient of gradient) over networks using softplus; custom loss functions that differentiate through an explicitly constructed *Bp op; porting models that assume nested autodiff support.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of deeplearning4j/deeplearning4j@4c22ac5fe4 (2026-09-07). Data as JSON: /api/errors/0d5a977a7225f6db. Report an issue: GitHub.

Appendix: source

Thrown at nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/ops/impl/transforms/gradient/SoftPlusBp.java:61

    }

    @Override
    public String opName(){
        return "softplus_bp";
    }

    @Override
    public List<DataType> calculateOutputDataTypes(List<DataType> dataTypes) {
        Preconditions
                .checkArgument(dataTypes != null && dataTypes.size() == 2, "Expected exactly 2 input datatypes, got %s", dataTypes);
        Preconditions.checkArgument(dataTypes.get(0).isFPType() && dataTypes.get(1).isFPType(), "Input datatypes must be floating point, got %s", dataTypes);

        return Collections.singletonList(dataTypes.get(0));
    }

    @Override
    public List<SDVariable> doDiff(List<SDVariable> f1) {
        throw new UnsupportedOperationException("Not supported");
    }
}

View on GitHub (pinned to 4c22ac5fe4)