Skip to content

Commit c8b08da

Browse files
Update simple_cerebros_random_search.py
Garbage collecting to cure RAM pressure accumulation: Added garbage collection and ensure a clean keras back-end state before starting a new model.
1 parent 6cea4e8 commit c8b08da

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

cerebros/simplecerebrosrandomsearch/simple_cerebros_random_search.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
# from cmdutil.cmdutil import run_command
1414
from multiprocessing import Process, Lock
1515
import os
16+
from gc import collect
17+
1618

1719
# import optuna
1820
# from optuna.pruners import BasePruner
@@ -480,6 +482,8 @@ def run_moity_permutations(self, spec, subtrial_number, lock):
480482
model_graph_file=model_graph_file,
481483
train_data_dtype=self.train_data_dtype
482484
)
485+
tf.keras.backend.clear_session()
486+
collect()
483487
nnf.materialize()
484488
nnf.compile_neural_network()
485489
neural_network = nnf.materialized_neural_network
@@ -515,7 +519,11 @@ def run_moity_permutations(self, spec, subtrial_number, lock):
515519
index=False,
516520
header=self.needs_oracle_header,
517521
mode='a')
522+
518523
self.needs_oracle_header = False
524+
neural_network = None
525+
tf.keras.backend.clear_session()
526+
collect()
519527
return 0
520528

521529
def run_random_search(self):

0 commit comments

Comments
 (0)