-
Notifications
You must be signed in to change notification settings - Fork 702
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Builders leak ParameterCollectionStorage memory upon construction #1632
Comments
Ping, just to see if anyone is watching/listening. @MihaiSurdeanu, this is the PR I mentioned this morning. I was hoping to find out the repercussions before resyncing the forks, but it's not a requirement. For clulab deployment I have only considered the builders that we are using, while for clab probably all should be checked, so it's not (yet) just a merge of our changes. I'm also not sure whether clab will want to stick with a plain pointer or change to a smart pointer, etc. |
Hi, thanks for checking this! I think that we considered this several years ago and ended up not fixing it for some reason, but honestly I don't remember why. I don't have time to go digging through the archives at the moment, but if the change passes all tests then I'll try to review it and accept the PR |
Do you mean any particular "the change"? Is it the one from several years ago? |
@kwalcock: my coreference resolution algorithm says that "the change" refers to this PR, no? |
This is just an issue filed. I don't have a PR that isolates this change or code that applies to every type of builder. It could be done, of course. I wouldn't trust it completely just because the unit tests pass. It would need close review. |
In part due to the use of a pointer in
ParameterCollection
forParameterCollectionStorage
and the lack of assignment operator or copy constructor forParameterCollection
,RnnBuilders
like aVanillaLSTMBuilder
will leak memory during their construction. In particular at a line likedynet/dynet/lstm.cc
Line 325 in 93a5cd2
This can be demonstrated with a short program like this one extracted from train_rnn-autobatch.cc:
If some debugging output is added like these lines in
model.cc
,and a note added to
lstm.cc
inVanillaLSTMBuilder::VanillaLSTMBuilder
one can get output like this:
The temporary ParameterCollection displayed in the
fwR
line and stored inlocal_model
will leak whenlocal_model
is overwritten with the value frommodel.add_subcollection("vanilla-lstm-builder");
.Probably the ParameterCollection should be made to assign and copy correctly. In this particular case, one can skip that and initialize
local_model
from the beginning by changing the constructor ofVanillaLSTMBuilder
toThis results in the output
This will still result in a leak because of the condition on the destructor of the
ParameterCollection
:This
parent
doesn't seem to have much to do with anything here. Perhaps it was meant to work around other problems. Removing the conditionparent == nullptr
will prevent the leak in this case. I was a little more cautious and changedstorage
to be a shared pointer, instead. It probably helps in cases whenParameterCollections
are copied.This problem probably exists with all or most builders, but I haven't studied whether similar modification will be effective for all the others. Thanks for looking into this.
The text was updated successfully, but these errors were encountered: