from torch.nn import functional as F
import ffutils
+
import mygpt
import sky, grids, quiz_machine
+from problem import MultiThreadProblem
# world quizzes vs. culture quizzes
######################################################################
-nb_new_c_quizzes_for_train = 1000
-nb_new_c_quizzes_for_test = 100
-
-######################################################################
-
if torch.cuda.is_available():
device = torch.device("cuda")
torch.backends.cuda.matmul.allow_tf32 = True
parser.add_argument("--deterministic_synthesis", action="store_true", default=False)
-parser.add_argument("--problem", type=str, default="sky")
+parser.add_argument("--problem", type=str, default="grids")
+
+parser.add_argument("--multi_thread_problem", action="store_true", default=False)
parser.add_argument("--nb_gpts", type=int, default=5)
######################################################################
-if args.dirty_debug:
- args.accuracy_to_make_c_quizzes = 0.0
- args.nb_gpts = 2
- nb_new_c_quizzes_for_train = 100
- nb_new_c_quizzes_for_test = 10
-
-######################################################################
-
default_args = {
"model": "37M",
"batch_size": 100,
else:
raise ValueError
+if args.multi_thread_problem:
+ problem = MultiThreadProblem(problem, args.nb_train_samples, chunk_size=1000)
+
quiz_machine = quiz_machine.QuizMachine(
problem=problem,
nb_train_samples=args.nb_train_samples,
)
file_name = os.path.join(args.result_dir, f"culture_c_quiz_{n_epoch:04d}_logp.dat")
+
with open(file_name, "w") as logp_file:
while (
valid_c_quizzes(quizzes_and_nb_correct_records, standard_validity).size(0)
temperature=args.generation_temperature,
)
- nb_correct, seq_logproba = quiz_machine.compute_correctness(
- c_quizzes,
- models,
- bidirectional_validation=args.bidirectional_validation,
- deterministic_validation=args.deterministic_validation,
- )
-
- for n, l in zip(nb_correct, seq_logproba):
- s = " ".join([str(x.item()) for x in l])
- logp_file.write(f"{n} {s}\n")
+ c_quizzes = c_quizzes[quiz_machine.non_trivial(c_quizzes)]
- if args.dirty_debug:
- nb_correct = torch.randint(
- len(models) + 1, nb_correct.size(), device=c_quizzes.device
+ if c_quizzes.size(0) > 0:
+ nb_correct, seq_logproba = quiz_machine.compute_correctness(
+ c_quizzes,
+ models,
+ bidirectional_validation=args.bidirectional_validation,
+ deterministic_validation=args.deterministic_validation,
)
- quizzes_and_nb_correct_records.append((c_quizzes, nb_correct))
+ for n, l in zip(nb_correct, seq_logproba):
+ s = " ".join([str(x.item()) for x in l])
+ logp_file.write(f"{n} {s}\n")
+
+ if args.dirty_debug:
+ nb_correct = torch.randint(
+ len(models) + 1, nb_correct.size(), device=c_quizzes.device
+ )
+
+ quizzes_and_nb_correct_records.append((c_quizzes, nb_correct))
nv = F.one_hot(nb_correct, num_classes=len(models) + 1).sum(0)
nv = " ".join([str(x.item()) for x in nv])
######################################################################
+nb_new_c_quizzes_for_train = args.nb_train_samples // 50
+nb_new_c_quizzes_for_test = args.nb_test_samples // 50
+
+log_string(
+ f"nb_new_c_quizzes_for_train {nb_new_c_quizzes_for_train} nb_new_c_quizzes_for_test {nb_new_c_quizzes_for_test}"
+)
+
+######################################################################
+
+if args.dirty_debug:
+ args.accuracy_to_make_c_quizzes = 0.0
+ args.nb_gpts = 2
+ nb_new_c_quizzes_for_train = 100
+ nb_new_c_quizzes_for_test = 10
+
+######################################################################
+
for n_epoch in range(args.nb_epochs):
log_string(f"--- epoch {n_epoch} ----------------------------------------")
cta = " ".join([f"{float(m.main_test_accuracy):.04f}" for m in models])
log_string(f"current_test_accuracies {cta}")
+ ##################################################
# Select, improve, and eval the worst model
weakest_model = min(models, key=lambda m: float(m.main_test_accuracy))
f"test_set_composition w_quizzes {quiz_machine.nb_batch_w_quizzes} c_quizzes {quiz_machine.nb_batch_c_quizzes}"
)
+ ##################################################
# Replace a fraction of the w_quizzes with fresh ones
quiz_machine.renew_w_quizzes(args.nb_train_samples // args.nb_gpts)
+ ##################################################
# If all the models are good enough, generate new quizzes and
# re-compute the test errors