2

I'm using Google Colab to train my model. After training, I want to change the model but I can't because there is not enough RAM for it. I tried to re-assign old model to None but RAM used didn't decrease.

enter image description here

I don't want to close the session and start from the beginning. Is there any way to free up RAM used in google colab?

desertnaut
  • 57,590
  • 26
  • 140
  • 166
Ha Bom
  • 2,787
  • 3
  • 15
  • 29
  • 1
    You can try to use `import gc` and then `gc.collect()` after cells, where you doing expensive computations such as train a model or do feature engineering. I`m hope, it helps to free some RAM from your colab – Dmitriy Kisil Feb 26 '19 at 08:28
  • Try to delete the intermediatory data created during feature engineering and cleaning. – Sleeba Paul Feb 26 '19 at 10:08

4 Answers4

3

I had this problem. I was looping through different models I was building and it helped me to clear the session from memory after each run, as per this other Stackoverflow contribution:

from tensorflow.keras import backend as K
K.clear_session()

For some other users this also helped:

tf.reset_default_graph()

It might also be, without you noticing, that your RAM gets exhausted because you are loading your data from a pandas dataframe. In such a case this might help you, too, more precisely adding the following lines under each loop cleared the memory in my case:

import gc
import pandas as pd

del(df)
gc.collect()
df=pd.DataFrame()
NeStack
  • 1,739
  • 1
  • 20
  • 40
1

Colab does not provide this feature to increase RAM now.

workaround that you can opt is to del all variables as soon as these are used. Secondly, try to dump your intermediate variable results using pickle or joblib libraries. so if the RAM crashes so you don't have to start all over again.

example:

from sklearn.externals import joblib
from google.colab import files

#you can save variable into file on colab files

joblib.dump(var,  'var.pkl')   
 
#this will download file to your local downloads

files.download('var.pkl')       

#reload your saved data.

var = joblib.load('var.pkl')    
ashraful16
  • 2,742
  • 3
  • 11
  • 32
Hira Ejaz
  • 11
  • 1
0

Colab dosen't support this feature. The only option is to start all over again.

-1

For a work around to increase your RAM to 25 gigs you can run below code and wait for the notebook to popup the RAM increasing option. There you go, you increased RAM to 25GB.

d =[]
while(1):
  d.append('1')
jboockmann
  • 1,011
  • 2
  • 11
  • 27