def parse_1_set_of_kwargs(env_instance, kwargs_to_parse, method_name, repeated_key, only_repeated, old_arguments=None): # print('\n\n_parse_1_set_of_kwargs method:\nkwargs_to_parse:\n', kwargs_to_parse, '\nmethod_name:\n', # method_name, '\nrepeated_key:\n', repeated_key, '\nonly_repeated:\n', only_repeated, '\nold_arguments:\n', # old_arguments) kwargs_to_parse = construct(kwargs_to_parse) process_abbreviations(env_instance, kwargs_to_parse, method_name) if old_arguments is None: if only_repeated: tmp = env_instance.get_default_method_parameters(method_name) current_arguments = tmp[repeated_key] else: current_arguments = env_instance.get_default_method_parameters( method_name) else: current_arguments = construct(old_arguments) for key, value in kwargs_to_parse.items(): paste_into_nested_structure(current_arguments, key, value) #print('current_arguments:\n', current_arguments) return current_arguments
def create_one_combination_insertions(insert_template, hp_combination): # print('\ncreate_one_combination_insertions') combination_insertions = construct(insert_template) for hp_name, value in hp_combination.items(): # print('hp_name:', hp_name) # print('value:', value) insert_key = (hp_name[0], hp_name[1], hp_name[2]) single_tmpl = combination_insertions[insert_key] # print('single_tmpl:', single_tmpl) # print('hp_name[0]:', hp_name[0]) # print('hp_name[3]:', hp_name[3]) if hp_name[0] == 'additional_placeholder': if hp_name[3] is not None: single_tmpl['paste']['value'][hp_name[3]] = value else: single_tmpl['paste']['value'] = value else: if hp_name[3] is not None: single_tmpl['paste'][hp_name[3]] = value else: single_tmpl['paste'] = value if single_tmpl['share'] is not None: share = single_tmpl['share'] if share['hp_type'] == 'additional_placeholder': share['paste']['value']['value'] = value else: share['paste']['value'] = value # print('\n') return combination_insertions
def process_other_hp_specs_absences(other_hps): other_hps = construct(other_hps) new_other_hps = dict() for hp_name, hp_values_and_specs in other_hps.items(): if isinstance(hp_values_and_specs, list): new_other_hps.update( process_other_hp_dictionary_absence(hp_name, hp_values_and_specs)) else: if 'list_indices' not in hp_values_and_specs: hp_values_and_specs['list_indices'] = None elif isinstance(hp_values_and_specs['list_indices'], int): hp_values_and_specs['list_indices'] = [ hp_values_and_specs['list_indices'] ] if 'hp_type' not in hp_values_and_specs: hp_values_and_specs['hp_type'] = 'additional_placeholder' if 'controller' not in hp_values_and_specs: hp_values_and_specs['controller'] = True if 'type' not in hp_values_and_specs: if hp_values_and_specs['controller']: hp_values_and_specs['type'] = 'fixed' else: hp_values_and_specs['type'] = None if 'fixed' not in hp_values_and_specs: if hp_values_and_specs['controller']: hp_values_and_specs['fixed'] = dict() else: hp_values_and_specs['fixed'] = None hp_values_and_specs['share'] = None new_other_hps[hp_name] = hp_values_and_specs return new_other_hps
def process_build_hp_abbreviations(build_hps): build_hps = construct(build_hps) new_build_hps = dict() for hp_name, hp_values_and_specs in build_hps.items(): if isinstance(hp_values_and_specs, list): new_build_hps.update( process_build_hp_text_abbreviation(hp_name, hp_values_and_specs)) else: if 'hp_type' not in hp_values_and_specs: hp_values_and_specs['hp_type'] = 'build_hp' if 'list_indices' not in hp_values_and_specs: hp_values_and_specs['list_indices'] = None elif isinstance(hp_values_and_specs['list_indices'], int): hp_values_and_specs['list_indices'] = [ hp_values_and_specs['list_indices'] ] if 'share' not in hp_values_and_specs: hp_values_and_specs['share'] = None hp_values_and_specs['controller'] = False hp_values_and_specs['type'] = None hp_values_and_specs['fixed'] = None if hp_values_and_specs['share'] is not None: if 'direction' not in hp_values_and_specs['share']: default = spot_direction(hp_name) if spot_direction(hp_name) is None: hp_values_and_specs['share'][ 'direction'] = 'batch_kwarg' else: hp_values_and_specs['share']['direction'] = default if 'controller' not in hp_values_and_specs['share']: hp_values_and_specs['share']['controller'] = True new_build_hps[hp_name] = hp_values_and_specs new_build_hps = reshape_1_index_hps(new_build_hps) return new_build_hps
def expand_varying_entry(hps): hps = construct(hps) new_hps = dict() for hp_name, hp_values_and_specs in hps.items(): if hp_values_and_specs['controller'] and isinstance( hp_values_and_specs['varying'], list): hp_values_and_specs['varying'] = { 'value': hp_values_and_specs['varying'] } new_hps[hp_name] = hp_values_and_specs return new_hps
def form_list_of_kwargs(kwargs_for_building, build_hyperparameters): output = [(construct(kwargs_for_building), dict(), list())] lengths = list() for name, values in build_hyperparameters.items(): new_output = list() lengths.append(len(values)) for base in output: for idx, value in enumerate(values): new_base = construct(base) new_base[0][name] = value new_base[1][name] = value new_base[2].append(idx) new_output.append(new_base) output = new_output sorting_factors = [1] for length in reversed(lengths[1:]): sorting_factors.append(sorting_factors[-1] * length) output = sorted(output, key=lambda set: sum( [point_idx*sorting_factor \ for point_idx, sorting_factor in zip(reversed(set[2][1:]), sorting_factors)])) return output
def configure_args_for_launches(env_instance, args_for_launches, shares): args_for_launches_to_be_used = construct(args_for_launches) parsed = list() for to_be_used in args_for_launches_to_be_used: with_shares = apply_shares(to_be_used, shares) one_parsed = parse_train_method_arguments( env_instance, [], with_shares, set_passed_parameters_as_default=False) start_specs = one_parsed['start_specs'] run_specs_set = one_parsed['run'] del one_parsed['session_specs'] parsed.append((start_specs, run_specs_set)) return parsed
def process_abbreviation_in_1_entry(key, value, method_name): new_value = construct(value) if key == 'stop': if isinstance(value, int): new_value = {'type': 'limit_steps', 'limit': value} set_controller_name_in_specs(new_value, 'stop') if key == 'batch_size': if isinstance(value, int): new_value = {'type': 'fixed', 'value': value} set_controller_name_in_specs(new_value, 'batch_size') if key == 'num_unrollings': if isinstance(value, int): new_value = {'type': 'fixed', 'value': value} set_controller_name_in_specs(new_value, 'num_unrollings') if key == 'checkpoint_steps': if isinstance(value, list): new_value = {'type': 'true_on_steps', 'steps': value} elif isinstance(value, int): new_value = {'type': 'periodic_truth', 'period': value} else: new_value = {'type': 'always_false'} set_controller_name_in_specs(new_value, 'checkpoint_steps') if key == 'learning_rate': set_controller_name_in_specs(new_value, 'learning_rate') if key == 'debug': if isinstance(value, int): new_value = {'type': 'true_on_steps', 'steps': [value]} else: new_value = None set_controller_name_in_specs(new_value, 'debug') if method_name == 'train': if key == 'additions_to_feed_dict': # print('inside additions_to_feed_dict shortcuts processing') if new_value is not None: for addition in new_value: # print('addition:', addition) if not isinstance(addition['value'], dict): # print('Removing of shortcut is happening now') addition['value'] = { 'type': 'fixed', 'value': addition['value'] } # print("addition['value']:", addition['value']) set_controller_name_in_specs(addition['value'], addition['placeholder']) return new_value
def create_1_set_of_args_for_launches(kwargs, one_set_of_args_insertions): kwargs = construct(kwargs) for one_hp_insertion in one_set_of_args_insertions: kwargs = insert_not_build_hp(kwargs, one_hp_insertion) return kwargs