Allocation of 360434219 exceeds 10% of free system memory.
还没有人认领这个 Issue。
- 主要语言
- Java
- 星标
- 928
- 派生
- 227
- PR 合并指标
- 30 天内没有已合并 PR
描述
Please make sure that this is a bug. As per our GitHub Policy, we only address code/doc bugs, performance issues, feature requests and build/installation issues on GitHub. tag:bug_template
System information
- Have I written custom code (as opposed to using a stock example script provided in TensorFlow):
- OS Platform and Distribution (e.g., Linux Ubuntu 16.04 x86_64): Linux x86_64 in a Docker cointainer
- TensorFlow installed from (source or binary):
- TensorFlow version (use command below): 1.0.0-RC.2
- Java version (i.e., the output of
java -version): openjdk version "21.0.4" - Java command line flags (e.g., GC parameters):
- Python version (if transferring a model trained in Python): 3.9
- Bazel version (if compiling from source):
- GCC/Compiler version (if compiling from source):
- CUDA/cuDNN version:
- GPU model and memory:
Describe the current behavior
I am using TensorFlow in a Spring Boot application, which exposes an endpoint for NER processing. The TensorFlow model is trained in Python and loaded into the Java application for inference.
To optimize performance, I initialize the TensorFlow session once during application startup using a @PostConstruct method and store it in a private field:
private Session session;
@PostConstruct
private void initialize() throws IOException {
byte[] bytes = Files.readAllBytes(Paths.get("/path/to/model/"));
Graph graph = new Graph();
graph.importGraphDef(GraphDef.parseFrom(bytes), "PREFIX");
session = new Session(graph);
}
The session is reused in a public method for running predictions:
public Result predict(String input) {
try (Tensor textTensor = Tensor.of(TINT32.class, ...);
Result result = session.runner()
.feed("otherOperationName", textTensor)
.fetch("operationName")
.run()) {
// Process the result here
}
}
During performance testing, I monitored the heap memory and found no significant issues. However, when the application runs in a Docker container, it crashes after a while, regardless of the memory allocated to the container (even with 120GB of memory). The following warning appears in the logs before the crash:
W external/local_tsl//framework/cpu_allocator_impl.cc:83] Allocation of 34891293 exceeds 10% of free system memory.
Is it possible that the memory leak is caused by the session being stored in a private field and never explicitly closed, even though all tensors and intermediate results are properly managed (closed) in the predict method?
Describe the expected behavior
The application should not exhibit memory leaks or crashes when deployed in a Docker container, regardless of memory allocation.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 @PostConstruct 中的 Java 初始化路径和 predict 方法开始,然后检查 Session 和 Graph 资源如何与张量及结果一起进行管理。如果可能,请使用报告中的 TensorFlow、Java 和 Python 版本重现 Docker 内存警告;完成的标准是确定 Session 生命周期是否导致崩溃,或记录缺失的复现细节和正确的资源管理方式。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- java, tensorflow
- 领域
- backend, machine-learning
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 需要澄清
- 新手友好度
- 30/100