ml5js / ml5-library

Friendly machine learning for the web! 🤖
https://ml5js.org
Other
6.46k stars 899 forks source link

Possible memory leak in charRNN? #1018

Open hlp-pls opened 4 years ago

hlp-pls commented 4 years ago

Dear ml5 community, I think there maybe a memory leak with charRNN in ml5js. I was making an example that uses stateful prediction with a custom-trained model. I followed the tutorial below provided by paperspace to train the model. https://blog.paperspace.com/training-an-lstm-and-using-the-model-in-ml5-js/ I'm quite new to ml5js, and the problem may exclusively be in my code, but memory leak is happening when text is being generated for some time.

→ Step 1: Describe the issue 📝

I think I found a possible memory leak while using charRNN.

→ Step 2: Screenshots or Relevant Documentation 🖼

I looked at the code that I think the charRNN library is using, and I don't think it is releasing tensors after use. Maybe there is no need to? I'm not sure. Below is the link to the code. https://github.com/ml5js/ml5-library/blob/development/src/CharRNN/index.js

→ Step 3: Share an example of the issue 🦄

The example below is a demonstration of this issue. The example is using stateful prediction. The model is trained with korean text, and therefore needs korean text as input. It takes some time for the browser to crash. example link: https://hlp-pls.github.io/generate-text-file/ code repository link: https://github.com/hlp-pls/generate-text-file

→ Describe your setup 🦄

Here's some helpful information about my setup...

hlp-pls commented 4 years ago
스크린샷 2020-06-29 오후 4 03 16

This is the error message that the console shows!

lindapaiste commented 2 years ago

Great catch! You are right — there are definitely some tensors which are not getting disposed. I’m adding this one to my todo list.