# Cannot read the array length because "inputsForOp" is null

**URL:** <https://community.konduit.ai/t/cannot-read-the-array-length-because-inputsforop-is-null/1961>\
**Category:** SameDiff\
**Created:** [August 16, 2022, 2:41pm UTC](https://community.konduit.ai/t/cannot-read-the-array-length-because-inputsforop-is-null/1961 "2022-08-16T14:41:24Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![SidneyLann](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/sidneylann/32/367_2.png) [@SidneyLann](https://community.konduit.ai/u/SidneyLann)\
**Post date:** [August 16, 2022, 2:41pm UTC](https://community.konduit.ai/t/cannot-read-the-array-length-because-inputsforop-is-null/1961/1 "2022-08-16T14:41:24Z")

</div>

This issue mark fixed at #9145 and # 9744, but the exception still exists in M2.1

exception in M2:  
java.lang.NullPointerException: Cannot load from object array because “inputsForOp” is null  
at org.nd4j.linalg.api.ops.impl.layers.recurrent.LSTMLayer.configureWithSameDiff(LSTMLayer.java:210)  
at org.nd4j.autodiff.samediff.SameDiff.fromFlatBuffers(SameDiff.java:5503)  
at org.nd4j.autodiff.samediff.SameDiff.fromFlatFile(SameDiff.java:5359)  
at org.nd4j.autodiff.samediff.SameDiff.load(SameDiff.java:5250)  
at org.nd4j.autodiff.listeners.checkpoint.CheckpointListener.loadCheckpoint(CheckpointListener.java:407)

exception in M2.1:  
java.lang.NullPointerException: Cannot read the array length because “inputsForOp” is null  
at org.nd4j.linalg.api.ops.impl.layers.recurrent.LSTMLayer.configureWithSameDiff(LSTMLayer.java:210)  
at org.nd4j.autodiff.samediff.SameDiff.fromFlatBuffers(SameDiff.java:6058)  
at org.nd4j.autodiff.samediff.SameDiff.fromFlatFile(SameDiff.java:5914)  
at org.nd4j.autodiff.samediff.SameDiff.load(SameDiff.java:5805)  
at org.nd4j.autodiff.listeners.checkpoint.CheckpointListener.loadCheckpoint(CheckpointListener.java:407)  
at org.nd4j.autodiff.listeners.checkpoint.CheckpointListener.loadLastCheckpoint(CheckpointListener.java:417)

---

<div class="post-metadata">

**Author:** ![agibsonccc](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/agibsonccc/32/697_2.png) [@agibsonccc](https://community.konduit.ai/u/agibsonccc)\
**Post date:** [August 25, 2022, 1:16am UTC](https://community.konduit.ai/t/cannot-read-the-array-length-because-inputsforop-is-null/1961/2 "2022-08-25T01:16:16Z")

</div>

@SidneyLann do you have the model?

---

<div class="post-metadata">

**Author:** ![SidneyLann](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/sidneylann/32/367_2.png) [@SidneyLann](https://community.konduit.ai/u/SidneyLann)\
**Post date:** [August 25, 2022, 2:48pm UTC](https://community.konduit.ai/t/cannot-read-the-array-length-because-inputsforop-is-null/1961/3 "2022-08-25T14:48:41Z")

</div>

I sent you my project before, it contains the model. Or you can remove the old model and change it to use M2.1 and train several minutes and then get a model. thanks.

---

<div class="post-metadata">

**Author:** ![agibsonccc](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/agibsonccc/32/697_2.png) [@agibsonccc](https://community.konduit.ai/u/agibsonccc)\
**Post date:** [August 30, 2022, 4:54am UTC](https://community.konduit.ai/t/cannot-read-the-array-length-because-inputsforop-is-null/1961/4 "2022-08-30T04:54:15Z")

</div>

@SidneyLann let me see if this does it: [Fixes #9756 by agibsonccc · Pull Request #9757 · deeplearning4j/deeplearning4j · GitHub](https://github.com/deeplearning4j/deeplearning4j/pull/9757) In my tests everything ran. Not sure what the difference was. Part of it was also just some changes not being committed properly (likely a botched pull request merge)

Sorry for the confusion. I’ll do another point release to address this.

---

<div class="post-metadata">

**Author:** ![SidneyLann](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/sidneylann/32/367_2.png) [@SidneyLann](https://community.konduit.ai/u/SidneyLann)\
**Post date:** [August 30, 2022, 4:57am UTC](https://community.konduit.ai/t/cannot-read-the-array-length-because-inputsforop-is-null/1961/5 "2022-08-30T04:57:13Z")

</div>

OK. Thank you for your help!

---

<div class="post-metadata">

**Author:** ![SidneyLann](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/sidneylann/32/367_2.png) [@SidneyLann](https://community.konduit.ai/u/SidneyLann)\
**Post date:** [September 13, 2022, 2:42am UTC](https://community.konduit.ai/t/cannot-read-the-array-length-because-inputsforop-is-null/1961/6 "2022-09-13T02:42:22Z")

</div>

This issue still exists.  
java.lang.NullPointerException: Cannot load from object array because “inputsForOp” is null  
at org.nd4j.linalg.api.ops.impl.layers.recurrent.LSTMLayer.configureWithSameDiff(LSTMLayer.java:210)  
at org.nd4j.autodiff.samediff.SameDiff.fromFlatBuffers(SameDiff.java:5503)  
at org.nd4j.autodiff.samediff.SameDiff.fromFlatFile(SameDiff.java:5359)  
at org.nd4j.autodiff.samediff.SameDiff.load(SameDiff.java:5250)  
at org.nd4j.autodiff.listeners.checkpoint.CheckpointListener.loadCheckpoint(CheckpointListener.java:407)  
at org.nd4j.autodiff.listeners.checkpoint.CheckpointListener.loadLastCheckpoint(CheckpointListener.java:417)

---

<div class="post-metadata">

**Author:** ![agibsonccc](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/agibsonccc/32/697_2.png) [@agibsonccc](https://community.konduit.ai/u/agibsonccc)\
**Post date:** [September 13, 2022, 2:52am UTC](https://community.konduit.ai/t/cannot-read-the-array-length-because-inputsforop-is-null/1961/7 "2022-09-13T02:52:08Z")

</div>

@SidneyLann what version are you using? If you look straight at the source this is impossible. We do a null check right here:

> <https://github.com/deeplearning4j/deeplearning4j/blob/29fd9c70c0dfa690ccedba130b43dc3e36c37b24/nd4j/nd4j-backends/nd4j-api-parent/nd4j-api/src/main/java/org/nd4j/linalg/api/ops/impl/layers/recurrent/LSTMLayer.java#L210>

@SidneyLann edit: I downloaded the source for M2.1. It appears that’s still in there. It’s already fixed in master so I guess just use snapshots. I’ll be doing another release soon anyways after checking one more issue.

---

<div class="post-metadata">

**Author:** ![SidneyLann](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/sidneylann/32/367_2.png) [@SidneyLann](https://community.konduit.ai/u/SidneyLann)\
**Post date:** [September 13, 2022, 7:45am UTC](https://community.konduit.ai/t/cannot-read-the-array-length-because-inputsforop-is-null/1961/8 "2022-09-13T07:45:08Z")

</div>

![image](https://canada1.discourse-cdn.com/flex035/uploads/konduit/original/1X/d0d87dcb1773b7af8f784dc40ae3ef802b66796f.png)  
 ![image](https://canada1.discourse-cdn.com/flex035/uploads/konduit/original/1X/7c7915c20524474b5653a78ff0ea9fce5ae6b09d.png)

I can’t download new jar, the pom setting is not correct?

---

<div class="post-metadata">

**Author:** ![agibsonccc](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/agibsonccc/32/697_2.png) [@agibsonccc](https://community.konduit.ai/u/agibsonccc)\
**Post date:** [September 13, 2022, 12:28pm UTC](https://community.konduit.ai/t/cannot-read-the-array-length-because-inputsforop-is-null/1961/9 "2022-09-13T12:28:57Z")

</div>

@SidneyLann that’s the old sonatype host. You need to use [s01.oss.sonatype.org](http://s01.oss.sonatype.org) now.

---

<div class="post-metadata">

**Author:** ![SidneyLann](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/sidneylann/32/367_2.png) [@SidneyLann](https://community.konduit.ai/u/SidneyLann)\
**Post date:** [September 13, 2022, 12:37pm UTC](https://community.konduit.ai/t/cannot-read-the-array-length-because-inputsforop-is-null/1961/10 "2022-09-13T12:37:52Z")

</div>

Thanks. But NPE at this line now:  
builder.peepholeWeights(sameDiff.getVariable(inputsForOp[inputsForOp.length - 1]));

java.lang.NullPointerException: Cannot read the array length because “inputsForOp” is null  
at org.nd4j.linalg.api.ops.impl.layers.recurrent.LSTMLayer.configureWithSameDiff(LSTMLayer.java:205)

Need to check all references to inputsForOp.

---

<div class="post-metadata">

**Author:** ![agibsonccc](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/agibsonccc/32/697_2.png) [@agibsonccc](https://community.konduit.ai/u/agibsonccc)\
**Post date:** [September 13, 2022, 1:22pm UTC](https://community.konduit.ai/t/cannot-read-the-array-length-because-inputsforop-is-null/1961/11 "2022-09-13T13:22:11Z")

</div>

> [@SidneyLann](#):
>
> riable(inpu

@SidneyLann I wonder if this is actually burying a deeper problem somewhere…has peephole and those booleans are either wrong or the state configured there mismatches your parameters. Before we go out of our way adding null checks for everything I want to make sure that we’re not trying to just work around a problem somewhere else.

---

<div class="post-metadata">

**Author:** ![SidneyLann](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/sidneylann/32/367_2.png) [@SidneyLann](https://community.konduit.ai/u/SidneyLann)\
**Post date:** [September 14, 2022, 12:08am UTC](https://community.konduit.ai/t/cannot-read-the-array-length-because-inputsforop-is-null/1961/12 "2022-09-14T00:08:42Z")

</div>

```
    if(inputsForOp != null && hasBiases) {
        builder.bias(sameDiff.getVariable(inputsForOp[3]));
    }

    if(inputsForOp != null && hasPH) {
        builder.peepholeWeights(sameDiff.getVariable(inputsForOp[inputsForOp.length - 1]));
    }

```

When I check like this, it can be trained and reloaded to train.

---

<div class="post-metadata">

**Author:** ![agibsonccc](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/agibsonccc/32/697_2.png) [@agibsonccc](https://community.konduit.ai/u/agibsonccc)\
**Post date:** [September 14, 2022, 3:57am UTC](https://community.konduit.ai/t/cannot-read-the-array-length-because-inputsforop-is-null/1961/13 "2022-09-14T03:57:01Z")

</div>

@SidneyLann I haven’t looked at this yet but the main thing I wanted to look at was to see if the neural network was imported correctly. There seems to be something off with variables being missing. I haven’t seen that a lot and want to make sure everything is correct.
