From 158399da4b368c2118e0d418f09f6dd142608760 Mon Sep 17 00:00:00 2001 From: nodchip Date: Wed, 9 Sep 2020 20:16:09 +0900 Subject: [PATCH 1/7] Remove compile warnings. --- .travis.yml | 3 +-- src/learn/gensfen.cpp | 5 ++--- src/nnue/evaluate_nnue_learner.cpp | 14 ++++++++++++-- src/nnue/trainer/trainer.h | 4 ++-- src/nnue/trainer/trainer_input_slice.h | 2 +- 5 files changed, 18 insertions(+), 10 deletions(-) diff --git a/.travis.yml b/.travis.yml index 438bf4d0..503d678a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -77,8 +77,7 @@ script: - if [[ "$TRAVIS_OS_NAME" != "linux" || "$COMP" == "gcc" ]]; then make clean && make -j2 ARCH=x86-64-modern profile-build && ../tests/signature.sh $benchref; fi # start some basic learner CI - #TODO enable -Werror - - export CXXFLAGS="" + - export CXXFLAGS="-Werror" - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then make clean && LDFLAGS="-lstdc++fs" make -j2 ARCH=x86-64-modern learn; fi - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then make clean && LDFLAGS="-lstdc++fs" make -j2 ARCH=x86-64-modern profile-learn; fi diff --git a/src/learn/gensfen.cpp b/src/learn/gensfen.cpp index 3d015acf..84feabb0 100644 --- a/src/learn/gensfen.cpp +++ b/src/learn/gensfen.cpp @@ -878,8 +878,7 @@ namespace Learner next_move = search_pv[0]; } - RANDOM_MOVE:; - + // Random move. auto random_move = choose_random_move(pos, random_move_flag, ply, actual_random_move_count); if (random_move.has_value()) { @@ -897,7 +896,7 @@ namespace Learner a_psv.clear(); } - DO_MOVE:; + // Do move. pos.do_move(next_move, states[ply]); // Call node evaluate() for each difference calculation. diff --git a/src/nnue/evaluate_nnue_learner.cpp b/src/nnue/evaluate_nnue_learner.cpp index 7be06832..8b0413e5 100644 --- a/src/nnue/evaluate_nnue_learner.cpp +++ b/src/nnue/evaluate_nnue_learner.cpp @@ -113,8 +113,13 @@ void SetOptions(const std::string& options) { void RestoreParameters(const std::string& dir_name) { const std::string file_name = Path::Combine(dir_name, NNUE::savedfileName); std::ifstream stream(file_name, std::ios::binary); - bool result = ReadParameters(stream); +#ifndef NDEBUG + bool result = +#endif + ReadParameters(stream); +#ifndef NDEBUG assert(result); +#endif SendMessages({{"reset"}}); } @@ -216,8 +221,13 @@ void save_eval(std::string dir_name) { const std::string file_name = Path::Combine(eval_dir, NNUE::savedfileName); std::ofstream stream(file_name, std::ios::binary); - const bool result = NNUE::WriteParameters(stream); +#ifndef NDEBUG + const bool result = +#endif + NNUE::WriteParameters(stream); +#ifndef NDEBUG assert(result); +#endif std::cout << "save_eval() finished. folder = " << eval_dir << std::endl; } diff --git a/src/nnue/trainer/trainer.h b/src/nnue/trainer/trainer.h index d526557a..94553c07 100644 --- a/src/nnue/trainer/trainer.h +++ b/src/nnue/trainer/trainer.h @@ -70,8 +70,8 @@ struct Example { // Message used for setting hyperparameters struct Message { - Message(const std::string& name, const std::string& value = ""): - name(name), value(value), num_peekers(0), num_receivers(0) {} + Message(const std::string& message_name, const std::string& message_value = ""): + name(message_name), value(message_value), num_peekers(0), num_receivers(0) {} const std::string name; const std::string value; std::uint32_t num_peekers; diff --git a/src/nnue/trainer/trainer_input_slice.h b/src/nnue/trainer/trainer_input_slice.h index b6d6635b..6b0adc9f 100644 --- a/src/nnue/trainer/trainer_input_slice.h +++ b/src/nnue/trainer/trainer_input_slice.h @@ -206,7 +206,7 @@ class Trainer> { const IndexType input_offset = kInputDimensions * b; const IndexType output_offset = kOutputDimensions * b; for (IndexType i = 0; i < kInputDimensions; ++i) { - if (i < Offset || i >= Offset + kOutputDimensions) { + if ((int)i < (int)Offset || i >= Offset + kOutputDimensions) { gradients_[input_offset + i] = static_cast(0.0); } else { gradients_[input_offset + i] = gradients[output_offset + i - Offset]; From d993bd36d0a984b47b7f2f0e14a91bbcec5f948e Mon Sep 17 00:00:00 2001 From: nodchip Date: Wed, 9 Sep 2020 21:21:10 +0900 Subject: [PATCH 2/7] Removed compile warnings. --- src/learn/learning_tools.h | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/learn/learning_tools.h b/src/learn/learning_tools.h index 348105b6..1f9bdf96 100644 --- a/src/learn/learning_tools.h +++ b/src/learn/learning_tools.h @@ -40,13 +40,14 @@ namespace EvalLearningTools static uint64_t eta2_epoch; // Batch initialization of eta. If 0 is passed, the default value will be set. - static void init_eta(double eta1, double eta2, double eta3, uint64_t eta1_epoch, uint64_t eta2_epoch) + static void init_eta(double new_eta1, double new_eta2, double new_eta3, + uint64_t new_eta1_epoch, uint64_t new_eta2_epoch) { - Weight::eta1 = (eta1 != 0) ? eta1 : 30.0; - Weight::eta2 = (eta2 != 0) ? eta2 : 30.0; - Weight::eta3 = (eta3 != 0) ? eta3 : 30.0; - Weight::eta1_epoch = (eta1_epoch != 0) ? eta1_epoch : 0; - Weight::eta2_epoch = (eta2_epoch != 0) ? eta2_epoch : 0; + Weight::eta1 = (new_eta1 != 0) ? new_eta1 : 30.0; + Weight::eta2 = (new_eta2 != 0) ? new_eta2 : 30.0; + Weight::eta3 = (new_eta3 != 0) ? new_eta3 : 30.0; + Weight::eta1_epoch = (new_eta1_epoch != 0) ? new_eta1_epoch : 0; + Weight::eta2_epoch = (new_eta2_epoch != 0) ? new_eta2_epoch : 0; } // Set eta according to epoch. From 005009f4e531561618d44780025ccf638532912c Mon Sep 17 00:00:00 2001 From: nodchip Date: Wed, 9 Sep 2020 23:38:00 +0900 Subject: [PATCH 3/7] Changed a option name more descriptive, "Training" -> "PruneAtShallowDepthOnPvNode". The default value was changed but the default behavior is not changed. Changed to set a global option prune_at_shallow_depth_on_pv_node on a callback function. --- src/search.cpp | 12 +++++++----- src/search.h | 4 ++++ src/ucioption.cpp | 8 +++++++- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/search.cpp b/src/search.cpp index 67348a2b..6fbfdedf 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -54,6 +54,10 @@ using std::string; using Eval::evaluate; using namespace Search; +#if defined(EVAL_LEARN) +bool Search::prune_at_shallow_depth_on_pv_node = false; +#endif + namespace { // Different node types, used as a template parameter @@ -68,8 +72,6 @@ namespace { return Value(223 * (d - improving)); } - bool training; - // Reductions lookup table, initialized at startup int Reductions[MAX_MOVES]; // [depth or moveNumber] @@ -195,8 +197,6 @@ void Search::init() { for (int i = 1; i < MAX_MOVES; ++i) Reductions[i] = int((22.0 + std::log(Threads.size())) * std::log(i)); - - training = Options["Training"]; } @@ -1011,7 +1011,9 @@ moves_loop: // When in check, search starts from here // Step 12. Pruning at shallow depth (~200 Elo) if ( !rootNode - && !(training && PvNode) +#ifdef EVAL_LEARN + && !(!prune_at_shallow_depth_on_pv_node && PvNode) +#endif && pos.non_pawn_material(us) && bestValue > VALUE_TB_LOSS_IN_MAX_PLY) { diff --git a/src/search.h b/src/search.h index 01d8a4c1..9d5ce279 100644 --- a/src/search.h +++ b/src/search.h @@ -33,6 +33,10 @@ namespace Search { constexpr int CounterMovePruneThreshold = 0; +#if defined(EVAL_LEARN) +extern bool prune_at_shallow_depth_on_pv_node; +#endif + /// Stack struct keeps track of the information we need to remember from nodes /// shallower and deeper in the tree during the search. Each search thread has /// its own array of Stack objects, indexed by the current ply. diff --git a/src/ucioption.cpp b/src/ucioption.cpp index 4f9fab5e..0e561416 100644 --- a/src/ucioption.cpp +++ b/src/ucioption.cpp @@ -42,6 +42,11 @@ void on_threads(const Option& o) { Threads.set(size_t(o)); } void on_tb_path(const Option& o) { Tablebases::init(o); } void on_use_NNUE(const Option& ) { Eval::init_NNUE(); } void on_eval_file(const Option& ) { Eval::init_NNUE(); } +#ifdef EVAL_LEARN +void on_prune_at_shallow_depth_on_pv_node(const Option& o) { + Search::prune_at_shallow_depth_on_pv_node = o; +} +#endif /// Our case insensitive less() function as required by UCI protocol bool CaseInsensitiveLess::operator() (const string& s1, const string& s2) const { @@ -69,7 +74,6 @@ void init(OptionsMap& o) { o["Move Overhead"] << Option(10, 0, 5000); o["Slow Mover"] << Option(100, 10, 1000); o["nodestime"] << Option(0, 0, 10000); - o["Training"] << Option(false); o["UCI_Chess960"] << Option(false); o["UCI_AnalyseMode"] << Option(false); o["UCI_LimitStrength"] << Option(false); @@ -96,6 +100,8 @@ void init(OptionsMap& o) { // Evalsave by default. This folder shall be prepared in advance. // Automatically create a folder under this folder like "0/", "1/", ... and save the evaluation function file there. o["EvalSaveDir"] << Option("evalsave"); + // Prune at shallow depth on PV nodes. Setting this value to true gains elo in shallow search. + o["PruneAtShallowDepthOnPvNode"] << Option(false, on_prune_at_shallow_depth_on_pv_node); #endif } From 69563aeed9726af36b6543be3572fbd825698f31 Mon Sep 17 00:00:00 2001 From: nodchip Date: Wed, 9 Sep 2020 20:16:09 +0900 Subject: [PATCH 4/7] Remove compile warnings. From 073d43738442657c30f1ddedd411b01a782f9d1b Mon Sep 17 00:00:00 2001 From: nodchip Date: Wed, 9 Sep 2020 21:21:10 +0900 Subject: [PATCH 5/7] Removed compile warnings. From e63b6088ba8066844fdf47a5843355196e0e2ad1 Mon Sep 17 00:00:00 2001 From: nodchip Date: Wed, 9 Sep 2020 23:38:00 +0900 Subject: [PATCH 6/7] Changed a option name more descriptive, "Training" -> "PruneAtShallowDepthOnPvNode". The default value was changed but the default behavior is not changed. Changed to set a global option prune_at_shallow_depth_on_pv_node on a callback function. --- src/search.cpp | 12 +++++++----- src/search.h | 4 ++++ src/ucioption.cpp | 8 +++++++- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/search.cpp b/src/search.cpp index 67348a2b..6fbfdedf 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -54,6 +54,10 @@ using std::string; using Eval::evaluate; using namespace Search; +#if defined(EVAL_LEARN) +bool Search::prune_at_shallow_depth_on_pv_node = false; +#endif + namespace { // Different node types, used as a template parameter @@ -68,8 +72,6 @@ namespace { return Value(223 * (d - improving)); } - bool training; - // Reductions lookup table, initialized at startup int Reductions[MAX_MOVES]; // [depth or moveNumber] @@ -195,8 +197,6 @@ void Search::init() { for (int i = 1; i < MAX_MOVES; ++i) Reductions[i] = int((22.0 + std::log(Threads.size())) * std::log(i)); - - training = Options["Training"]; } @@ -1011,7 +1011,9 @@ moves_loop: // When in check, search starts from here // Step 12. Pruning at shallow depth (~200 Elo) if ( !rootNode - && !(training && PvNode) +#ifdef EVAL_LEARN + && !(!prune_at_shallow_depth_on_pv_node && PvNode) +#endif && pos.non_pawn_material(us) && bestValue > VALUE_TB_LOSS_IN_MAX_PLY) { diff --git a/src/search.h b/src/search.h index 01d8a4c1..9d5ce279 100644 --- a/src/search.h +++ b/src/search.h @@ -33,6 +33,10 @@ namespace Search { constexpr int CounterMovePruneThreshold = 0; +#if defined(EVAL_LEARN) +extern bool prune_at_shallow_depth_on_pv_node; +#endif + /// Stack struct keeps track of the information we need to remember from nodes /// shallower and deeper in the tree during the search. Each search thread has /// its own array of Stack objects, indexed by the current ply. diff --git a/src/ucioption.cpp b/src/ucioption.cpp index 4f9fab5e..0e561416 100644 --- a/src/ucioption.cpp +++ b/src/ucioption.cpp @@ -42,6 +42,11 @@ void on_threads(const Option& o) { Threads.set(size_t(o)); } void on_tb_path(const Option& o) { Tablebases::init(o); } void on_use_NNUE(const Option& ) { Eval::init_NNUE(); } void on_eval_file(const Option& ) { Eval::init_NNUE(); } +#ifdef EVAL_LEARN +void on_prune_at_shallow_depth_on_pv_node(const Option& o) { + Search::prune_at_shallow_depth_on_pv_node = o; +} +#endif /// Our case insensitive less() function as required by UCI protocol bool CaseInsensitiveLess::operator() (const string& s1, const string& s2) const { @@ -69,7 +74,6 @@ void init(OptionsMap& o) { o["Move Overhead"] << Option(10, 0, 5000); o["Slow Mover"] << Option(100, 10, 1000); o["nodestime"] << Option(0, 0, 10000); - o["Training"] << Option(false); o["UCI_Chess960"] << Option(false); o["UCI_AnalyseMode"] << Option(false); o["UCI_LimitStrength"] << Option(false); @@ -96,6 +100,8 @@ void init(OptionsMap& o) { // Evalsave by default. This folder shall be prepared in advance. // Automatically create a folder under this folder like "0/", "1/", ... and save the evaluation function file there. o["EvalSaveDir"] << Option("evalsave"); + // Prune at shallow depth on PV nodes. Setting this value to true gains elo in shallow search. + o["PruneAtShallowDepthOnPvNode"] << Option(false, on_prune_at_shallow_depth_on_pv_node); #endif } From 94f3cae760f0ed6ab464cf8febd79ebe9925b53a Mon Sep 17 00:00:00 2001 From: nodchip Date: Thu, 10 Sep 2020 08:23:21 +0900 Subject: [PATCH 7/7] Changed a sentence. --- src/search.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/search.cpp b/src/search.cpp index 6fbfdedf..b92ea7c8 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -1012,7 +1012,7 @@ moves_loop: // When in check, search starts from here // Step 12. Pruning at shallow depth (~200 Elo) if ( !rootNode #ifdef EVAL_LEARN - && !(!prune_at_shallow_depth_on_pv_node && PvNode) + && (PvNode ? prune_at_shallow_depth_on_pv_node : true) #endif && pos.non_pawn_material(us) && bestValue > VALUE_TB_LOSS_IN_MAX_PLY)