Repository navigation
Fix native TensorFlow resource leaks causing non-deterministic SIGABRT in tests (#778) - #903
Open
harshitsingh070 wants to merge 1 commit into
Open
harshitsingh070 wants to merge 1 commit into
harshitsingh070 wants to merge 1 commit into
Conversation
Close the per-batch training tensor in train(), the prediction Result in predict()/close(), and all Results and feed tensors in TensorflowOperatorTest. Previously these leaked and were freed by the GC during JVM shutdown, racing with Session/Graph teardown and aborting the process (exit 134). Fixes apache#778
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
TensorflowModelTestfailed intermittently withProcess Exit Code: 134(SIGABRT) and"The forked VM terminated without properly saying goodbye" during JVM shutdown.
The previous fix (#781) only cleaned up resources inside the test itself and did not
address the actual leaks.
Root cause
TensorFlow Java native tensors are released by JavaCPP deallocators when not closed
explicitly. Leaked tensors were therefore freed by the GC at arbitrary times, including
during JVM shutdown, racing with
Session/Graphteardown and aborting the process.The real leaks were:
TensorflowModel.train()createdTBool.scalarOf(true)on every batch and never closed it.TensorflowModel.predict()never closed theResultreturned bysession.runner().run().TensorflowOperatorTestleaked aResultand feed tensors in almost every test.Because Surefire runs all test classes in one forked JVM, these leaks accumulated and the
crash was often attributed to whichever test class ran last (
TensorflowModelTest).Fix
train()via try-with-resources.Resultfrompredict()inTensorflowModel.close().Result, feed tensor, andTBool/TFloat32inTensorflowOperatorTestwith try-with-resources.
All native resources are now released deterministically before the session/graph are
closed, so no deferred cleanup is left at JVM shutdown.
Testing
mvn -pl wayang-platforms/wayang-tensorflow testpasses repeatedly (13 tests, multiple runs).is removed.
Fixes #778