X-Git-Url: https://www.fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=blobdiff_plain;f=beaver.py;h=5abe39b767c13299d8dcffcc3369682bfbfff69f;hb=HEAD;hp=6e1eaf4137f5a3bc184f4bd8fd529adbd1791745;hpb=519b5419b30de82828a41b620e76d993a70423e9;p=beaver.git diff --git a/beaver.py b/beaver.py index 6e1eaf4..5abe39b 100755 --- a/beaver.py +++ b/beaver.py @@ -127,6 +127,8 @@ def log_string(s): sys.stdout.flush() +log_string(f"cmd {' '.join(sys.argv)}") + for n in vars(args): log_string(f"args.{n} {getattr(args, n)}") @@ -236,8 +238,13 @@ def oneshot_trace_loss(mazes, output, policies, height, width): def oneshot(model, learning_rate_scheduler, task): t = model.training model.eval() - mazes = task.test_input[:32].clone() + mazes = task.test_input[:48].clone() mazes[:, task.height * task.width :] = 0 + policies = task.test_policies[:48] + targets = maze.stationary_densities( + mazes[:, : task.height * task.width].view(-1, task.height, task.width), + policies.view(-1, 4, task.height, task.width), + ).flatten(-2) output = eval_mygpt(model, mazes, prompt_len=task.height * task.width) output = F.softmax(output, dim=2) print(f"{output.size()=}") @@ -245,16 +252,17 @@ def oneshot(model, learning_rate_scheduler, task): -1, task.height, task.width ) mazes = mazes[:, : task.height * task.width].reshape(-1, task.height, task.width) - paths = task.test_input[:32, task.height * task.width :].reshape( + targets = targets.reshape(-1, task.height, task.width) + paths = task.test_input[:48, task.height * task.width :].reshape( -1, task.height, task.width ) filename = f"oneshot.png" maze.save_image( os.path.join(args.result_dir, filename), mazes=mazes, - target_paths=paths, + # target_paths=paths, score_paths=proba_path, - # score_truth=targets, + score_truth=targets, ) log_string(f"wrote {filename}") @@ -327,8 +335,8 @@ def oneshot_old(gpt, learning_rate_scheduler, task): ) # ------------------- - mazes = task.test_input[:32, : task.height * task.width] - policies = task.test_policies[:32] + mazes = task.test_input[:48, : task.height * task.width] + policies = task.test_policies[:48] output_gpt = eval_mygpt( gpt, mazes, mode=args.oneshot_input, prompt_len=task.height * task.width ) @@ -571,7 +579,7 @@ class TaskMaze(Task): f"accuracy_test nb_total {test_nb_total} nb_correct {test_nb_correct} accuracy {(100.0*test_nb_correct)/test_nb_total:.02f}%" ) - input = self.test_input[:32] + input = self.test_input[:48] result = input.clone() ar_mask = result.new_zeros(result.size()) ar_mask[:, self.height * self.width :] = 1