# NPE when load TF to SameDiff

**URL:** https://community.konduit.ai/t/npe-when-load-tf-to-samediff/1661
**Category:** SameDiff
**Created:** [October 26, 2021, 8:37am UTC](https://community.konduit.ai/t/npe-when-load-tf-to-samediff/1661 "2021-10-26T08:37:44Z")
**Posts on this page:** 20
**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: [October 26, 2021, 8:37am UTC](https://community.konduit.ai/t/npe-when-load-tf-to-samediff/1661/1 "2021-10-26T08:37:44Z")

</div>

SameDiff sd = SameDiff.importFrozenTF(new File(NerUtil.DATA\_HOME + “/bert/bert\_pretrain\_model\_zh.pb”));

this works in beta7, but below code not works in SNAPSHOT:  
TensorflowFrameworkImporter tensorflowFrameworkImporter = new TensorflowFrameworkImporter();  
SameDiff sd = tensorflowFrameworkImporter.runImport(NerUtil.DATA\_HOME + “/bert/bert\_pretrain\_model\_zh.pb”, Collections.emptyMap());

java.lang.NullPointerException  
at org.nd4j.samediff.frameworkimport.registry.OpMappingRegistry.lookupInputFrameworkOpDef(OpMappingRegistry.kt:99)  
at org.nd4j.samediff.frameworkimport.ir.IRFunctionsKt.importInfoForEachNodeInGraph(IRFunctions.kt:63)  
at org.nd4j.samediff.frameworkimport.tensorflow.ir.TensorflowIRGraph.importInfoForEachNode(TensorflowIRGraph.kt:162)  
at org.nd4j.samediff.frameworkimport.ImportGraph.importGraph(ImportGraph.kt:238)  
at org.nd4j.samediff.frameworkimport.tensorflow.importer.TensorflowFrameworkImporter.importFromGraph(TensorflowFrameworkImporter.kt:58)  
at org.nd4j.samediff.frameworkimport.tensorflow.importer.TensorflowFrameworkImporter.runImport(TensorflowFrameworkImporter.kt:64)

---

<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: [October 26, 2021, 8:39am UTC](https://community.konduit.ai/t/npe-when-load-tf-to-samediff/1661/2 "2021-10-26T08:39:59Z")

</div>

@SidneyLann can you DM me the model? I’d be happy to look at it, we’re importing BERT models fine. I’d be happy to look at the variant here.

---

<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: [October 26, 2021, 10:06am UTC](https://community.konduit.ai/t/npe-when-load-tf-to-samediff/1661/3 "2021-10-26T10:06:53Z")

</div>

But can’t upload zip file here.

---

<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: [October 26, 2021, 9:14pm UTC](https://community.konduit.ai/t/npe-when-load-tf-to-samediff/1661/4 "2021-10-26T21:14:49Z")

</div>

@agibsonccc sent the model to you, please help to check. 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: [October 26, 2021, 10:26pm UTC](https://community.konduit.ai/t/npe-when-load-tf-to-samediff/1661/5 "2021-10-26T22:26:26Z")

</div>

@SidneyLann please check your DMs, the model download was giving me some difficulties.

---

<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: [October 28, 2021, 1:39am UTC](https://community.konduit.ai/t/npe-when-load-tf-to-samediff/1661/6 "2021-10-28T01:39:46Z")

</div>

@agibsonccc Please download from [dl4j - Google Drive](https://drive.google.com/drive/folders/1VbwKHzRiqx45LbzJAUyaGpSIObfGVRHa?usp=sharing)

---

<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: [October 29, 2021, 1:39pm UTC](https://community.konduit.ai/t/npe-when-load-tf-to-samediff/1661/7 "2021-10-29T13:39:01Z")

</div>

@agibsonccc Can import the model in SNAPSHOT?

---

<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: [October 29, 2021, 1:40pm UTC](https://community.konduit.ai/t/npe-when-load-tf-to-samediff/1661/8 "2021-10-29T13:40:37Z")

</div>

@SidneyLann I got your model, sorry will be testing it after my current batch of PRs is merged.

---

<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: [November 8, 2021, 12:48pm UTC](https://community.konduit.ai/t/npe-when-load-tf-to-samediff/1661/9 "2021-11-08T12:48:11Z")

</div>

@agibsonccc Could you fix this issue and then I can test other issues? 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: [November 11, 2021, 9:48pm UTC](https://community.konduit.ai/t/npe-when-load-tf-to-samediff/1661/10 "2021-11-11T21:48:19Z")

</div>

@SidneyLann I haven’t tried yet. I’ve been working on overhauling various aspects of the training and ensuring that’s solid (basically addressing your other concerns first) I wanted to try out various models after getting that done as a litmus test. Luckily I’m on the tail end of that work now and will be able to take a look at this.

---

<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: [November 23, 2021, 2:15am UTC](https://community.konduit.ai/t/npe-when-load-tf-to-samediff/1661/11 "2021-11-23T02:15:00Z")

</div>

@SidneyLann I finally got some time to look in to this. With the latest changes I did here: [https://github.com/eclipse/deeplearning4j/pull/9535](https://github.com/eclipse/deeplearning4j/pull/9535) it appears to import this fine now. If you want the converted model let me know. Thanks for reporting 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: [November 23, 2021, 2:28pm UTC](https://community.konduit.ai/t/npe-when-load-tf-to-samediff/1661/12 "2021-11-23T14:28:05Z")

</div>

@agibsonccc Is the PR available in SNAPSHOT now? still can’t import.

tensorflowFrameworkImporter.runImport(NerUtil.DATA\_HOME + “/bert/bert\_pretrain\_model\_zh.pb”, Collections.emptyMap(), true or false);

not work

---

<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: [November 24, 2021, 12:48am UTC](https://community.konduit.ai/t/npe-when-load-tf-to-samediff/1661/13 "2021-11-24T00:48:49Z")

</div>

@SidneyLann again if you want the model , happy to send it. Otherwise, snapshots runs every 2 days.

---

<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: [November 27, 2021, 3:34am UTC](https://community.konduit.ai/t/npe-when-load-tf-to-samediff/1661/14 "2021-11-27T03:34:35Z")

</div>

Bert model imported successfully now, but it consume 1.5g heap + 7g offheap memory in snapshot but only consume 1g heap + 4g offheap memory in beta7.

---

<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: [December 3, 2021, 10:58am UTC](https://community.konduit.ai/t/npe-when-load-tf-to-samediff/1661/15 "2021-12-03T10:58:48Z")

</div>

@SidneyLann is this at runtime or just passive? Anything to reproduce this would be nice. There have barely been any changes between beta7 and M1.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: [December 3, 2021, 11:40am UTC](https://community.konduit.ai/t/npe-when-load-tf-to-samediff/1661/16 "2021-12-03T11:40:56Z")

</div>

@agibsonccc Just import the bert model I had sent you in beta7 and SNAPSHOT should see the different memory comsume.

---

<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: [December 3, 2021, 11:42am UTC](https://community.konduit.ai/t/npe-when-load-tf-to-samediff/1661/17 "2021-12-03T11:42:35Z")

</div>

@SidneyLann how were you measuring though? Were you using anything like yourkit? Were you using our built in performance listener?

---

<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: [December 3, 2021, 11:45am UTC](https://community.konduit.ai/t/npe-when-load-tf-to-samediff/1661/18 "2021-12-03T11:45:24Z")

</div>

One pc has 6g RAM, it can’t import the model, but another pc has 8g RAM can import successfuly.

successfully by using:  
-Xmx1500m -Dorg.bytedeco.javacpp.maxbytes=6656m -Dorg.bytedeco.javacpp.maxphysicalbytes=7168m

fail in SNAPSHOT but successfully in beta7 by using:  
-Xmx1024m -Dorg.bytedeco.javacpp.maxbytes=4096m -Dorg.bytedeco.javacpp.maxphysicalbytes=4096m

---

<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: [December 3, 2021, 11:50am UTC](https://community.konduit.ai/t/npe-when-load-tf-to-samediff/1661/19 "2021-12-03T11:50:10Z")

</div>

@SidneyLann ok…I can’t really use that. I would need code I can run where I can clearly see profiler output to figure out the source of the problem if there is one or if this is just an opinion.

The goal I have when I ask a question like that is to figure out how to reply to you. If I don’t have clear examples I can run or how you are interpreting what more memory usage is I am not going to chase that down.

My only guess is that it’s the new eager mode that was added. During import we execute graphs 1 op at a time and store the results. This is for use in more complex use cases where we need to know the shape of something during import.

This won’t affect actually saving the model. I would recommend just running the conversion in a standalone process then that won’t be a problem.

---

<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: [December 3, 2021, 11:56am UTC](https://community.konduit.ai/t/npe-when-load-tf-to-samediff/1661/20 "2021-12-03T11:56:51Z")

</div>

The bert model was generated in 2018, I’m not sure if it used eager mode or not.

[Next page](https://community.konduit.ai/t/npe-when-load-tf-to-samediff/1661.md?page=2)
