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:

Blockquote
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)
All open workspaces: [WS_LAYER_WORKING_MEM, EVALUATION, WS_LAYER_ACT_1]
at org.nd4j.linalg.workspace.WorkspaceUtils.assertValidArray(WorkspaceUtils.java:126)
at org.nd4j.linalg.api.ndarray.BaseNDArray.dup(BaseNDArray.java:1707)
at org.deeplearning4j.nn.layers.recurrent.LSTMHelpers.activateHelper(LSTMHelpers.java:132)
at org.deeplearning4j.nn.layers.recurrent.LSTM.activateHelper(LSTM.java:171)
at org.deeplearning4j.nn.layers.recurrent.LSTM.activate(LSTM.java:143)
at org.deeplearning4j.nn.multilayer.MultiLayerNetwork.outputOfLayerDetached(MultiLayerNetwork.java:1301)
at org.deeplearning4j.nn.multilayer.MultiLayerNetwork.output(MultiLayerNetwork.java:2419)
at org.deeplearning4j.nn.multilayer.MultiLayerNetwork.output(MultiLayerNetwork.java:2400)

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()
                .policyLearning(LearningPolicy.FIRST_LOOP)
                .policyAllocation(AllocationPolicy.STRICT)
                .build();
    }
    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;
        ws.close();
    }