def main(args, unknown_args): args, config = parse_args_uargs(args, unknown_args, dump_config=True) os.makedirs(args.logdir, exist_ok=True) save_config(config=config, logdir=args.logdir) if args.expdir is not None: modules = prepare_modules( # noqa: F841 expdir=args.expdir, dump_dir=args.logdir) algorithm = Registry.get_fn("algorithm", args.algorithm) algorithm_kwargs = algorithm.prepare_for_trainer(config) redis_server = StrictRedis(port=config.get("redis", {}).get("port", 12000)) redis_prefix = config.get("redis", {}).get("prefix", "") pprint(config["trainer"]) pprint(algorithm_kwargs) trainer = Trainer(**config["trainer"], **algorithm_kwargs, logdir=args.logdir, redis_server=redis_server, redis_prefix=redis_prefix) pprint(trainer) def on_exit(): for p in trainer.get_processes(): p.terminate() atexit.register(on_exit) trainer.run()
def main(args, unknown_args): args, config = parse_args_uargs(args, unknown_args, dump_config=True) set_global_seeds(args.seed) assert args.baselogdir is not None or args.logdir is not None if args.logdir is None: modules_ = prepare_modules(model_dir=args.model_dir) logdir = modules_["model"].prepare_logdir(config=config) args.logdir = str(pathlib.Path(args.baselogdir).joinpath(logdir)) create_if_need(args.logdir) save_config(config=config, logdir=args.logdir) modules = prepare_modules(model_dir=args.model_dir, dump_dir=args.logdir) datasource = modules["data"].DataSource() model = modules["model"].prepare_model(config) runner = modules["model"].ModelRunner(model=model) runner.train_stages(datasource=datasource, args=args, stages_config=config["stages"], verbose=args.verbose)
def main(args, unknown_args): args, config = parse_args_uargs(args, unknown_args, dump_config=True) os.makedirs(args.logdir, exist_ok=True) save_config(config=config, logdir=args.logdir) if args.expdir is not None: modules = prepare_modules( # noqa: F841 expdir=args.expdir, dump_dir=args.logdir) algorithm = Registry.get_fn("algorithm", args.algorithm) if args.environment is not None: # @TODO: remove this hack # come on, just refactor whole rl environment_fn = Registry.get_fn("environment", args.environment) env = environment_fn(**config["env"]) config["shared"]["observation_size"] = env.observation_shape[0] config["shared"]["action_size"] = env.action_shape[0] del env algorithm_kwargs = algorithm.prepare_for_trainer(config) redis_server = StrictRedis(port=config.get("redis", {}).get("port", 12000)) redis_prefix = config.get("redis", {}).get("prefix", "") pprint(config["trainer"]) pprint(algorithm_kwargs) trainer = Trainer(**config["trainer"], **algorithm_kwargs, logdir=args.logdir, redis_server=redis_server, redis_prefix=redis_prefix) pprint(trainer) def on_exit(): for p in trainer.get_processes(): p.terminate() atexit.register(on_exit) trainer.run()
def main(args, unknown_args): args, config = parse_args_uargs(args, unknown_args) set_global_seeds(args.seed) modules = prepare_modules(expdir=args.expdir) model = Registry.get_model(**config["model_params"]) datasource = modules["data"].DataSource() data_params = config.get("data_params", {}) or {} loaders = datasource.prepare_loaders(mode="infer", n_workers=args.workers, batch_size=args.batch_size, **data_params) runner = modules["model"].ModelRunner(model=model) callbacks_params = config.get("callbacks_params", {}) or {} callbacks = runner.prepare_callbacks(mode="infer", resume=args.resume, out_prefix=args.out_prefix, **callbacks_params) runner.infer(loaders=loaders, callbacks=callbacks, verbose=args.verbose)
def main(args, unknown_args): args, config = parse_args_uargs(args, unknown_args) os.makedirs(args.logdir, exist_ok=True) save_config(config=config, logdir=args.logdir) if args.expdir is not None: modules = prepare_modules( # noqa: F841 expdir=args.expdir, dump_dir=args.logdir) algorithm = Registry.get_fn("algorithm", args.algorithm) environment = Registry.get_fn("environment", args.environment) processes = [] sampler_id = 0 def on_exit(): for p in processes: p.terminate() atexit.register(on_exit) params = dict(logdir=args.logdir, algorithm=algorithm, environment=environment, config=config, resume=args.resume, redis=args.redis) if args.debug: params_ = dict( vis=False, infer=False, action_noise=0.5, param_noise=0.5, action_noise_prob=args.action_noise_prob, param_noise_prob=args.param_noise_prob, id=sampler_id, ) run_sampler(**params, **params_) for i in range(args.vis): params_ = dict( vis=False, infer=False, action_noise_prob=0, param_noise_prob=0, id=sampler_id, ) p = mp.Process(target=run_sampler, kwargs=dict(**params, **params_)) p.start() processes.append(p) sampler_id += 1 for i in range(args.infer): params_ = dict( vis=False, infer=True, action_noise_prob=0, param_noise_prob=0, id=sampler_id, ) p = mp.Process(target=run_sampler, kwargs=dict(**params, **params_)) p.start() processes.append(p) sampler_id += 1 for i in range(1, args.train + 1): action_noise = args.max_action_noise * i / args.train \ if args.max_action_noise is not None \ else None param_noise = args.max_param_noise * i / args.train \ if args.max_param_noise is not None \ else None params_ = dict( vis=False, infer=False, action_noise=action_noise, param_noise=param_noise, action_noise_prob=args.action_noise_prob, param_noise_prob=args.param_noise_prob, id=sampler_id, ) p = mp.Process(target=run_sampler, kwargs=dict(**params, **params_)) p.start() processes.append(p) sampler_id += 1 for p in processes: p.join()