alfabet icon indicating copy to clipboard operation
alfabet copied to clipboard

There may be memory leaks.

Open LuckyLittleMonster opened this issue 2 years ago • 7 comments

I need to invoke model.predict() a lot of times. But it seems that there is a memory leak in predict(). This code gives increasing memory usage.

from alfabet import model

smiles = 'O=C(O)CCC/C=C/CC1C2CCC(O2)C1CCNC(=O)Nc1ccccc1'
while True:
	model.predict([smiles])

alfabet_memory_usage

LuckyLittleMonster avatar Sep 17 '22 21:09 LuckyLittleMonster

Very odd, thanks for the report! I didn't think that was something I needed to worry about in python 😄. Would that trigger an OOM error eventually? I wonder if it's inherited from one of the underlying C libraries. Do you get the same result running

while True:
    rdkit.Chem.MolFromSmiles(smiles)

pstjohn avatar Sep 19 '22 14:09 pstjohn

Yes, my code crashed after 4-5 hours. I also think the memory leak is related to C libraries. I will test your code and check if I got the same result.

LuckyLittleMonster avatar Sep 19 '22 16:09 LuckyLittleMonster

does the memory leak also occur if you don't call model.predict() in a loop? it should be faster anyways to enable some batching over the input molecules. model.predict(my_smiles_list, batch_size=128, verbose=True) for instance, might give better performance, especially on a GPU

pstjohn avatar Sep 19 '22 17:09 pstjohn

while True:
    rdkit.Chem.MolFromSmiles(smiles)

This code don't have memory leak. There is no memory leak if I don't call predict(). Batching should be faster, but we have to calculate the molecules one by one for now.

LuckyLittleMonster avatar Sep 21 '22 01:09 LuckyLittleMonster

@LuckyLittleMonster can you try to disable caching on this line?

https://github.com/NREL/alfabet/blob/master/alfabet/model.py#L68

den-run-ai avatar Sep 21 '22 15:09 den-run-ai

@denfromufa I disabled that line. But the used memory is still increasing. used_memory_no_cache

LuckyLittleMonster avatar Sep 27 '22 14:09 LuckyLittleMonster

Some memory leaks are related to tf.data.Dataset.from_generator(). https://github.com/tensorflow/tensorflow/issues/37653

LuckyLittleMonster avatar Oct 12 '22 16:10 LuckyLittleMonster