def main_loop(self): evaluator = Evaluator(stats=False) # Set game to online model. env, args = load_env(os.environ, evaluator=evaluator, overrides=dict( num_games=1, batchsize=1, num_games_per_thread=1, greedy=True, T=1, additional_labels="aug_code,move_idx")) GC = env["game"].initialize() model = env["model_loaders"][0].load_model(GC.params) mi = ModelInterface() mi.add_model("model", model) mi.add_model("actor", model, copy=True, cuda=args.gpu is not None, gpu_id=args.gpu) mi["model"].eval() mi["actor"].eval() self.evaluator = evaluator self.last_move_idx = None def human_actor(batch): print("In human_actor") return self.prompt("DF> ", batch) def actor(batch): return self.actor(batch) def train(batch): self.prompt("DF Train> ", batch) evaluator.setup(sampler=env["sampler"], mi=mi) GC.reg_callback_if_exists("actor", actor) GC.reg_callback_if_exists("human_actor", human_actor) GC.reg_callback_if_exists("train", train) GC.Start() evaluator.episode_start(0) while True: GC.Run() if self.exit: break GC.Stop()
def main_loop(self): evaluator = Evaluator(stats=False) # Set game to online model. env, args = load_env(os.environ, evaluator=evaluator, overrides=dict(num_games=1, batchsize=1, num_games_per_thread=1, greedy=True, T=1, additional_labels="aug_code,move_idx")) GC = env["game"].initialize() model = env["model_loaders"][0].load_model(GC.params) mi = ModelInterface() mi.add_model("model", model) mi.add_model("actor", model, copy=True, cuda=args.gpu is not None, gpu_id=args.gpu) mi["model"].eval() mi["actor"].eval() self.evaluator = evaluator self.last_move_idx = None def human_actor(batch): print("In human_actor") return self.prompt("DF> ", batch) def actor(batch): return self.actor(batch) def train(batch): self.prompt("DF Train> ", batch) evaluator.setup(sampler=env["sampler"], mi=mi) GC.reg_callback_if_exists("actor", actor) GC.reg_callback_if_exists("human_actor", human_actor) GC.reg_callback_if_exists("train", train) GC.Start() evaluator.episode_start(0) while True: GC.Run() if self.exit: break GC.Stop()
model = env["model_loaders"][0].load_model(GC.params) env["mi"].add_model("actor", model, cuda=not args.gpu is None, gpu_id=args.gpu) env["mi"]["actor"].eval() def actor(batch): reply = evaluator.actor(batch) ''' s = batch["s"][0][0] seq = batch["seq"][0][0] for i in range(s.size(0)): print("[seq=%d][c=%d]: %s" % (seq, i, str(s[i]))) print("[seq=%d]: %s" % (seq, str(reply["pi"][0]))) print("[seq=%d]: %s" % (seq, str(reply["a"][0]))) ''' eval_iters.stats.feed_batch(batch) return reply evaluator.setup(sampler=env["sampler"], mi=env["mi"]) GC.reg_callback("actor", actor) GC.Start() evaluator.episode_start(0) for n in eval_iters.iters(): GC.Run() GC.Stop()
evaluator.setup(mi=mi) total_batchsize = 0 total_sel_batchsize = 0 def actor(batch): global total_batchsize, total_sel_batchsize reply = evaluator.actor(batch) total_sel_batchsize += batch.batchsize total_batchsize += batch.max_batchsize if total_sel_batchsize >= 5000: print("Batch usage: %d/%d (%.2f%%)" % (total_sel_batchsize, total_batchsize, 100.0 * total_sel_batchsize / total_batchsize)) total_sel_batchsize = 0 total_batchsize = 0 # import pdb # pdb.set_trace() return reply GC.reg_callback_if_exists("actor", actor) GC.Start() evaluator.episode_start(0) while True: GC.Run() GC.Stop()