+ ##################################################
+ # Select, improve, and eval the worst model
+
+ ranked_models = sorted(models, key=lambda m: float(m.main_test_accuracy))
+
+ weakest_models = ranked_models[: len(gpus)]
+
+ threads = []
+
+ for gpu, model in zip(gpus, weakest_models):
+ log_string(f"training model {model.id}")
+
+ t = threading.Thread(
+ target=one_epoch, daemon=True, args=(model, quiz_machine, gpu)
+ )
+
+ threads.append(t)
+
+ t.start()
+
+ for t in threads:
+ t.join()
+
+ ##################################################
+ # Replace a fraction of the w_quizzes with fresh ones
+
+ log_string(
+ f"cache_w_quizzes contains {quiz_machine.problem.nb_cached_quizzes()} quizzes"
+ )
+
+ # Renew entirely the train set
+
+ for model in weakest_models:
+ quiz_machine.renew_w_quizzes(model, args.nb_train_samples)
+
+ ##################################################
+ # If all the models are good enough, generate new quizzes and
+ # re-compute the test errors