Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

FeedForward.scala and NDArrayIter.scala leak memory by not disposing of NDArrays #10436

Closed
milandesai opened this issue Apr 6, 2018 · 7 comments

Comments

@milandesai
Copy link
Contributor

Description

FeedForward.scala and NDArrayIter.scala leak memory by not disposing of NDArrays. We see the below leak warnings occur running on MXNet 1.1.0. Additionally, there is no clean way of disposing a FeedForward and its contents.

Version

MXNet 1.1.0

Error Message:

[2018-04-06 01:12:13,895] WARN  - Finalizer - WarnIfNotDisposed - LEAK: An instance of class ml.dmlc.mxnet.NDArray was not disposed. Creation point of this resource was:
	java.lang.Thread.getStackTrace(Thread.java:1552)
	ml.dmlc.mxnet.WarnIfNotDisposed.$init$(WarnIfNotDisposed.scala:52)
	ml.dmlc.mxnet.NDArray.<init>(NDArray.scala:549)
	ml.dmlc.mxnet.NDArray.slice(NDArray.scala:632)
	ml.dmlc.mxnet.FeedForward.$anonfun$predict$5(FeedForward.scala:233)
	scala.collection.TraversableLike$WithFilter.$anonfun$foreach$1(TraversableLike.scala:789)
	scala.collection.IndexedSeqOptimized.foreach(IndexedSeqOptimized.scala:32)
	scala.collection.IndexedSeqOptimized.foreach$(IndexedSeqOptimized.scala:29)
	scala.collection.mutable.ArrayOps$ofRef.foreach(ArrayOps.scala:191)
	scala.collection.TraversableLike$WithFilter.foreach(TraversableLike.scala:788)
	ml.dmlc.mxnet.FeedForward.predict(FeedForward.scala:232)

[2018-04-06 01:12:13,895] WARN  - Finalizer - WarnIfNotDisposed - LEAK: An instance of class ml.dmlc.mxnet.NDArray was not disposed. Creation point of this resource was:
	java.lang.Thread.getStackTrace(Thread.java:1552)
	ml.dmlc.mxnet.WarnIfNotDisposed.$init$(WarnIfNotDisposed.scala:52)
	ml.dmlc.mxnet.NDArray.<init>(NDArray.scala:549)
	ml.dmlc.mxnet.NDArray.slice(NDArray.scala:632)
	ml.dmlc.mxnet.io.NDArrayIter.$anonfun$_getData$2(NDArrayIter.scala:163)
	scala.collection.TraversableLike.$anonfun$map$1(TraversableLike.scala:234)
	scala.collection.Iterator.foreach(Iterator.scala:929)
	scala.collection.Iterator.foreach$(Iterator.scala:929)
	scala.collection.AbstractIterator.foreach(Iterator.scala:1417)
	scala.collection.IterableLike.foreach(IterableLike.scala:71)
	scala.collection.IterableLike.foreach$(IterableLike.scala:70)
	scala.collection.AbstractIterable.foreach(Iterable.scala:54)
	scala.collection.TraversableLike.map(TraversableLike.scala:234)
	scala.collection.TraversableLike.map$(TraversableLike.scala:227)
	scala.collection.AbstractTraversable.map(Traversable.scala:104)
	ml.dmlc.mxnet.io.NDArrayIter._getData(NDArrayIter.scala:163)
	ml.dmlc.mxnet.io.NDArrayIter.getData(NDArrayIter.scala:176)
	ml.dmlc.mxnet.io.NDArrayIter.next(NDArrayIter.scala:134)
	ml.dmlc.mxnet.FeedForward.predict(FeedForward.scala:226)

The culprit appears to be FeedForward.scala:233 and NDArrayIter:163. Additionally, it would be nice to to provide a method that disposes of a FeedForward; i.e. it disposes the symbol, executor, and aux/arg params.

@wellner
Copy link

wellner commented May 21, 2018

Any chance of having this issue bumped up? This bug renders training via Scala impossible in many cases and could be problematic for large batch decoding/inference.

@lanking520
Copy link
Member

Thanks for your message! We are currently working on a draft proposal to solve this issue and send to the devlist. The disposing method currently brings a great inconvenience to users. In the past, we tried to place that into finalizer stage and it sometimes crash for unknown reasons. Will follow up with this thread with our progress.

@wellner
Copy link

wellner commented May 23, 2018

Great! Looking forward to it and happy to help test and/or review.

andrewfayres pushed a commit to andrewfayres/incubator-mxnet that referenced this issue Jun 7, 2018
andrewfayres pushed a commit to andrewfayres/incubator-mxnet that referenced this issue Jun 9, 2018
nswamy pushed a commit that referenced this issue Jun 14, 2018
anirudh2290 pushed a commit that referenced this issue Jun 14, 2018
* Fixes Scala memory leak (#10436)

* Replaced the copy and disposed of sliced ndArray to resolve memory leak

* Wrapped disposes in a finally to ensure they are called.
marcoabreu pushed a commit to marcoabreu/incubator-mxnet that referenced this issue Jun 14, 2018
* Fixes Scala memory leak (apache#10436)

* Replaced the copy and disposed of sliced ndArray to resolve memory leak

* Wrapped disposes in a finally to ensure they are called.
marcoabreu pushed a commit that referenced this issue Jun 14, 2018
* Fixes Scala memory leak (#10436)

* Replaced the copy and disposed of sliced ndArray to resolve memory leak

* Wrapped disposes in a finally to ensure they are called.
anirudh2290 pushed a commit to anirudh2290/mxnet that referenced this issue Jun 15, 2018
* Fixes Scala memory leak (apache#10436)

* Replaced the copy and disposed of sliced ndArray to resolve memory leak

* Wrapped disposes in a finally to ensure they are called.
zheng-da pushed a commit to zheng-da/incubator-mxnet that referenced this issue Jun 28, 2018
@andrewfayres
Copy link
Contributor

Memory leak was a result of the FeedForward predict method not properly disposing of two NDArrays. This was fixed in the PR above. Issue can be closed. @nswamy

@lanking520
Copy link
Member

@wellner Currently @yzhliu brings a solution on Memory leaks here: #11751. Please take a look in here.

XinYao1994 pushed a commit to XinYao1994/incubator-mxnet that referenced this issue Aug 29, 2018
@vandanavk
Copy link
Contributor

Can this issue be closed? @milandesai @wellner

@vandanavk
Copy link
Contributor

@sandeep-krishnamurthy Please close this issue as PRs with fixes have been submitted.

@milandesai @wellner Please feel free to reopen the issue if you see it again.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants