You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2019/03/07 19:06:01 UTC

[GitHub] [incubator-mxnet] yuxihu edited a comment on issue #13951: Gluon RNN memory leaks with extra variables

yuxihu edited a comment on issue #13951: Gluon RNN memory leaks with extra variables
URL: https://github.com/apache/incubator-mxnet/issues/13951#issuecomment-470653186
 
 
   The memory leak is related to the extra unused variable you passed into your RNN model but it is NOT specific to RNN. In your repro script, you created a size-zero ndarray in each loop which caused the memory leak.
   ```
   for epoch in range(args.epochs):
       ...
       for i, (data, target) in enumerate(train_data):
           ...
           with autograd.record():
               ....
               output, hidden = model(data, hidden, mx.nd.array([], ctx=context))
   ```
   However, since the size-zero ndarray is unused anywhere, it is a better code practice to create once outside the loop and use it throughout your training. The same change applies to the eval() function in your repro script.
   ```
   extra = mx.nd.array([], ctx=context)
   for epoch in range(args.epochs):
       ...
       for i, (data, target) in enumerate(train_data):
           ...
           with autograd.record():
               ....
               output, hidden = model(data, hidden, extra)
   ```
   With this change, I ran your repro script for 10 epochs with mxnet_cu90mkl 1.3.1 and 1.4.0 packages and did not see memory leak.
   
   But there is indeed a memory leak issue which is the root cause for this issue. Please refer to #14358 for more details.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services