SavedModelBundle memory leak
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 28/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- java, tensorflow
- Domain
- machine-learning
Research direction
Start with the reproduction in App.main, focusing on the repeated SavedModelBundle.load(modelPath, "serve") and model.close() calls, and use the saved_model resource named in the issue. Confirm that memory continues growing across iterations and that the loading and closing path can complete repeatedly without an OutOfMemoryError.
Written by the indexing model from the issue text.
Description
System information
- Have I written custom code (as opposed to using a stock example script provided in TensorFlow): Yes
- OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Linux Ubuntu 18.04.5 LTS
- TensorFlow installed from (source or binary): Included in java artifact
- TensorFlow version: 2.4.1
Describe the current behavior
Loading and closing SavedModelBundle in an infinite loop leads to OutOfMemoryError:
Exception in thread "main" java.lang.OutOfMemoryError: Physical memory usage is too high: physicalBytes (7828M) > maxPhysicalBytes (7828M)
at org.bytedeco.javacpp.Pointer.deallocator(Pointer.java:695)
at org.tensorflow.internal.c_api.AbstractTF_Status.newStatus(AbstractTF_Status.java:70)
at org.tensorflow.SavedModelBundle.load(SavedModelBundle.java:401)
at org.tensorflow.SavedModelBundle.access$000(SavedModelBundle.java:59)
at org.tensorflow.SavedModelBundle$Loader.load(SavedModelBundle.java:68)
at org.tensorflow.SavedModelBundle.load(SavedModelBundle.java:242)
at com.mycompany.app.App.main(App.java:13)
I use 0.3.1 version of the library. It is the only dependency:
<dependency>
<groupId>org.tensorflow</groupId>
<artifactId>tensorflow-core-platform</artifactId>
<version>0.3.1</version>
</dependency>
The memory leak is reproducible with a model from this repository:
https://github.com/tensorflow/java/tree/master/tensorflow-core/tensorflow-core-api/src/test/resources/saved_model
Describe the expected behavior
I assume that the following code should run endlessly
Code to reproduce the issue
package com.mycompany.app;
import org.tensorflow.SavedModelBundle;
import java.net.URISyntaxException;
import java.nio.file.Paths;
public class App {
public static void main(String[] args) throws URISyntaxException {
var modelPath = Paths.get(App.class.getResource("/saved_model").toURI()).toString();
while (true) {
var model = SavedModelBundle.load(modelPath, "serve");
model.close();
}
}
}
- Dominant language
- Java
- Stars
- 928
- Forks
- 227
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from tensorflow/java
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
tensorflow/java#653 · 1 comment · 4 reactions ·
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
tensorflow/java#621 · 4 comments ·
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
tensorflow/java#617 · 3 comments ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 55/100
tensorflow/java#615 · 1 comment ·
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
tensorflow/java#614 · 1 comment ·
Similar issues
-
bug
Difficulty 1/5 Under an hour Newbie friendliness 90/100
apache/cloudstack#14222 ·
-
[BUG]茶杯方块在取茶时会引发崩溃 Open
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
1.0.0-alpha2 Type/Improvement
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
wso2/dpdp-accelerator#272 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
apache/rocketmq-dashboard#4860 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
infinispan/infinispan#18150 ·