def oneshot(ver, gene): import sys if "../lib" not in sys.path: sys.path.append("../lib") import geneop import config as cfg gene_type = ver geneop.load_type(gene_type) gene = int(gene) n = { "v1": 142, }[gene_type] gene = geneop.cvtintlst(gene, n) cfg.worker_config = { "result_format": ("sdr", "neg_gflops", "neg_mega_pc"), "batch_size": 2, "max_lr": 3e-4, "min_lr": 1e-4, "warmup_fac": 0.3, "first_lr_period": 100, "warmup_period": 100, "n_hop_per_sample": 64, "work_sr": 8000, "hop_size": 256, "fft_size": 1024, "n_feature": 512, "n_train": 156, "n_step": 700, "n_eval": 3, } pre_fn() r = eval_fn(gene) del cfg.worker_config clean_env() return r
def infer(x, n_out_channel, train, ver=None, gene=None): import sys if not "../lib" in sys.path: sys.path.append("../lib") import geneop import config as cfg if ver is not None: geneop.load_type(ver) if isinstance(gene, int): gene = geneop.cvtintlst(gene, geneop.gene_len) else: raise TypeError("Invalid gene value `%r`" % (gene,)) else: geneop.load_type(cfg.gene_ver) gene = geneop.cvtintlst(cfg.gene_value, geneop.gene_len) return geneop.build_from_gene(x, n_out_channel, gene)
def pre_fn(): import simpleopt dataset_type = simpleopt.get("dataset") gene_type = simpleopt.get("ver") geneop.load_type(gene_type) cfg.n = { "v1": 142, "v1pe": 142, "v1f16": 142, }[gene_type] if dataset_type == "mus2": '''cfg.worker_config = { "result_format": ("sdr", "neg_gflops", "neg_mega_pc", "valid_sdr"), "batch_size": 3, "max_lr": 3e-4, "min_lr": 1e-4, "warmup_fac": 0.3, "first_lr_period": 10000, "warmup_period": 1000, "n_hop_per_sample": 64, "work_sr": 16000, "hop_size": 512, "fft_size": 2048, "n_feature": 1024, }''' cfg.worker_config = { "result_format": ("sdr", "neg_gflops", "neg_mega_pc", "valid_sdr"), "batch_size": 3, "max_lr": 3e-4, "min_lr": 1e-4, "warmup_fac": 0.3, "first_lr_period": 100, "warmup_period": 100, "n_hop_per_sample": 64, "work_sr": 16000, "hop_size": 512, "fft_size": 2048, "n_feature": 1024, } else: cfg.worker_config = { "result_format": ("sdr", "neg_gflops", "neg_mega_pc", "valid_sdr"), "batch_size": 2, "max_lr": 3e-4, "min_lr": 1e-4, "warmup_fac": 0.3, "first_lr_period": 100, "warmup_period": 100, "n_hop_per_sample": 64, "work_sr": 8000, "hop_size": 256, "fft_size": 1024, "n_feature": 512, } if dataset_type == "mir2": cfg.worker_config.update( n_train=100, n_step=1500, n_eval=55, n_valid=20, ) elif dataset_type == "dsd2": cfg.worker_config.update( n_train=30, n_step=3100, n_eval=15, n_valid=5, ) elif dataset_type == "mus2": '''cfg.worker_config.update( n_train=60, n_step=30000, n_eval=30, n_valid=10, )''' cfg.worker_config.update( n_train=60, n_step=3100, n_eval=30, n_valid=10, ) cfg.worker = __import__("worker_%s" % (dataset_type, )) cfg.worker.clean_env() cfg.worker.pre_fn()
def main(pool): import requests, time, os, socket from urllib3.util.retry import Retry from requests.adapters import HTTPAdapter print("* Check RNG reliability... ", end="") check_rng() print("OK") create_lock() import config as cfg cfg.pool = pool print("* Check framework reliability... ", end="") check_framework() print("OK") while True: cfg.pool = None def boundary(): for x in ("worker_mir2", "worker_dsd2"): __import__(x).clean_env() boundary() del boundary try: with requests.Session() as net_sess: retries = Retry(total=8, backoff_factor=0.1, status_forcelist=[500, 502, 503, 504]) net_sess.mount("http://", HTTPAdapter(max_retries=retries)) net_sess.mount("https://", HTTPAdapter(max_retries=retries)) cfg.net_sess = net_sess print("* Register") url_register = urljoin(cfg.srv_url, "/register") ret = cfg.net_sess.post(url_register, json={ "hostname": socket.gethostname(), "version": cfg.cli_version }, timeout=8.0) if ret.status_code != 200: raise RuntimeError("Cannot connect to server: HTTP %d" % (ret.status_code, )) ret = ret.json() cfg.cli_id = ret["cli_id"] print("* Client ID=#%d" % (cfg.cli_id, )) with Boundary(): print("* Enter boundary") worker_type, worker_config, gene_type = ret[ "worker_type"], ret["worker_config"], ret["gene_type"] print("* worker_type=%r" % (worker_type, )) print("* worker_config=%r" % (worker_config, )) cfg.worker_type = worker_type cfg.worker_config = worker_config cfg.gene_type = gene_type import geneop geneop.load_type(gene_type) cfg.pool = pool cfg.dog = watchdog.Watchdog() cfg.dog.start() worker = __import__("worker_%s" % (worker_type, )) worker.pre_fn() while True: try: print("* Acquire GPU...") cfg.lock.acquire() print("* Got GPU!") print("* Asking for new task...") ret = send_rpc("get_task") action = ret["action"] if action == "wait": print("* No task available at this moment.") time.sleep( 3 if cfg.worker_type != "toy" else 0.1) elif action == "run": print("* Got new task, working...") task_id, gene = ret["task_id"], ret["gene"] cfg.hurdle_limit_list = ret.get( "hurdle_limit_list", None) result = worker.eval_fn(gene) print("* Task finished, submitting result...") send_rpc("submit_result", task_id, result) print("* Result submitted") finally: cfg.lock.release() except KeyboardInterrupt: print("* Got KeyboardInterrupt, killing watchdog...") if cfg.dog is not None: cfg.dog.request_stop = True cfg.dog.join() print("* Bye!") os._exit(0) except: print("* Got Exception, restarting...") traceback.print_exc() if cfg.dog is not None: cfg.dog.request_stop = True cfg.dog.join() print("* Restarted!")
# Server will be stopped if this value is met. # n_gen = 300 # ⚠️ defined dynmatically in the end of this config ⚠️ # str: Algorithm of evolution to use. # "g1" for single target, "nsga2" for two target. evo_type = "nsga2" # module: Python module for specified evo_type (do not change!) evo_module = __import__("evo_%s" % (evo_type, )) # float: Ratio of pure random gene in initial population. # 0.0 means no pure random gene, 1.0 means all population are built with pure random gene. init_random_ratio = 0.0 p2 = 0.02 # Section: Gene # str: "v1" for the paper (do not change!) gene_type = "v1" geneop.load_type(gene_type) # List[List[bool]]: Handcrafted initial population (do not change!) if init_random_ratio != 1.0: if gene_type == "v1": manual_gene_list = [ geneop.cvtintlst(x, 142) for x in [ 4182591019167972528534244115322478782824676, ] ] else: assert False # Section: Evolution(Additional) # int: Maximum number of bits to flip when generate gene from handcrafted popluation (do not change!) if init_random_ratio != 1.0: if gene_type in ("v1", ):