Skip to content

Commit 11d332c

Browse files
Update simple_cerebros_random_search.py
Add an option to purge model storage after a trial to keep memory from accumulating in a containerized run.
1 parent 488705e commit 11d332c

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

cerebros/simplecerebrosrandomsearch/simple_cerebros_random_search.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from multiprocessing import Process, Lock
1515
import os
1616
from gc import collect
17+
from shutil import rmtree
1718

1819

1920
# import optuna
@@ -585,8 +586,14 @@ def run_random_search(self):
585586
print(f"Best model name: {self.best_model_path}")
586587
return best
587588

588-
def get_best_model(self):
589+
def purge_model_storage(self):
590+
path_0 = f"{self.project_name}/models"
591+
rmtree(path_0)
592+
593+
def get_best_model(self, purge_model_storage_files=False):
589594
best_model = tf.keras.models.load_model(self.best_model_path)
595+
if purge_model_storage:
596+
self.purge_model_storage()
590597
return best_model
591598

592599
# ->

0 commit comments

Comments
 (0)