def _uniform_dim(args, func_name, flag_name): from skopt.space import space if len(args) == 2: dim_args = args initial = None elif len(args) == 3: dim_args = args[:2] initial = args[2] else: raise batch_util.BatchError( "%s requires 2 or 3 args, got %r for flag %s" % (func_name, args, flag_name)) return space.check_dimension(dim_args), initial
def parse_ranges(s): if isinstance(s, str): j = json.loads(s) else: j = s dimensions = [] for s in j.values(): # First check, if the string is a list/tuple or a function call: param_str = re.findall(r"(\w+)\(", s) if len(param_str) > 0: # Function args, kwargs = [], dict() # TODO: this split does not always work # (example Categorical(["a", "b", "c"])) prior_param_strings = re.findall(r"\((.*?)\)", s)[0].split(",") for arg_string in prior_param_strings: # Check if arg or kwarg: if "=" in arg_string: # kwarg: # trim all remaining whitespace: arg_string = "".join(arg_string.split()) key, val = arg_string.split("=") kwargs[key] = _make_numeric(val) elif "[" in arg_string or "(" in arg_string: args.append(literal_eval(arg_string)) else: # args: val = _make_numeric(arg_string) args.append(val) if hasattr(skspace, param_str[0]): dim = getattr(skspace, param_str[0])(*args, **kwargs) else: raise ValueError("Dimension {} does not exist.".format(param_str)) dimensions.append(dim) else: # Tuple or list # We assume that the contents of the collection should be used as is and # construct a python list/tuple # skopt.space.check_dimension will be used for validation parsed = literal_eval(s) if isinstance(parsed, (tuple, list)): dimensions.append(check_dimension(parsed)) else: raise ValueError( "Dimension {} is not valid. Make sure you pass a Dimension, tuple " "or list.".format(param_str) ) return dict(zip(j.keys(), dimensions))
def _uniform_dim(args, func_name, flag_name): from skopt.space import space dim_args, initial = _dim_args_and_initial(args, func_name, flag_name) return space.check_dimension(dim_args), initial
def run_ray_tune(ray_address): sk_space = collections.OrderedDict() sk_space['disc_up_per_iter'] = (2, 12) # small values don't work sk_space['sampler_time_steps'] = (8, 20) # small is okay? sk_space['sampler_batch_envs'] = (8, 24) # bigger = better? sk_space['ppo_lr'] = (1e-6, 1e-3, 'log-uniform') sk_space['ppo_gamma'] = (0.9, 1.0, 'log-uniform') sk_space['ppo_lambda'] = (0.9, 1.0, 'log-uniform') sk_space['ppo_ent'] = (1e-6, 1e-4, 'log-uniform') sk_space['ppo_adv_clip'] = (0.05, 0.2, 'uniform') sk_space['add_preproc'] = ['LoRes4E', 'LoRes3EA'] # allow us to have smaller batches or run more of them sk_space['ppo_minibatches'] = [4, 6] sk_space['ppo_epochs'] = [2, 10] sk_space['ppo_use_bn'] = [True, False] sk_space['ppo_aug'] = ['none', 'all', 'crop'] # things I'm commenting out for simplicity: # sk_space['bc_loss'] = ['0.0', str(int(1e-3)), str(1)] # sk_space['ppo_use_bn'] = [True, False] # things that don't matter that much: # sk_space['omit_noop'] = [True, False] # ??? # sk_space['disc_lr'] = (1e-5, 5e-4, 'log-uniform') # fix to 1e-4 # sk_space['disc_use_act'] = [True, False] # fix to True # sk_space['disc_all_frames'] = [True, False] # fix to True # sk_space['disc_replay_mult'] = opt_space.Integer(1, 32, 'log-uniform') # fix to 4 # noqa: E501 # sk_space['ppo_norm_adv'] = [True, False] # fix to False known_working = { 'disc_up_per_iter': [4, 2], 'sampler_time_steps': [16, 16], 'sampler_batch_envs': [32, 12], # 'bc_loss': [0.0, 0.0], 'ppo_lr': [2.5e-4, 2e-4], 'ppo_adv_clip': [0.05, 0.1], 'ppo_minibatches': [4, 5], 'ppo_epochs': [4, 6], 'ppo_use_bn': [False, False], 'ppo_aug': ['none', 'none'], 'ppo_gamma': [0.95, 0.9], 'ppo_lambda': [0.95, 0.9], 'ppo_ent': [1e-5, 1.2e-5], 'add_preproc': ['LoRes4E', 'LoRes4E'] # things that I'm removing because they'll take too much time # 'omit_noop': [True], # things that don't matter much: # 'disc_lr': [1e-4], # 'disc_use_act': [True], # 'disc_all_frames': [True], # 'disc_replay_mult': [4], # 'ppo_norm_adv': [False], } for k, v in list(sk_space.items()): new_v = opt_space.check_dimension(v) new_v.name = k sk_space[k] = new_v sk_optimiser = Optimizer(list(sk_space.values()), base_estimator='GP') n_known_working, = set(map(len, known_working.values())) search_alg = SkOptSearch( sk_optimiser, sk_space.keys(), max_concurrent=8, # XXX figure out how to make this configurable metric='hp_score', mode='max', points_to_evaluate=[[known_working[k][i] for k in sk_space] for i in range(n_known_working)]) if ray_address: ray.init(redis_address=ray_address) tune.run( ray_tune_trial, search_alg=search_alg, local_dir='ray-tune-results', resources_per_trial={"gpu": 0.24}, # this could be 2 days to a week of runs, depending on the env num_samples=200, scheduler=CheckpointFIFOScheduler(search_alg))