assert args.picocvlr_prune_properties in {"none", "train+eval", "eval"}
-if args.result_dir is None: args.result_dir=f"results_{args.task}"
-
-try:
- os.mkdir(args.result_dir)
-except FileExistsError:
- if not args.overwrite_results:
- print(f"result directory {args.result_dir} already exists")
- exit(1)
-
-log_file = open(os.path.join(args.result_dir, args.log_filename), "a")
-
-if args.seed >= 0:
- # torch.backends.cudnn.deterministic = True
- # torch.backends.cudnn.benchmark = False
- # torch.use_deterministic_algorithms(True)
- torch.manual_seed(args.seed)
- if torch.cuda.is_available():
- torch.cuda.manual_seed_all(args.seed)
+if args.result_dir is None:
+ args.result_dir = f"results_{args.task}"
######################################################################
######################################################################
+try:
+ os.mkdir(args.result_dir)
+except FileExistsError:
+ if not args.overwrite_results:
+ print(f"result directory {args.result_dir} already exists")
+ exit(1)
+
+log_file = open(os.path.join(args.result_dir, args.log_filename), "a")
+
+if args.seed >= 0:
+ # torch.backends.cudnn.deterministic = True
+ # torch.backends.cudnn.benchmark = False
+ # torch.use_deterministic_algorithms(True)
+ torch.manual_seed(args.seed)
+ if torch.cuda.is_available():
+ torch.cuda.manual_seed_all(args.seed)
+
+######################################################################
+
def log_string(s):
t = time.strftime("%Y%m%d-%H:%M:%S ", time.localtime())
model, "train", nb_to_use=1000
)
log_string(
- f"accuracy_train nb_total {train_nb_total} nb_correct {train_nb_correct} accuracy {(100.0*train_nb_correct)/train_nb_total:.02f}%"
+ f"accuracy_train {n_epoch} nb_total {train_nb_total} nb_correct {train_nb_correct} accuracy {(100.0*train_nb_correct)/train_nb_total:.02f}%"
)
test_nb_total, test_nb_correct, count = self.compute_error(
model, "test", nb_to_use=1000
)
log_string(
- f"accuracy_test nb_total {test_nb_total} nb_correct {test_nb_correct} accuracy {(100.0*test_nb_correct)/test_nb_total:.02f}%"
+ f"accuracy_test {n_epoch} nb_total {test_nb_total} nb_correct {test_nb_correct} accuracy {(100.0*test_nb_correct)/test_nb_total:.02f}%"
)
if count is not None:
)
log_string(
- f"accuracy_test nb_total {test_nb_total} nb_correct {test_nb_correct} accuracy {(100.0*test_nb_correct)/test_nb_total:.02f}%"
+ f"accuracy_test {n_epoch} nb_total {test_nb_total} nb_correct {test_nb_correct} accuracy {(100.0*test_nb_correct)/test_nb_total:.02f}%"
)
model.train(t)
self.device,
)
- mask = self.test_input.clone()
- stack.remove_popped_values(mask, self.nb_stacks, self.nb_digits)
- mask = mask != self.test_input
- counts = self.test_stack_counts.flatten()[mask.flatten()]
+ i = torch.logical_and(self.test_input % 2 == 1, self.test_input < 2 * nb_stacks)
+ counts = self.test_stack_counts.flatten()[i.flatten()]
counts = F.one_hot(counts).sum(0)
- log_string(f"stack_count {counts}")
+ log_string(f"pop_stack_counts {counts}")
self.nb_codes = max(self.train_input.max(), self.test_input.max()) + 1
test_nb_total, test_nb_correct = compute_nb_correct(self.test_input[:1000])
log_string(
- f"accuracy_test nb_total {test_nb_total} nb_correct {test_nb_correct} accuracy {(100.0*test_nb_correct)/test_nb_total:.02f}%"
+ f"accuracy_test {n_epoch} nb_total {test_nb_total} nb_correct {test_nb_correct} accuracy {(100.0*test_nb_correct)/test_nb_total:.02f}%"
)
- #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- l = 50
- l = l - l % (1 + self.nb_digits)
- input = self.test_input[:10, :l]
+ ##############################################################
+ # Log a few generated sequences
+ input = self.test_input[:10, : 12 * (1 + self.nb_digits)]
result = input.clone()
stack.remove_popped_values(result, self.nb_stacks, self.nb_digits)
ar_mask = (result != input).long()
log_string(
f"test_after {stack.seq_to_str(result[n],nb_stacks=self.nb_stacks,nb_digits=self.nb_digits)}"
)
- #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+ ##############################################################
model.train(t)
(stack_counts[k, st] - 1).clamp(min=0),
]
stack[k, st, stack_counts[k, st]] = val_push
- recorded_stack_counts[:, (1 + nb_digits) * t + 1] = stack_counts[k, st]
+ recorded_stack_counts[:, (1 + nb_digits) * t] = stack_counts[k, st]
stack_counts[k[op == 0], st[op == 0]] += 1
stack_counts[k[op == 1], st[op == 1]] -= 1
result[:, (1 + nb_digits) * t] = st * 2 + op
n_op = seq[(1 + nb_digits) * t]
if t > 0:
s += " "
+ if recorded_stack_counts is not None:
+ s += f"[{recorded_stack_counts[(1 + nb_digits)*t]}] "
s += f"POP" if n_op % 2 == 1 else f"PSH"
if nb_stacks > 1:
s += f"_{n_op//2}"
s += " ?"
else:
s += f" {seq[(1 + nb_digits) * t + 1 + d] - 2 * nb_stacks:1d}"
- if recorded_stack_counts is not None:
- s += f"[{recorded_stack_counts[(1 + nb_digits)*t+1]}] "
return s
)
for n in range(min(10, seq.size(0))):
- # print(seq_to_str(seq[n], recorded_stack_counts[n]))
- print(seq_to_str(seq[n], nb_stacks=nb_stacks, nb_digits=nb_digits))
+ print(
+ seq_to_str(
+ seq[n],
+ nb_stacks=nb_stacks,
+ nb_digits=nb_digits,
+ recorded_stack_counts=recorded_stack_counts[n],
+ )
+ )
+ # print(seq_to_str(seq[n], nb_stacks=nb_stacks, nb_digits=nb_digits))
print("-- PREPARED FOR TEST -----------------")