From: François Fleuret Date: Thu, 20 Jul 2023 06:41:23 +0000 (+0200) Subject: Update. X-Git-Url: https://ant.fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=commitdiff_plain;h=f38523dc7bcd791867b45423babb8ddb3358b31e;p=picoclvr.git Update. --- diff --git a/README.txt b/README.txt index d4cb93d..a4cd46b 100644 --- a/README.txt +++ b/README.txt @@ -1,10 +1,12 @@ +====================================================================== For the stack experiment: ./main.py --task=stack Takes ~1h10min on a 4090. +====================================================================== For the arithmetic expressions experiments # 38M parameters / 250k samples @@ -15,3 +17,4 @@ For the arithmetic expressions experiments learning rate schedule is obviously terrible ./main.py --task=expr --nb_blocks=48 --dim_model=1024 --nb_train_samples=2500000 --result_dir=results_expr_48b_d1024_2.5M +====================================================================== diff --git a/main.py b/main.py index 71026c5..ba8843b 100755 --- a/main.py +++ b/main.py @@ -79,7 +79,18 @@ parser.add_argument("--overwrite_results", action="store_true", default=False) parser.add_argument("--checkpoint_name", type=str, default="checkpoint.pth") ############################## -# picoclvr options +# rpl options + +parser.add_argument("--rpl-nb_starting_values", type=int, default=5) + +parser.add_argument("--rpl-max_input", type=int, default=9) + +parser.add_argument("--rpl-prog_len", type=int, default=10) + +parser.add_argument("--rpl-nb_runs", type=int, default=8) + +############################## +# sandbox options parser.add_argument("--sandbox_level", type=int, default=0) @@ -427,6 +438,10 @@ elif args.task == "rpl": nb_train_samples=args.nb_train_samples, nb_test_samples=args.nb_test_samples, batch_size=args.batch_size, + nb_starting_values=args.rpl_nb_starting_values, + max_input=args.rpl_max_input, + prog_len=args.rpl_prog_len, + nb_runs=args.rpl_nb_runs, logger=log_string, device=device, ) diff --git a/tasks.py b/tasks.py index bad4536..0fac0a7 100755 --- a/tasks.py +++ b/tasks.py @@ -1097,7 +1097,10 @@ class RPL(Task): self.token2id = dict([(c, n) for n, c in enumerate(symbols)]) self.id2token = dict([(n, c) for c, n in self.token2id.items()]) - self.t_nul, self.t_prog = self.token2id[""], self.token2id[""] + self.t_nul = self.token2id[""] + self.t_prog = self.token2id[""] + self.t_input = self.token2id[""] + self.t_output = self.token2id[""] self.train_input = self.tensorize(train_sequences) self.test_input = self.tensorize(test_sequences) @@ -1133,7 +1136,7 @@ class RPL(Task): self, n_epoch, model, result_dir, logger, deterministic_synthesis ): # -------------------------------------------------------------------- - def compute_nb_errors(input, nb_to_log=0): + def compute_nb_errors_prog(input, nb_to_log=0): result = input.clone() s = (result == self.t_prog).long() ar_mask = (s.cumsum(dim=1) - s).clamp(min=0, max=1) @@ -1173,9 +1176,51 @@ class RPL(Task): return sum_nb_total, sum_nb_errors + # -------------------------------------------------------------------- + def compute_nb_errors_output(input, nb_to_log=0): + result = input.clone() + k = torch.arange(result.size(1), device=result.device)[None,:] + last_output_idx = ((result == self.t_output) * k).max(dim=1,keep_dim=True) + first_prog_idx = ((result == self.t_prog) * k).min(dim=1,keep_dim=True) + ar_mask = (k > last_output_idx).long() * (k < first_prog_idx) + result = (1 - ar_mask) * result + ar_mask * self.t_nul + + masked_inplace_autoregression( + model, + self.batch_size, + result, + ar_mask, + deterministic_synthesis, + device=self.device, + ) + + sum_nb_total, sum_nb_errors = 0, 0 + for x, y in zip(input, result): + seq = [self.id2token[i.item()] for i in y] + sum_nb_total += 1 + sum_nb_errors += 0 if (x-y).abs().max() == 0 else 1 + if nb_to_log > 0: + gt_seq = [self.id2token[i.item()] for i in x] + _, _, gt_prog, _ = rpl.compute_nb_errors(gt_seq) + gt_prog = " ".join([str(x) for x in gt_prog]) + prog = " ".join([str(x) for x in prog]) + comment = "*" if nb_errors == 0 else "-" + logger(f"{comment} PROG [{gt_prog}] PREDICTED [{prog}]") + for start_stack, target_stack, result_stack, correct in stacks: + comment = "*" if correct else "-" + start_stack = " ".join([str(x) for x in start_stack]) + target_stack = " ".join([str(x) for x in target_stack]) + result_stack = " ".join([str(x) for x in result_stack]) + logger( + f" {comment} [{start_stack}] -> [{target_stack}] PREDICTED [{result_stack}]" + ) + nb_to_log -= 1 + + return sum_nb_total, sum_nb_errors + # -------------------------------------------------------------------- - test_nb_total, test_nb_errors = compute_nb_errors( + test_nb_total, test_nb_errors = compute_nb_errors_prog( self.test_input[:1000].to(self.device), nb_to_log=10 )