LSTM output with open memory workspace exception

Hello everyone,

If I am trying to get output with LSTM network inside open workspace, I am using this method output(inputINDArray, false, activeWs) as I am using with others non recurrent nets. But in case of LSTMs I am getting this exception:

Exception in thread “main” org.nd4j.linalg.workspace.ND4JWorkspaceException: Cannot duplicate INDArray: Array outdated workspace pointer from workspace EVALUATION (array generation 1, current workspace generation 2)
at org.nd4j.linalg.workspace.WorkspaceUtils.assertValidArray(
at org.nd4j.linalg.api.ndarray.BaseNDArray.dup(
at org.deeplearning4j.nn.layers.recurrent.LSTMHelpers.activateHelper(
at org.deeplearning4j.nn.layers.recurrent.LSTM.activateHelper(
at org.deeplearning4j.nn.layers.recurrent.LSTM.activate(
at org.deeplearning4j.nn.multilayer.MultiLayerNetwork.outputOfLayerDetached(
at org.deeplearning4j.nn.multilayer.MultiLayerNetwork.output(
at org.deeplearning4j.nn.multilayer.MultiLayerNetwork.output(

Should this work with open workspace, or am I doing something wrong? I am getting same exception with CPU and also with GPU backend.

Thank you in advance for the advice

Could you post how you’re attempting to use workspaces here?

Of course :slight_smile:

private WorkspaceConfiguration configuration;

private WorkspaceConfiguration getConfiguration() {
    if (configuration == null) {
        configuration = WorkspaceConfiguration.builder()
    return configuration;

public void eval(TimeSeriesSampleList sampleList) {
    MemoryWorkspace workspace = Nd4j.getWorkspaceManager().getWorkspaceForCurrentThread(getConfiguration(), "EVALUATION");

    int index = 0;
    int size = sampleList.size();
    while (index < size) {
        MemoryWorkspace ws = workspace.notifyScopeEntered();
        int n = (index + batchSize) < size ? batchSize : size - index;
        List<TimeSeriesSample> batch = sampleList.subList(index, index + n);
        INDArray input = Nd4j.create(dataType, n, nFeatures, nInput);

        for (int j = 0; j < batch.size(); j++) {
            TimeSeriesSample sample = batch.get(j);
            input.put(new INDArrayIndex[]{new PointIndex(j)}, sample.getInput()); // sample.getInput() create new INDArray

        double[][] output = model.output(input, false, ws).toDoubleMatrix();
        index += n;