clab / clab/dynet

Memory leak in Model

Open
#418 6 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
C++
Stars
3.4k
Forks
701
PR merge metrics
No merged PRs in 30d

Description

When running this code :

import _dynet as dy

dp=dy.DynetParams()
dp.from_args()
dp.set_mem(512)
dp.init()

def create_model():
m=dy.Model()
w=m.add_parameters((1000,1000))
del m

for i in range(100):
print '=== Iteration %d ===' % i
try:
create_model()
except e:
exit()
print '===================='

With an old version (without dynamic memory pool), I get the following error

[dynet] random seed: 2856107851
[dynet] allocating memory: 512MB
[dynet] memory allocation done.
=== Iteration 0 ===
====================
=== Iteration 1 ===
====================
=== Iteration 2 ===
====================
=== Iteration 3 ===
====================
=== Iteration 4 ===
====================
=== Iteration 5 ===
====================
=== Iteration 6 ===
====================
=== Iteration 7 ===
====================
=== Iteration 8 ===
====================
=== Iteration 9 ===
====================
=== Iteration 10 ===
====================
=== Iteration 11 ===
====================
=== Iteration 12 ===
====================
=== Iteration 13 ===
====================
=== Iteration 14 ===
====================
=== Iteration 15 ===
====================
=== Iteration 16 ===
====================
=== Iteration 17 ===
====================
=== Iteration 18 ===
====================
=== Iteration 19 ===
====================
=== Iteration 20 ===
====================
=== Iteration 21 ===
====================
=== Iteration 22 ===
terminate called after throwing an instance of 'std::runtime_error'
what(): CPU parameter memory is out of memory, try increasing with --dynet-mem (current capacity: 178257920). See http://dynet.readthedocs.io/en/latest/commandline.html for details.
[1] 3281 abort (core dumped) python test_mem.py

There are two big problems here :

- There is a memory leak
- With the new dynamic memory pool this is much worse since there is no way to limit the memory used by dynet

Is there a way to limit the memory (ideally an option like `--dynet-mem [initial mem]-[maximum-mem]`) ?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.