You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Memory 'leak' issue with MapTable and clearState #1141
Calling clearState() on MapTable seems to lead to a significant increase in memory usage for future iterations. I was unable to find the source, but the following script demonstrates the bug. (Of course, the exact memory amounts may not match across systems, but the relative amounts should be correct.)
--[[ Displays memory 'leak' with nn.MapTable after clearState() ]]--localnn=require'nn'localcunn=require'cunn'model=nn.MapTable():add(nn.SpatialConvolution(3, 256, 3, 3, 1, 1, 1, 1, 1))
:cuda()
i= {torch.rand(30, 3, 224, 224):cuda(), torch.rand(30, 3, 224, 224):cuda()}
functioncheck_mem() os.execute('nvidia-smi | grep luajit') end-- Train two iterations without clear state:print('Before training 1'); check_mem() -- 277 MiBo=model:forward(i)
print('After forward 1'); check_mem() -- 3254 MiB-- Train another iteration:print('Before training 2'); check_mem() -- 3254 MiBo=model:forward(i)
print('After forward 2'); check_mem() -- 3254 MiB-- Clear state:model:clearState()
collectgarbage()
collectgarbage()
-- Train a final iteration before clearState. This final forward call causes an-- increase in memory usage for the rest of the program!print('Before training 3 (after clearState)'); check_mem() -- 3254 MiBo=model:forward(i)
print('After forward 3 (after clearState)'); check_mem() -- 4724 MiB!-- Garbage collection doesn't fix it.collectgarbage()
collectgarbage()
print('After collectgarbage()'); check_mem() -- 4724 MiB!
Activity
achalddave commentedon Feb 20, 2017
Update: This issue is fixed if the modules in
MapTablehaveclearStatecalled before they are removed fromMapTable, here:nn/MapTable.lua
Line 80 in acc6b8c
Fix memory issue with MapTable module removal
Call clearState when removing modules
Do not call clearState on model while training