1
0
Fork 0

Verify whether there is a network being used during training.

pull/3472/head
Tomasz Sobczyk 2020-10-14 20:20:10 +02:00 committed by nodchip
parent e503cc4ea8
commit 5db46d0c82
7 changed files with 58 additions and 32 deletions

View File

@ -1000,7 +1000,7 @@ namespace Learner
<< " detect_draw_by_insufficient_mating_material = " << detect_draw_by_insufficient_mating_material << endl;
// Show if the training data generator uses NNUE.
Eval::NNUE::verify();
Eval::NNUE::verify_eval_file_loaded();
Threads.main()->ponder = false;

View File

@ -1486,6 +1486,27 @@ namespace Learner
std::cout << "..shuffle_on_memory done." << std::endl;
}
static void set_learning_search_limits()
{
// About Search::Limits
// Be careful because this member variable is global and affects other threads.
auto& limits = Search::Limits;
limits.startTime = now();
// Make the search equivalent to the "go infinite" command. (Because it is troublesome if time management is done)
limits.infinite = true;
// Since PV is an obstacle when displayed, erase it.
limits.silent = true;
// If you use this, it will be compared with the accumulated nodes of each thread. Therefore, do not use it.
limits.nodes = 0;
// depth is also processed by the one passed as an argument of Learner::search().
limits.depth = 0;
}
// Learning from the generated game record
void learn(Position&, istringstream& is)
{
@ -1837,30 +1858,9 @@ namespace Learner
cout << "init.." << endl;
// Read evaluation function parameters
Eval::NNUE::init();
Threads.main()->ponder = false;
// About Search::Limits
// Be careful because this member variable is global and affects other threads.
{
auto& limits = Search::Limits;
limits.startTime = now();
// Make the search equivalent to the "go infinite" command. (Because it is troublesome if time management is done)
limits.infinite = true;
// Since PV is an obstacle when displayed, erase it.
limits.silent = true;
// If you use this, it will be compared with the accumulated nodes of each thread. Therefore, do not use it.
limits.nodes = 0;
// depth is also processed by the one passed as an argument of Learner::search().
limits.depth = 0;
}
set_learning_search_limits();
cout << "init_training.." << endl;
Eval::NNUE::InitializeTraining(seed);
@ -1907,6 +1907,8 @@ namespace Learner
sr.read_validation_set(validation_set_file_name, eval_limit);
}
Eval::NNUE::verify_any_net_loaded();
// Calculate rmse once at this point (timing of 0 sfen)
// sr.calc_rmse();

View File

@ -11,11 +11,6 @@
void MultiThink::go_think()
{
// Read evaluation function, etc.
// In the case of the learn command, the value of the evaluation function may be corrected after reading the evaluation function, so
// Skip memory corruption check.
Eval::NNUE::init();
// Call the derived class's init().
init();

View File

@ -235,6 +235,7 @@ namespace Eval::NNUE {
else
{
sync_cout << "info string ERROR: failed to load eval file " << directory + eval_file << sync_endl;
eval_file_loaded.clear();
}
}
@ -243,7 +244,7 @@ namespace Eval::NNUE {
}
/// NNUE::verify() verifies that the last net used was loaded successfully
void verify() {
void verify_eval_file_loaded() {
std::string eval_file = std::string(Options["EvalFile"]);
@ -273,4 +274,31 @@ namespace Eval::NNUE {
sync_cout << "info string classical evaluation enabled" << sync_endl;
}
/// In training we override eval file so this is useful.
void verify_any_net_loaded() {
if (useNNUE != UseNNUEMode::False && eval_file_loaded.empty())
{
UCI::OptionsMap defaults;
UCI::init(defaults);
std::string msg1 = "If the UCI option \"Use NNUE\" is set to true, network evaluation parameters compatible with the engine must be available.";
std::string msg2 = "The option is set to true, but the network file was not loaded successfully.";
std::string msg3 = "The UCI option EvalFile might need to specify the full path, including the directory name, to the network file.";
std::string msg5 = "The engine will be terminated now.";
sync_cout << "info string ERROR: " << msg1 << sync_endl;
sync_cout << "info string ERROR: " << msg2 << sync_endl;
sync_cout << "info string ERROR: " << msg3 << sync_endl;
sync_cout << "info string ERROR: " << msg5 << sync_endl;
std::exit(EXIT_FAILURE);
}
if (useNNUE != UseNNUEMode::False)
sync_cout << "info string NNUE evaluation using " << eval_file_loaded << " enabled" << sync_endl;
else
sync_cout << "info string classical evaluation enabled" << sync_endl;
}
} // namespace Eval::NNUE

View File

@ -96,7 +96,8 @@ namespace Eval::NNUE {
Value evaluate(const Position& pos);
bool load_eval(std::string name, std::istream& stream);
void init();
void verify();
void verify_eval_file_loaded();
void verify_any_net_loaded();
} // namespace Eval::NNUE

View File

@ -219,7 +219,7 @@ void MainThread::search() {
Time.init(Limits, us, rootPos.game_ply());
TT.new_search();
Eval::NNUE::verify();
Eval::NNUE::verify_eval_file_loaded();
if (rootMoves.empty())
{

View File

@ -101,7 +101,7 @@ namespace {
Position p;
p.set(pos.fen(), Options["UCI_Chess960"], &states->back(), Threads.main());
Eval::NNUE::verify();
Eval::NNUE::verify_eval_file_loaded();
sync_cout << "\n" << Eval::trace(p) << sync_endl;
}