Skip to content

Commit 2764ba5

Browse files
Update ames-wo-val-hyperparam-optimization-local.py
The last run successfully ran 1 trial qucikly, then spent hours running the next trial that should have taken about 3 minutes. The only reason I can think of as to why this would be is if there were a memory leak. 1. Added garbage collection. 2. Replaced deprecated suggest_log_uniform with suggest_float(... log=True) ...
1 parent da4d9da commit 2764ba5

File tree

1 file changed

+32
-12
lines changed

1 file changed

+32
-12
lines changed

ames-wo-val-hyperparam-optimization-local.py

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,12 @@
99
import pendulum
1010
import pandas as pd
1111
import tensorflow as tf
12-
from cerebros.simplecerebrosrandomsearch.simple_cerebros_random_search\
13-
import SimpleCerebrosRandomSearch
14-
from cerebros.units.units import DenseUnit
15-
from cerebros.denseautomlstructuralcomponent.dense_automl_structural_component\
16-
import zero_7_exp_decay, zero_95_exp_decay, simple_sigmoid
12+
1713
from ast import literal_eval
1814

15+
from copy import copy
16+
from gc import collect
17+
1918
# Define constants
2019
LABEL_COLUMN = 'price'
2120
NUMBER_OF_TRAILS_PER_BATCH = 2
@@ -43,20 +42,25 @@
4342
OUTPUT_SHAPES = [1]
4443

4544
def objective(trial):
45+
from cerebros.simplecerebrosrandomsearch.simple_cerebros_random_search\
46+
import SimpleCerebrosRandomSearch
47+
from cerebros.units.units import DenseUnit
48+
from cerebros.denseautomlstructuralcomponent.dense_automl_structural_component\
49+
import zero_7_exp_decay, zero_95_exp_decay, simple_sigmoid
4650
# Define hyperparameter space
47-
minimum_levels = trial.suggest_int('minimum_levels', 1, 5)
48-
maximum_levels = trial.suggest_int('maximum_levels', minimum_levels, 5)
51+
minimum_levels = trial.suggest_int('minimum_levels', 1, 4)
52+
maximum_levels = trial.suggest_int('maximum_levels', minimum_levels, 4)
4953
minimum_units_per_level = trial.suggest_int('minimum_units_per_level', 1, 5)
5054
maximum_units_per_level = trial.suggest_int('maximum_units_per_level', minimum_units_per_level, 5)
5155
minimum_neurons_per_unit = trial.suggest_int('minimum_neurons_per_unit', 1, 5)
5256
maximum_neurons_per_unit = trial.suggest_int('maximum_neurons_per_unit', minimum_neurons_per_unit, 5)
5357
activation = trial.suggest_categorical('activation', ['relu', 'elu', 'gelu', 'swish', 'softplus'])
54-
predecessor_level_connection_affinity_factor_first = trial.suggest_loguniform('predecessor_level_connection_affinity_factor_first', 0.1, 40.0)
55-
predecessor_level_connection_affinity_factor_main = trial.suggest_loguniform('predecessor_level_connection_affinity_factor_main', 0.1, 40.0)
58+
predecessor_level_connection_affinity_factor_first = trial.suggest_float('predecessor_level_connection_affinity_factor_first', 0.1, 40.0, log=True)
59+
predecessor_level_connection_affinity_factor_main = trial.suggest_float('predecessor_level_connection_affinity_factor_main', 0.1, 40.0, log=True)
5660
max_consecutive_lateral_connections = trial.suggest_int('max_consecutive_lateral_connections', 1, 35)
57-
p_lateral_connection = trial.suggest_loguniform('p_lateral_connection', 0.1, 35)
61+
p_lateral_connection = trial.trial.suggest_float('p_lateral_connection', 0.1, 35, log=True)
5862
num_lateral_connection_tries_per_unit = trial.suggest_int('num_lateral_connection_tries_per_unit', 1, 35)
59-
learning_rate = trial.suggest_loguniform('learning_rate', 10**-6, 0.6)
63+
learning_rate = trial.trial.suggest_float('learning_rate', 10**-6, 0.6, log=True)
6064
epochs = trial.suggest_int('epochs', 1, 150)
6165
batch_size = trial.suggest_int('batch_size', 1, 800)
6266

@@ -113,7 +117,23 @@ def objective(trial):
113117
meta_trial_number=meta_trial_number)
114118

115119
result = cerebros.run_random_search()
116-
return result
120+
121+
# Make a copy of the result so it isn't lost in garbage collection.
122+
123+
result_0 = copy(result)
124+
125+
# Garbage collection to create a clen state for
126+
# the next run and to prevent memory leakage
127+
del(result)
128+
del(cerebros)
129+
del(SimpleCerebrosRandomSearch)
130+
del(DenseUnit)
131+
del(zero_7_exp_decay)
132+
del(zero_95_exp_decay)
133+
del(simple_sigmoid)
134+
collect()
135+
136+
return result_0
117137

118138
def main():
119139
study = optuna.create_study(direction='minimize')

0 commit comments

Comments
 (0)