Skip to content

Commit

Permalink
ENAS enable to add None values in algorithm settings (#1153)
Browse files Browse the repository at this point in the history
* ENAS enable to add None values as algorithm settings

* Delete TODO
  • Loading branch information
andreyvelich authored Apr 17, 2020
1 parent dfa4361 commit 7022d3d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
10 changes: 7 additions & 3 deletions pkg/suggestion/v1alpha3/nas/enas/AlgorithmSettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
"controller_train_steps": [int, [1, 'inf']],
"controller_log_every_steps": [int, [1, 'inf']],
}
enableNoneSettingsList = [
"controller_temperature", "controller_tanh_const", "controller_entropy_weight", "controller_skip_weight"]


# TODO: Enable to add None values, e.g in controller_temperature parameter
def parseAlgorithmSettings(settings_raw):

algorithm_settings_default = {
Expand All @@ -32,7 +33,10 @@ def parseAlgorithmSettings(settings_raw):
for setting in settings_raw:
s_name = setting.name
s_value = setting.value
s_type = algorithmSettingsValidator[s_name][0]
algorithm_settings_default[s_name] = s_type(s_value)
if s_value == "None":
algorithm_settings_default[s_name] = None
else:
s_type = algorithmSettingsValidator[s_name][0]
algorithm_settings_default[s_name] = s_type(s_value)

return algorithm_settings_default
2 changes: 1 addition & 1 deletion pkg/suggestion/v1alpha3/nas/enas/Controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def build_trainer(self):
normalize = tf.dtypes.cast((self.num_layers * (self.num_layers - 1) / 2), tf.float32)
self.skip_rate = tf.dtypes.cast((self.skip_count / normalize), tf.float32)

if self.controller_entropy_weight:
if self.controller_entropy_weight is not None:
self.reward += self.controller_entropy_weight * self.sample_entropy

self.sample_log_probs = tf.reduce_sum(self.sample_log_probs)
Expand Down
11 changes: 8 additions & 3 deletions pkg/suggestion/v1alpha3/nas/enas_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
from pkg.apis.manager.v1alpha3.python import api_pb2_grpc
from pkg.suggestion.v1alpha3.nas.enas.Controller import Controller
from pkg.suggestion.v1alpha3.nas.enas.Operation import SearchSpace
from pkg.suggestion.v1alpha3.nas.enas.AlgorithmSettings import parseAlgorithmSettings, algorithmSettingsValidator
from pkg.suggestion.v1alpha3.nas.enas.AlgorithmSettings import (
parseAlgorithmSettings, algorithmSettingsValidator, enableNoneSettingsList)
from pkg.suggestion.v1alpha3.base_health_service import HealthServicer


Expand Down Expand Up @@ -122,8 +123,6 @@ def print_algorithm_settings(self):
spec, self.algorithm_settings[spec]))

self.logger.info("")
self.logger.info("RequestNumber:\t\t\t{}".format(self.num_trials))
self.logger.info("")


class EnasService(api_pb2_grpc.SuggestionServicer, HealthServicer):
Expand Down Expand Up @@ -205,6 +204,8 @@ def ValidateAlgorithmSettings(self, request, context):
settings_raw = request.experiment.spec.algorithm.algorithm_setting
for setting in settings_raw:
if setting.name in algorithmSettingsValidator.keys():
if setting.name in enableNoneSettingsList and setting.value == "None":
continue
setting_type = algorithmSettingsValidator[setting.name][0]
setting_range = algorithmSettingsValidator[setting.name][1]
try:
Expand Down Expand Up @@ -243,6 +244,10 @@ def GetSuggestions(self, request, context):
self.logger.info("-" * 100 + "\nSuggestion Step {} for Experiment {}\n".format(
experiment.suggestion_step, experiment.experiment_name) + "-" * 100)

self.logger.info("")
self.logger.info(">>> RequestNumber:\t\t{}".format(experiment.num_trials))
self.logger.info("")

with experiment.tf_graph.as_default():
saver = tf.compat.v1.train.Saver()
ctrl = experiment.controller
Expand Down

0 comments on commit 7022d3d

Please sign in to comment.